[PATCH 2/2] i2c-tools: fix build with upstream i2c-tools' headers

Denys Vlasenko vda.linux at googlemail.com
Mon Aug 28 13:48:03 UTC 2017


On Mon, Aug 28, 2017 at 11:49 AM, Bartosz Golaszewski
<bartekgola at gmail.com> wrote:
> Installing headers from upstream i2c-tools makes it impossible to
> build the busybox version due to redefined symbols. This is caused by
> the fact that linux/i2c-dev.h from i2c-tools overwrites the one from
> linux uapi and defines symbols already defined by linux' linux/i2c.h.
>
> Fix it by including linux/i2c.h and defining the i2c access routines
> only if a well known symbol provided by linux uapi is not defined in
> linux/i2c-dev.h.
>
> Tested by building on systems with and without i2c-tools headers.
>
> Signed-off-by: Bartosz Golaszewski <bartekgola at gmail.com>
> ---
>  miscutils/i2c_tools.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/miscutils/i2c_tools.c b/miscutils/i2c_tools.c
> index 03a09d519..9cc55eb27 100644
> --- a/miscutils/i2c_tools.c
> +++ b/miscutils/i2c_tools.c
> @@ -62,7 +62,6 @@
>
>  #include "libbb.h"
>
> -#include <linux/i2c.h>
>  #include <linux/i2c-dev.h>
>
>  #define I2CDUMP_NUM_REGS               256
> @@ -79,6 +78,19 @@ static ALWAYS_INLINE void *itoptr(int i)
>         return (void*)(intptr_t)i;
>  }
>
> +/*
> + * Only include linux/i2c.h if the symbols provided by it are not already
> + * defined in linux/i2c-dev.h. This - while not correct - happens if we
> + * install the headers provided by upstream i2c-tools and is the default on
> + * some distributions (Debian, OpenSUSE). linux/i2c-dev.h from i2c-tools
> + * overwrites the linux uapi header and redefines a bunch of symbols, as
> + * well as already provides the i2c access functions we redefine below.

Oh boy. They have "static inlines" there, right?
That would add some hundreds of bytes of code.

Maybe we should drop "#include <linux/i2c-dev.h>" instead?

What are we using from those, "struct i2c_smbus_ioctl_data"
and "struct i2c_rdwr_ioctl_data" only?


More information about the busybox mailing list