All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i2cdetect: Sort the bus list by number
@ 2021-05-27  8:07 Jean Delvare
  2021-05-28 19:13 ` Wolfram Sang
  0 siblings, 1 reply; 2+ messages in thread
From: Jean Delvare @ 2021-05-27  8:07 UTC (permalink / raw)
  To: Linux I2C

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(+)

--- 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;
 }
 


-- 
Jean Delvare
SUSE L3 Support

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] i2cdetect: Sort the bus list by number
  2021-05-27  8:07 [PATCH] i2cdetect: Sort the bus list by number Jean Delvare
@ 2021-05-28 19:13 ` Wolfram Sang
  0 siblings, 0 replies; 2+ messages in thread
From: Wolfram Sang @ 2021-05-28 19:13 UTC (permalink / raw)
  To: Jean Delvare; +Cc: Linux I2C

[-- Attachment #1: Type: text/plain, Size: 314 bytes --]

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>


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-28 19:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-27  8:07 [PATCH] i2cdetect: Sort the bus list by number Jean Delvare
2021-05-28 19:13 ` Wolfram Sang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.