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

Bartosz Golaszewski bartekgola at gmail.com
Mon Aug 28 09:49:25 UTC 2017


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.
+ *
+ * Check a well known symbol and include linux/i2c.h conditionally.
+ */
+#ifndef I2C_FUNC_I2C
+#include <linux/i2c.h>
+
 static int32_t i2c_smbus_access(int fd, char read_write, uint8_t cmd,
 				int size, union i2c_smbus_data *data)
 {
@@ -240,6 +252,8 @@ static int32_t i2c_smbus_write_quick(int fd, uint8_t val)
 }
 #endif /* ENABLE_I2CDETECT */
 
+#endif /* I2C_FUNC_I2C */
+
 static int i2c_bus_lookup(const char *bus_str)
 {
 	return xstrtou_range(bus_str, 10, 0, 0xfffff);
-- 
2.13.2



More information about the busybox mailing list