Skip to contentSkip to conversation

i2c-tools: Make tools accept bus path

PATCH Applied Brigham Campbell 2 participants 11 messages Jul 22 – Nov 16 I2C subsystem host drivers

lore
Share & tools
lore
#0 lore raw

v5 cover i2c-tools: Make tools accept bus path

The purpose of this series is to make i2c-tools userspace utilities accept an i2c bus character device file path as an argument. This is useful, for example, if a sysadmin creates udev rules to create a persistent symlink to an i2c bus and wishes to use that symlink with i2c-tools.

Since v1:
* Scrapped brittle checking against device major number 89 in favor of an i2c_bus_hint variant struct.
Since v2:
* Scrapped i2c_bus_hint variant in favor of combining the lookup and open steps into one function. No more awkward variant.
Since v3:
* Rebased onto master and fixed minor conflicts.
Since v4:
* Inline much of the functionality of open_i2c_dev.
* Where possible, make functions static.

---
Brigham Campbell (2):
i2c-tools: Allow passing device file paths
i2c-tools: Document device paths as I2CBUS arg

 tools/i2cbusses.c   | 127 ++++++++++++++++++++++++++++++----------------------
 tools/i2cbusses.h   |   3 +-
 tools/i2cdetect.8   |   8 ++--
 tools/i2cdetect.c   |  14 +++---
 tools/i2cdump.8     |   7 +--
 tools/i2cdump.c     |  14 +++---
 tools/i2cget.8      |   9 ++--
 tools/i2cget.c      |  13 +++---
 tools/i2cset.8      |  12 ++---
 tools/i2cset.c      |  13 +++---
 tools/i2ctransfer.8 |   2 +-
 tools/i2ctransfer.c |  13 +++---
 12 files changed, 120 insertions(+), 115 deletions(-)

---
base-commit: 5852f5375eea6ca9dabf31f4772cb8b8ecc905d8
change-id: 20260530-accept-device-path-539164c9c1df

Thanks!

Signature · 2 lines
Brigham Campbell
https://brighamcampbell.com
#1 lore raw

PATCH v5 1/2 i2c-tools: Allow passing device file paths

Make i2c-tools binaries accept a device file path or symlink directly. This is useful, for example, for use with stable symlinks generated by udev.

In the case of conflict, the bus parameter is parsed with the following precedence in order to maintain backwards compatibility:

number -> name -> device path

---
 tools/i2cbusses.c   | 127 ++++++++++++++++++++++++++++++----------------------
 tools/i2cbusses.h   |   3 +-
 tools/i2cdetect.c   |  12 ++---
 tools/i2cdump.c     |  12 ++---
 tools/i2cget.c      |  11 ++---
 tools/i2cset.c      |  11 ++---
 tools/i2ctransfer.c |  11 ++---
 7 files changed, 95 insertions(+), 92 deletions(-)
tools/i2cbusses.c +74 -53
index d687615..40d863f 100644
@@ -58,6 +58,42 @@ static struct adap_type adap_types[5] = {
 	  .algo		= "N/A", },
 };
 
+static int open_i2c_dev_by_nr(int i2cbus, char *filename, size_t size, int quiet)
+{
+	int file, len;
+
+	len = snprintf(filename, size, "/dev/i2c/%d", i2cbus);
+	if (len >= (int)size) {
+		fprintf(stderr, "%s: path truncated\n", filename);
+		return -EOVERFLOW;
+	}
+	file = open(filename, O_RDWR);
+
+	if (file < 0 && (errno == ENOENT || errno == ENOTDIR)) {
+		len = snprintf(filename, size, "/dev/i2c-%d", i2cbus);
+		if (len >= (int)size) {
+			fprintf(stderr, "%s: path truncated\n", filename);
+			return -EOVERFLOW;
+		}
+		file = open(filename, O_RDWR);
+	}
+
+	if (file < 0 && !quiet) {
+		if (errno == ENOENT) {
+			fprintf(stderr, "Error: Could not open file "
+				"`/dev/i2c-%d' or `/dev/i2c/%d': %s\n",
+				i2cbus, i2cbus, strerror(ENOENT));
+		} else {
+			fprintf(stderr, "Error: Could not open file "
+				"`%s': %s\n", filename, strerror(errno));
+			if (errno == EACCES)
+				fprintf(stderr, "Run as root?\n");
+		}
+	}
+
+	return file;
+}
+
 static enum adt i2c_get_funcs(int i2cbus)
 {
 	unsigned long funcs;
@@ -65,7 +101,7 @@ static enum adt i2c_get_funcs(int i2cbus)
 	char filename[20];
 	enum adt ret;
 
-	file = open_i2c_dev(i2cbus, filename, sizeof(filename), 1);
+	file = open_i2c_dev_by_nr(i2cbus, filename, sizeof(filename), 1);
 	if (file < 0)
 		return adt_unknown;
 
@@ -348,37 +384,11 @@ static int lookup_i2c_bus_by_name(const char *bus_name)
 		}
 	}
 
-	if (i2cbus == -1)
-		fprintf(stderr, "Error: I2C bus name doesn't match any "
-			"bus present!\n");
-
 done:
 	free_adapters(adapters);
 	return i2cbus;
 }
 
-/*
- * Parse an I2CBUS command line argument and return the corresponding
- * bus number, or a negative value if the bus is invalid.
- */
-int lookup_i2c_bus(const char *i2cbus_arg)
-{
-	unsigned long i2cbus;
-	char *end;
-
-	i2cbus = strtoul(i2cbus_arg, &end, 0);
-	if (*end || !*i2cbus_arg) {
-		/* Not a number, maybe a name? */
-		return lookup_i2c_bus_by_name(i2cbus_arg);
-	}
-	if (i2cbus > 0xFFFFF) {
-		fprintf(stderr, "Error: I2C bus out of range!\n");
-		return -2;
-	}
-
-	return i2cbus;
-}
-
 /*
  * Parse a CHIP-ADDRESS command line argument and return the corresponding
  * chip address, or a negative value if the address is invalid.
@@ -410,39 +420,50 @@ int parse_i2c_address(const char *address_arg, int all_addrs)
 	return address;
 }
 
-int open_i2c_dev(int i2cbus, char *filename, size_t size, int quiet)
+/*
+ * Parse a I2CBUS command line argument and return the corresponding file
+ * descriptor, or a negative value if the file can't be resolved. Use *filename
+ * to return the file path. size refers to the size of the buffer which
+ * **filename initially points to.
+ *
+ * For historical reasons, I2CBUS parsing precedence is as follows:
+ * 	number -> name -> device path
+ */
+int open_i2c_dev(char *i2cbus_arg, char **filename, size_t size, int quiet)
 {
-	int file, len;
+	int file, i2cbus;
+	unsigned long i2cbus_ul;
+	char *end;
 
-	len = snprintf(filename, size, "/dev/i2c/%d", i2cbus);
-	if (len >= (int)size) {
-		fprintf(stderr, "%s: path truncated\n", filename);
-		return -EOVERFLOW;
-	}
-	file = open(filename, O_RDWR);
-
-	if (file < 0 && (errno == ENOENT || errno == ENOTDIR)) {
-		len = snprintf(filename, size, "/dev/i2c-%d", i2cbus);
-		if (len >= (int)size) {
-			fprintf(stderr, "%s: path truncated\n", filename);
-			return -EOVERFLOW;
+	i2cbus_ul = strtoul(i2cbus_arg, &end, 0);
+	if (!*end && *i2cbus_arg) {
+		if (i2cbus_ul > 0xFFFFF) {
+			fprintf(stderr, "Error: I2C bus out of range!\n");
+			return -2;
 		}
-		file = open(filename, O_RDWR);
+
+		return open_i2c_dev_by_nr(i2cbus_ul, *filename, size, quiet);
 	}
 
-	if (file < 0 && !quiet) {
-		if (errno == ENOENT) {
-			fprintf(stderr, "Error: Could not open file "
-				"`/dev/i2c-%d' or `/dev/i2c/%d': %s\n",
-				i2cbus, i2cbus, strerror(ENOENT));
-		} else {
-			fprintf(stderr, "Error: Could not open file "
-				"`%s': %s\n", filename, strerror(errno));
-			if (errno == EACCES)
-				fprintf(stderr, "Run as root?\n");
-		}
+	i2cbus = lookup_i2c_bus_by_name(i2cbus_arg);
+	if (i2cbus >= 0) {
+		return open_i2c_dev_by_nr(i2cbus, *filename, size, quiet);
 	}
 
+	*filename = i2cbus_arg;
+	file = open(i2cbus_arg, O_RDWR);
+
+	if (file >= 0 || quiet) return file;
+
+	if (errno == EACCES) {
+		fprintf(stderr, "Error: Could not open file `%s': %s\n"
+			"Run as root?\n", i2cbus_arg, strerror(errno));
+		return file;
+	}
+
+	fprintf(stderr, "Error: Couldn't interpret `%s' as a bus number, "
+		"name, or device file path!\n", i2cbus_arg);
+
 	return file;
 }
 
tools/i2cbusses.h +1 -2
index 6f901b6..0cec50f 100644
@@ -29,9 +29,8 @@ struct i2c_adap {
 struct i2c_adap *gather_i2c_busses(void);
 void free_adapters(struct i2c_adap *adapters);
 
-int lookup_i2c_bus(const char *i2cbus_arg);
 int parse_i2c_address(const char *address_arg, int all_addrs);
-int open_i2c_dev(int i2cbus, char *filename, size_t size, int quiet);
+int open_i2c_dev(char *i2cbus_arg, char **filename, size_t size, int quiet);
 int set_slave_addr(int file, int address, int force);
 
 #define MISSING_FUNC_FMT	"Error: Adapter does not have %s capability\n"
tools/i2cdetect.c +4 -8
index 3c22f17..b62f395 100644
@@ -213,8 +213,9 @@ static void print_i2c_busses(void)
 int main(int argc, char *argv[])
 {
 	char *end;
-	int i2cbus, file, res;
-	char filename[20];
+	int file, res;
+	char filename_buf[20];
+	char *filename = filename_buf;
 	unsigned long funcs;
 	int mode = MODE_AUTO;
 	int first = 0x08, last = 0x77;
@@ -277,11 +278,6 @@ int main(int argc, char *argv[])
 		help();
 		exit(1);
 	}
-	i2cbus = lookup_i2c_bus(argv[optind]);
-	if (i2cbus < 0) {
-		help();
-		exit(1);
-	}
 
 	/* read address range if present */
 	if (argc == optind + 3 && mode != MODE_FUNC) {
@@ -321,7 +317,7 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
-	file = open_i2c_dev(i2cbus, filename, sizeof(filename), 0);
+	file = open_i2c_dev(argv[optind], &filename, sizeof(filename_buf), 0);
 	if (file < 0) {
 		exit(1);
 	}
tools/i2cdump.c +4 -8
index d315e2f..ce3be2c 100644
@@ -100,9 +100,10 @@ static int check_funcs(int file, int size, int pec)
 int main(int argc, char *argv[])
 {
 	char *end;
-	int i, j, res, i2cbus, address, size, file;
+	int i, j, res, address, size, file;
 	int bank = 0, bankreg = 0x4E, old_bank = 0;
-	char filename[20];
+	char filename_buf[20];
+	char *filename = filename_buf;
 	int block[256];
 	int pec = 0, even = 0;
 	int opt;
@@ -135,11 +136,6 @@ int main(int argc, char *argv[])
 		help();
 		exit(1);
 	}
-	i2cbus = lookup_i2c_bus(argv[optind]);
-	if (i2cbus < 0) {
-		help();
-		exit(1);
-	}
 
 	if (argc < optind + 2) {
 		fprintf(stderr, "Error: No address specified!\n");
@@ -235,7 +231,7 @@ int main(int argc, char *argv[])
 		}
 	}
 
-	file = open_i2c_dev(i2cbus, filename, sizeof(filename), 0);
+	file = open_i2c_dev(argv[optind], &filename, sizeof(filename_buf), 0);
 	if (file < 0
 	 || check_funcs(file, size, pec)
 	 || set_slave_addr(file, address, force))
tools/i2cget.c +4 -7
index 17d78bf..e08ee81 100644
@@ -169,9 +169,10 @@ static int confirm(const char *filename, int address, int size, int daddress,
 int main(int argc, char *argv[])
 {
 	char *end;
-	int res, i2cbus, address, size, file;
+	int res, address, size, file;
 	int daddress;
-	char filename[20];
+	char filename_buf[20];
+	char *filename = filename_buf;
 	int pec = 0;
 	int opt;
 	int force = 0, yes = 0, version = 0, all_addrs = 0;
@@ -199,10 +200,6 @@ int main(int argc, char *argv[])
 	if (argc < optind + 2)
 		help(1);
 
-	i2cbus = lookup_i2c_bus(argv[optind]);
-	if (i2cbus < 0)
-		help(1);
-
 	address = parse_i2c_address(argv[optind+1], all_addrs);
 	if (address < 0)
 		help(1);
@@ -251,7 +248,7 @@ int main(int argc, char *argv[])
 		length = I2C_SMBUS_BLOCK_MAX;
 	}
 
-	file = open_i2c_dev(i2cbus, filename, sizeof(filename), 0);
+	file = open_i2c_dev(argv[optind], &filename, sizeof(filename_buf), 0);
 	if (file < 0
 	 || check_funcs(file, size, daddress, pec)
 	 || set_slave_addr(file, address, force))
tools/i2cset.c +4 -7
index aaf7faf..8371570 100644
@@ -151,9 +151,10 @@ int main(int argc, char *argv[])
 {
 	char *end;
 	const char *maskp = NULL;
-	int res, i2cbus, address, size, file;
+	int res, address, size, file;
 	int value, daddress, vmask = 0;
-	char filename[20];
+	char filename_buf[20];
+	char *filename = filename_buf;
 	int pec = 0;
 	int opt;
 	int force = 0, yes = 0, version = 0, readback = 0, all_addrs = 0;
@@ -183,10 +184,6 @@ int main(int argc, char *argv[])
 	if (argc < optind + 3)
 		help(1);
 
-	i2cbus = lookup_i2c_bus(argv[optind]);
-	if (i2cbus < 0)
-		help(1);
-
 	address = parse_i2c_address(argv[optind+1], all_addrs);
 	if (address < 0)
 		help(1);
@@ -301,7 +298,7 @@ int main(int argc, char *argv[])
 		}
 	}
 
-	file = open_i2c_dev(i2cbus, filename, sizeof(filename), 0);
+	file = open_i2c_dev(argv[optind], &filename, sizeof(filename_buf), 0);
 	if (file < 0
 	 || check_funcs(file, size, pec)
 	 || set_slave_addr(file, address, force))
tools/i2ctransfer.c +4 -7
index a49b734..d9d1396 100644
@@ -257,8 +257,9 @@ static enum supported_flags_retval
 
 int main(int argc, char *argv[])
 {
-	char filename[20];
-	int i2cbus, address = -1, file, opt, nmsgs = 0, nmsgs_sent, i;
+	char filename_buf[20];
+	char *filename = filename_buf;
+	int address = -1, file, opt, nmsgs = 0, nmsgs_sent, i;
 	int force = 0, yes = 0, version = 0, verbose = 0, all_addrs = 0, binary = 0;
 	struct i2c_msg msgs[I2C_RDRW_IOCTL_MAX_MSGS];
 	enum parse_state state = PARSE_GET_DESC;
@@ -293,11 +294,7 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
-	i2cbus = lookup_i2c_bus(argv[optind++]);
-	if (i2cbus < 0)
-		exit(1);
-
-	file = open_i2c_dev(i2cbus, filename, sizeof(filename), 0);
+	file = open_i2c_dev(argv[optind++], &filename, sizeof(filename_buf), 0);
 	if (file < 0 || get_funcs(file, &funcs) || check_funcs(funcs))
 		exit(1);
 
Signature · 1 line
2.55.0
#2 lore raw

Re: [PATCH v5 1/2] i2c-tools: Allow passing device file paths

Hi Brigham,

finally! Thanks to a long train travel :)

Quoted 11 lines · Brigham Campbell

Make i2c-tools binaries accept a device file path or symlink directly. This is useful, for example, for use with stable symlinks generated by udev.

In the case of conflict, the bus parameter is parsed with the following precedence in order to maintain backwards compatibility:

number -> name -> device path

Yes, I like how this turned out in the end. I think the code is easy to understand. It seems to work well. It took a little time to find one corner case in need to be dealt with ;) But it is simple enough...

Review

Quoted 5 lines
(quoted diff) +5 -0
+	i2cbus_ul = strtoul(i2cbus_arg, &end, 0);
+	if (!*end && *i2cbus_arg) {
+		if (i2cbus_ul > 0xFFFFF) {
+			fprintf(stderr, "Error: I2C bus out of range!\n");
+			return -2;

This fails if you use a name/path like "1111111111111". A diff like this makes it work:

tools/i2cbusses.c +1 -6
index 40d863f..47ebffa 100644
@@ -436,12 +436,7 @@ int open_i2c_dev(char *i2cbus_arg, char **filename, size_t size, int quiet)
 	char *end;
 
 	i2cbus_ul = strtoul(i2cbus_arg, &end, 0);
-	if (!*end && *i2cbus_arg) {
-		if (i2cbus_ul > 0xFFFFF) {
-			fprintf(stderr, "Error: I2C bus out of range!\n");
-			return -2;
-		}
-
+	if (!*end && *i2cbus_arg && i2cbus_ul < 0x100000) {
 		return open_i2c_dev_by_nr(i2cbus_ul, *filename, size, quiet);
 	}
 

That should do it, or?

Review

Quoted 3 lines
(quoted diff) +3 -0
+	fprintf(stderr, "Error: Couldn't interpret `%s' as a bus number, "
+		"name, or device file path!\n", i2cbus_arg);
+

I think this error message does its job very well. In my book, no need to make it more fine-grained.

The rest (including patch 2) looks also good to me.

Thank you and happy hacking,

Wolfram

#3 lore raw

Re: [PATCH v5 1/2] i2c-tools: Allow passing device file paths

Hi Brigham,

Quoted 28 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+	i2cbus_ul = strtoul(i2cbus_arg, &end, 0);
+	if (!*end && *i2cbus_arg) {
+		if (i2cbus_ul > 0xFFFFF) {
+			fprintf(stderr, "Error: I2C bus out of range!\n");
+			return -2;

This fails if you use a name/path like "1111111111111". A diff like this makes it work:

tools/i2cbusses.c +1 -6
index 40d863f..47ebffa 100644
@@ -436,12 +436,7 @@ int open_i2c_dev(char *i2cbus_arg, char **filename, size_t size, int quiet)
 	char *end;
 
 	i2cbus_ul = strtoul(i2cbus_arg, &end, 0);
-	if (!*end && *i2cbus_arg) {
-		if (i2cbus_ul > 0xFFFFF) {
-			fprintf(stderr, "Error: I2C bus out of range!\n");
-			return -2;
-		}
-
+	if (!*end && *i2cbus_arg && i2cbus_ul < 0x100000) {
 		return open_i2c_dev_by_nr(i2cbus_ul, *filename, size, quiet);
 	}
 
Quoted 1 line

That should do it, or?

Do you need some more time to review? Or are you okay with me applying it with my suggested addition?

Happy hacking,

Wolfram

#4 lore raw

Re: [PATCH v5 1/2] i2c-tools: Allow passing device file paths

In reply to Wolfram Sang

Wolfram,

Finally getting back to you after a good friend's wedding.

Quoted 29 lines · Wolfram Sang

Review

Quoted 5 lines · Brigham Campbell
(quoted diff) +5 -0
+	i2cbus_ul = strtoul(i2cbus_arg, &end, 0);
+	if (!*end && *i2cbus_arg) {
+		if (i2cbus_ul > 0xFFFFF) {
+			fprintf(stderr, "Error: I2C bus out of range!\n");
+			return -2;

This fails if you use a name/path like "1111111111111". A diff like this makes it work:

tools/i2cbusses.c +1 -6
index 40d863f..47ebffa 100644
@@ -436,12 +436,7 @@ int open_i2c_dev(char *i2cbus_arg, char **filename, size_t size, int quiet)
 	char *end;
 
 	i2cbus_ul = strtoul(i2cbus_arg, &end, 0);
-	if (!*end && *i2cbus_arg) {
-		if (i2cbus_ul > 0xFFFFF) {
-			fprintf(stderr, "Error: I2C bus out of range!\n");
-			return -2;
-		}
-
+	if (!*end && *i2cbus_arg && i2cbus_ul < 0x100000) {
 		return open_i2c_dev_by_nr(i2cbus_ul, *filename, size, quiet);
 	}
 
Quoted 1 line

That should do it, or?

Yes, this looks correct to me. However, the behavior of v5 was intentional. It's reflective of the behavior of i2c-tools before my
patch: If the i2cbus argument can be parsed as an unsigned long, it will be treated as the bus number. i2c-tools will never even make an attempt to interpret it as a bus name.

$ pacman -Q i2c-tools
i2c-tools 4.4-4
$ i2cget -y 1111111111111 0
Error: I2C bus out of range!
...

Printing an error instead of trying to parse the argument as a name or path is an undercommitment on the part of the user interface. It makes breaking changes to that 0xFFFFF boundary easier. When we increase the boundary size, we don't need to worry about users passing (PREVIOUS_BOUNDARY + 1) and expecting it to be interpreted as a bus name or device file path.

Even if we know the boundary will never change, I think it would be better if users can always expect unsigned long values to be interpreted as bus numbers directly, even if too-big values always result in an error.

If you disagree, I'm happy to make the change or you can make it yourself, but I'd like it to be a follow-on patch to this series because with respect to this particular issue, I made an effort to preserve the original behavior in this patch.

Quoted 8 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+	fprintf(stderr, "Error: Couldn't interpret `%s' as a bus number, "
+		"name, or device file path!\n", i2cbus_arg);
+

I think this error message does its job very well. In my book, no need to make it more fine-grained.

The rest (including patch 2) looks also good to me.

Thanks again for your thoughtful review!

Signature · 2 lines
Brigham Campbell
https://brighamcampbell.com
#5 lore raw

Re: [PATCH v5 1/2] i2c-tools: Allow passing device file paths

Brigham,

Quoted 1 line

Finally getting back to you after a good friend's wedding.

Nice! Hope you had a great time.

Quoted 11 lines

Printing an error instead of trying to parse the argument as a name or path is an undercommitment on the part of the user interface. It makes breaking changes to that 0xFFFFF boundary easier. When we increase the boundary size, we don't need to worry about users passing (PREVIOUS_BOUNDARY + 1) and expecting it to be interpreted as a bus name or device file path.

Even if we know the boundary will never change, I think it would be better if users can always expect unsigned long values to be interpreted as bus numbers directly, even if too-big values always result in an error.

Good argument, I am convinced. I will apply v5 as is now.

Thank you for all the work on this!

All the best,

Wolfram

#6 lore raw

PATCH v5 2/2 i2c-tools: Document device paths as I2CBUS arg

In reply to Brigham Campbell

i2c-tools now accept device file paths in addition to the i2c adapter number and i2c adapter name. Add this capability to documentation.

---
 tools/i2cdetect.8   |  8 ++++----
 tools/i2cdetect.c   |  2 +-
 tools/i2cdump.8     |  7 ++++---
 tools/i2cdump.c     |  2 +-
 tools/i2cget.8      |  9 +++++----
 tools/i2cget.c      |  2 +-
 tools/i2cset.8      | 12 ++++++------
 tools/i2cset.c      |  2 +-
 tools/i2ctransfer.8 |  2 +-
 tools/i2ctransfer.c |  2 +-
 10 files changed, 25 insertions(+), 23 deletions(-)
tools/i2cdetect.8 +4 -4
index 5935b2b..fdfff62 100644
@@ -26,10 +26,10 @@ i2cdetect \- detect I2C chips
 .SH DESCRIPTION
 i2cdetect is a userspace program to scan an I2C bus for devices. It
 outputs a table with the list of detected devices on the specified bus.
-\fIi2cbus\fR indicates the number or name of the I2C bus to be scanned, and
-should correspond to one of the busses listed by \fIi2cdetect -l\fR.
-The optional parameters \fIfirst\fR and \fIlast\fR restrict the scanning
-range (default: from 0x08 to 0x77).
+\fIi2cbus\fR indicates the number, name, or device file path of the I2C
+bus to be scanned, and should correspond to one of the busses listed by
+\fIi2cdetect -l\fR.  The optional parameters \fIfirst\fR and \fIlast\fR
+restrict the scanning range (default: from 0x08 to 0x77).
 .PP
 As there is no standard I2C detection command, i2cdetect uses arbitrary
 SMBus commands (namely SMBus quick write and SMBus receive byte) to probe
tools/i2cdetect.c +1 -1
index b62f395..78a0955 100644
@@ -38,7 +38,7 @@ static void help(void)
 		"Usage: i2cdetect [-y] [-a] [-q|-r] I2CBUS [FIRST LAST]\n"
 		"       i2cdetect -F I2CBUS\n"
 		"       i2cdetect -l\n"
-		"  I2CBUS is an integer or an I2C bus name\n"
+		"  I2CBUS is an integer, I2C bus name, or I2C bus device path\n"
 		"  If provided, FIRST and LAST limit the probing range.\n");
 }
 
tools/i2cdump.8 +4 -3
index 6ede625..103051d 100644
@@ -52,9 +52,10 @@ scripts.
 Allow using addresses between 0x00 - 0x07 and 0x78 - 0x7f. Not recommended.
 .PP
 At least two options must be provided to i2cdump. \fIi2cbus\fR indicates the
-number or name of the I2C bus to be scanned. This number should correspond to one
-of the busses listed by \fIi2cdetect -l\fR. \fIaddress\fR indicates the
-address to be scanned on that bus, and is an integer between 0x08 and 0x77.
+number, name, or device file path of the I2C bus to be scanned. This number
+should correspond to one of the busses listed by \fIi2cdetect -l\fR.
+\fIaddress\fR indicates the address to be scanned on that bus, and is an integer
+between 0x08 and 0x77.
 .PP
 The \fImode\fR parameter, if specified, is one of the letters \fBb\fP, \fBw\fP,
 or \fBi\fP, corresponding to a read size of a single byte, a 16-bit
tools/i2cdump.c +1 -1
index ce3be2c..6389e68 100644
@@ -32,7 +32,7 @@ static void help(void)
 {
 	fprintf(stderr,
 		"Usage: i2cdump [-f] [-y] [-r first-last] [-a] I2CBUS ADDRESS [MODE [BANK [BANKREG]]]\n"
-		"  I2CBUS is an integer or an I2C bus name\n"
+		"  I2CBUS is an integer, I2C bus name, or I2C bus device path\n"
 		"  ADDRESS is an integer (0x08 - 0x77, or 0x00 - 0x7f if -a is given)\n"
 		"  MODE is one of:\n"
 		"    b (byte, default)\n"
tools/i2cget.8 +5 -4
index 69586cc..ba261a9 100644
@@ -45,10 +45,11 @@ scripts. Use with caution.
 .B -a
 Allow using addresses between 0x00 - 0x07 and 0x78 - 0x7f. Not recommended.
 .PP
-There are two required options to i2cget. \fIi2cbus\fR indicates the number
-or name of the I2C bus to be scanned.  This number should correspond to one of
-the busses listed by \fIi2cdetect -l\fR. \fIchip-address\fR specifies the
-address of the chip on that bus, and is an integer between 0x08 and 0x77.
+There are two required options to i2cget. \fIi2cbus\fR indicates the number,
+name, or device file path of the I2C bus to be scanned.  This number should
+correspond to one of the busses listed by \fIi2cdetect -l\fR.
+\fIchip-address\fR specifies the address of the chip on that bus, and is an
+integer between 0x08 and 0x77.
 .PP
 \fIdata-address\fR specifies the address on that chip to read from, and is
 an integer between 0x00 and 0xFF. If omitted, the currently active register
tools/i2cget.c +1 -1
index e08ee81..759f016 100644
@@ -35,7 +35,7 @@ static void __attribute__ ((noreturn)) help(int status)
 {
 	fprintf(stderr,
 		"Usage: i2cget [-f] [-y] [-a] I2CBUS CHIP-ADDRESS [DATA-ADDRESS [MODE [LENGTH]]]\n"
-		"  I2CBUS is an integer or an I2C bus name\n"
+		"  I2CBUS is an integer, I2C bus name, or I2C bus device path\n"
 		"  ADDRESS is an integer (0x08 - 0x77, or 0x00 - 0x7f if -a is given)\n"
 		"  MODE is one of:\n"
 		"    b (read byte data, default)\n"
tools/i2cset.8 +6 -6
index e4e1870..d7a2c05 100644
@@ -65,12 +65,12 @@ apply as those of option \fB-m\fR.
 .B -a
 Allow using addresses between 0x00 - 0x07 and 0x78 - 0x7f. Not recommended.
 .PP
-There are three required options to i2cset. \fIi2cbus\fR indicates the number
-or name of the I2C bus to be scanned.  This number should correspond to one of
-the busses listed by \fIi2cdetect -l\fR. \fIchip-address\fR specifies the
-address of the chip on that bus, and is an integer between 0x08 and 0x77.
-\fIdata-address\fR specifies the address on that chip to write to, and is an
-integer between 0x00 and 0xFF.
+There are three required options to i2cset. \fIi2cbus\fR indicates the number,
+name, or device file path of the I2C bus to be scanned. This number should
+correspond to one of the busses listed by \fIi2cdetect -l\fR. \fIchip-address\fR
+specifies the address of the chip on that bus, and is an integer between 0x08
+and 0x77. \fIdata-address\fR specifies the address on that chip to write to, and
+is an integer between 0x00 and 0xFF.
 .PP
 The \fIvalue\fR parameter, if specified, is the value to write to that
 location on the chip. If this parameter is omitted, then a short write is
tools/i2cset.c +1 -1
index 8371570..27e3c7f 100644
@@ -32,7 +32,7 @@ static void __attribute__ ((noreturn)) help(int status)
 {
 	fprintf(stderr,
 		"Usage: i2cset [-f] [-y] [-m MASK] [-r] [-a] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE] ... [MODE]\n"
-		"  I2CBUS is an integer or an I2C bus name\n"
+		"  I2CBUS is an integer, I2C bus name, or I2C bus device path\n"
 		"  ADDRESS is an integer (0x08 - 0x77, or 0x00 - 0x7f if -a is given)\n"
 		"  MODE is one of:\n"
 		"    c (byte, no value)\n"
tools/i2ctransfer.8 +1 -1
index de03c7d..20fd454 100644
@@ -84,7 +84,7 @@ This is mainly meant to be used in scripts.
 .PP
 The first parameter
 .I i2cbus
-indicates the number or name of the I2C bus to be used.
+indicates the number, name, or device file path of the I2C bus to be used.
 This number should correspond to one of the busses listed by
 .B i2cdetect -l.
 
tools/i2ctransfer.c +1 -1
index d9d1396..925c2b4 100644
@@ -59,7 +59,7 @@ static void help(void)
 		"           -v verbose mode\n"
 		"           -V version info\n"
 		"           -y yes to all confirmations\n"
-		"  I2CBUS is an integer or an I2C bus name\n"
+		"  I2CBUS is an integer, I2C bus name, or I2C bus device path\n"
 		"  DESC describes the transfer in the form: [inpst]{r|w}LENGTH[@address]\n"
 		"    1) optional message modifier flags, if supported\n"
 		"       i: ignore NACK from client\n"
Signature · 1 line
2.55.0
#7 lore raw
In reply to Brigham Campbell

Hi, Wolfram, Jean!

Quoted 5 lines · Brigham Campbell

The purpose of this series is to make i2c-tools userspace utilities accept an i2c bus character device file path as an argument. This is useful, for example, if a sysadmin creates udev rules to create a persistent symlink to an i2c bus and wishes to use that symlink with i2c-tools.

I appreciate the feedback you've given to help get this series to v5. Do you have any outstanding concerns about this series? Is there anything I can do to help get it across the finish line?

Thanks!

Signature · 2 lines
Brigham Campbell
https://brighamcampbell.com
#8 lore raw

Hi Brigham,

Quoted 3 lines

I appreciate the feedback you've given to help get this series to v5. Do you have any outstanding concerns about this series? Is there anything I can do to help get it across the finish line?

The main problem here is time :( I have important conferences coming up, so I can only schedule this to the second half of October, I am afraid.

What would help a little is maybe a description what cases you tested?

If other people want to review it before, that would help a lot, too, of course!

Thanks for your work and patience,

Wolfram

#9 lore raw
Quoted 2 lines · Wolfram Sang

The main problem here is time :( I have important conferences coming up, so I can only schedule this to the second half of October, I am afraid.

No worries at all. I understand. I hope you enjoy the conferences!

Quoted 1 line

What would help a little is maybe a description what cases you tested?

I tested as I was developing the patch, but that was a while ago now. I'll test some more and report back with the details.

By the way, I'm happy to review (and test, when I can) other patches if it would help. If so, feel free to send me some lore links or msgids.

Signature · 2 lines
Brigham Campbell
https://brighamcampbell.com
Applied
#10 lore raw
In reply to Brigham Campbell
Quoted 18 lines · Brigham Campbell

The purpose of this series is to make i2c-tools userspace utilities accept an i2c bus character device file path as an argument. This is useful, for example, if a sysadmin creates udev rules to create a persistent symlink to an i2c bus and wishes to use that symlink with i2c-tools.

Since v1:
* Scrapped brittle checking against device major number 89 in favor of an i2c_bus_hint variant struct.
Since v2:
* Scrapped i2c_bus_hint variant in favor of combining the lookup and open steps into one function. No more awkward variant.
Since v3:
* Rebased onto master and fixed minor conflicts.
Since v4:
* Inline much of the functionality of open_i2c_dev.
* Where possible, make functions static.

Quoted 5 lines

---
Brigham Campbell (2):
i2c-tools: Allow passing device file paths
i2c-tools: Document device paths as I2CBUS arg

Applied, thank you!