diff mbox series

i2cdetect: Sort the bus list by number

Message ID 20210527100703.71519bbe@endymion
State New
Headers show
Series i2cdetect: Sort the bus list by number | expand

Commit Message

Jean Delvare May 27, 2021, 8:07 a.m. UTC
The bus list (option -l) will be easier to read once sorted, as
typically this will group the buses by driver.

Signed-off-by: Jean Delvare <jdelvare@suse.de>
---
Why did I not do that earlier... I don't know.

 tools/i2cbusses.c |   11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Wolfram Sang May 28, 2021, 7:13 p.m. UTC | #1
On Thu, May 27, 2021 at 10:07:03AM +0200, Jean Delvare wrote:
> The bus list (option -l) will be easier to read once sorted, as

> typically this will group the buses by driver.

> 

> Signed-off-by: Jean Delvare <jdelvare@suse.de>


I like it!

Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
diff mbox series

Patch

--- i2c-tools.orig/tools/i2cbusses.c	2020-09-17 14:29:28.275299253 +0200
+++ i2c-tools/tools/i2cbusses.c	2021-05-27 10:00:04.864407042 +0200
@@ -129,6 +129,14 @@  static struct i2c_adap *more_adapters(st
 	return new_adapters;
 }
 
+static int sort_i2c_busses(const void *a, const void *b)
+{
+	const struct i2c_adap *adap1 = a;
+	const struct i2c_adap *adap2 = b;
+
+	return adap1->nr - adap2->nr;
+}
+
 struct i2c_adap *gather_i2c_busses(void)
 {
 	char s[120];
@@ -314,6 +322,9 @@  struct i2c_adap *gather_i2c_busses(void)
 	closedir(dir);
 
 done:
+	/* Sort by bus number for convenience */
+	qsort(adapters, count, sizeof(struct i2c_adap), sort_i2c_busses);
+
 	return adapters;
 }