Skip to content

Commit 49a6905

Browse files
sandip4nCalcProgrammer1
authored andcommitted
i2c-smbus: linux: Fix interface detection
There are cases where detection of an interface fails due to lack of permissions when accessing /dev/i2c-*. In some instances, the current code will perform a double readdir() and skip what should have been the next interface to be enumerated. E.g. consider a system with the following configuration $ ls -l /sys/bus/i2c/devices total 0 lrwxrwxrwx. 1 root 0 Sep 4 07:19 i2c-0 -> ../../../devices/platform/AMDI0010:03/i2c-0/ lrwxrwxrwx. 1 root 0 Sep 4 01:49 i2c-1 -> ../../../devices/pci0000:00/0000:00:08.1/0000:03:00.0/i2c-1/ lrwxrwxrwx. 1 root 0 Sep 4 01:50 i2c-10 -> ../../../devices/pci0000:00/0000:00:14.0/i2c-10/ lrwxrwxrwx. 1 root 0 Sep 4 01:49 i2c-2 -> ../../../devices/pci0000:00/0000:00:08.1/0000:03:00.0/i2c-2/ lrwxrwxrwx. 1 root 0 Sep 4 01:49 i2c-3 -> ../../../devices/pci0000:00/0000:00:08.1/0000:03:00.0/i2c-3/ lrwxrwxrwx. 1 root 0 Sep 4 01:49 i2c-4 -> ../../../devices/pci0000:00/0000:00:08.1/0000:03:00.0/i2c-4/ lrwxrwxrwx. 1 root 0 Sep 4 01:49 i2c-5 -> ../../../devices/pci0000:00/0000:00:08.1/0000:03:00.0/drm/card1/card1-eDP-1/i2c-5/ lrwxrwxrwx. 1 root 0 Sep 4 01:49 i2c-6 -> ../../../devices/pci0000:00/0000:00:08.1/0000:03:00.0/drm/card1/card1-DP-1/i2c-6/ lrwxrwxrwx. 1 root 0 Sep 4 01:49 i2c-7 -> ../../../devices/pci0000:00/0000:00:08.1/0000:03:00.0/drm/card1/card1-DP-2/i2c-7/ lrwxrwxrwx. 1 root 0 Sep 4 01:50 i2c-8 -> ../../../devices/pci0000:00/0000:00:14.0/i2c-8/ lrwxrwxrwx. 1 root 0 Sep 4 01:50 i2c-9 -> ../../../devices/pci0000:00/0000:00:14.0/i2c-9/ lrwxrwxrwx. 1 root 0 Sep 4 07:19 i2c-PNP0C50:0e -> ../../../devices/platform/AMDI0010:03/i2c-0/i2c-PNP0C50:0e/ $ openrgb --verbose --list-devices Before: ... Registering I2C interface: /dev/i2c-3 Device 1002:164C Subsystem: 1462:130C Registering I2C interface: /dev/i2c-10 Device 1022:790B Subsystem: 1462:130C Registering I2C interface: /dev/i2c-1 Device 1002:164C Subsystem: 1462:130C Registering I2C interface: /dev/i2c-8 Device 1022:790B Subsystem: 1462:130C [i2c_smbus_linux] Failed to read i2c device PCI device ID Registering I2C interface: /dev/i2c-6 Device 0000:0000 Subsystem: 0000:0000 Registering I2C interface: /dev/i2c-4 Device 1002:164C Subsystem: 1462:130C [i2c_smbus_linux] Failed to read i2c device PCI device ID Registering I2C interface: /dev/i2c-PNP0C50:0e Device 0000:0000 Subsystem: 0000:0000 Registering I2C interface: /dev/i2c-0 Device 0000:0000 Subsystem: 0000:0000 Registering I2C interface: /dev/i2c-9 Device 1022:790B Subsystem: 1462:130C [i2c_smbus_linux] Failed to read i2c device PCI device ID Registering I2C interface: /dev/i2c-7 Device 0000:0000 Subsystem: 0000:0000 [i2c_smbus_linux] Failed to read i2c device PCI device ID Registering I2C interface: /dev/i2c-5 Device 0000:0000 Subsystem: 0000:0000 ... After: ... Registering I2C interface: /dev/i2c-3 Device 1002:164C Subsystem: 1462:130C Registering I2C interface: /dev/i2c-10 Device 1022:790B Subsystem: 1462:130C Registering I2C interface: /dev/i2c-1 Device 1002:164C Subsystem: 1462:130C Registering I2C interface: /dev/i2c-8 Device 1022:790B Subsystem: 1462:130C [i2c_smbus_linux] Failed to read i2c device PCI device ID Registering I2C interface: /dev/i2c-6 Device 0000:0000 Subsystem: 0000:0000 Registering I2C interface: /dev/i2c-4 Device 1002:164C Subsystem: 1462:130C [i2c_smbus_linux] Failed to read i2c device PCI device ID Registering I2C interface: /dev/i2c-PNP0C50:0e Device 0000:0000 Subsystem: 0000:0000 Registering I2C interface: /dev/i2c-2 Device 1002:164C Subsystem: 1462:130C Registering I2C interface: /dev/i2c-0 Device 0000:0000 Subsystem: 0000:0000 Registering I2C interface: /dev/i2c-9 Device 1022:790B Subsystem: 1462:130C [i2c_smbus_linux] Failed to read i2c device PCI device ID Registering I2C interface: /dev/i2c-7 Device 0000:0000 Subsystem: 0000:0000 [i2c_smbus_linux] Failed to read i2c device PCI device ID Registering I2C interface: /dev/i2c-5 Device 0000:0000 Subsystem: 0000:0000 ... Signed-off-by: Sandipan Das <[email protected]>
1 parent f5dc4a6 commit 49a6905

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

i2c_smbus/i2c_smbus_linux.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,7 @@ bool i2c_smbus_linux_detect()
9494
}
9595

9696
// Loop through all entries in i2c-adapter list
97-
ent = readdir(dir);
98-
99-
if(ent == NULL)
100-
{
101-
closedir(dir);
102-
return(false);
103-
}
104-
105-
while(ent != NULL)
97+
while((ent = readdir(dir)) != NULL)
10698
{
10799
if(ent->d_type == DT_DIR || ent->d_type == DT_LNK)
108100
{
@@ -229,7 +221,6 @@ bool i2c_smbus_linux_detect()
229221

230222
if (test_fd < 0)
231223
{
232-
ent = readdir(dir);
233224
ret = false;
234225
}
235226

@@ -249,7 +240,6 @@ bool i2c_smbus_linux_detect()
249240
}
250241
}
251242
}
252-
ent = readdir(dir);
253243
}
254244
closedir(dir);
255245

0 commit comments

Comments
 (0)