From bd4d1c4c6930606dfcbc9b4c113124d140d5fe0c Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Wed, 2 Jun 2021 11:00:38 +0200 Subject: [PATCH] i2cdetect: Sort the bus list by number 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 --- CHANGES | 1 + tools/i2cbusses.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGES b/CHANGES index aa46d3a..fbf62f7 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,7 @@ i2c-tools CHANGES master decode-dimms: Attempt to decode LPDDR3 modules eeprom, eepromer: removed the tools in favor of eeprog + i2cdetect: Sort the bus list by number i2ctransfer: reverted check for returned length from driver 4.2 (2020-09-22) diff --git a/tools/i2cbusses.c b/tools/i2cbusses.c index b4f00ae..d23ee7a 100644 --- a/tools/i2cbusses.c +++ b/tools/i2cbusses.c @@ -129,6 +129,14 @@ static struct i2c_adap *more_adapters(struct i2c_adap *adapters, int n) 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 @@ found: closedir(dir); done: + /* Sort by bus number for convenience */ + qsort(adapters, count, sizeof(struct i2c_adap), sort_i2c_busses); + return adapters; }