Be more careful when probing i2c buses by checking the bus name

The current approach to detection of RGB controllers accessible via i2c bus is a bit optimistic. OpenRGB currently relies on matching the device and vendor IDs and trying every i2c bus that matches. Especially on Linux, this approach is not always sufficient. For example, my Sapphire Radeon 9070XT exposes the following i2c buses on Linux.

i2c-1	i2c       	AMDGPU SMU 0                    	I2C adapter
i2c-2	i2c       	AMDGPU SMU 1                    	I2C adapter
i2c-3	i2c       	AMDGPU DM i2c hw bus 0          	I2C adapter
i2c-4	i2c       	AMDGPU DM i2c hw bus 1          	I2C adapter
i2c-5	i2c       	AMDGPU DM i2c hw bus 2          	I2C adapter
i2c-6	i2c       	AMDGPU DM i2c hw bus 3          	I2C adapter
i2c-7	i2c       	AMDGPU DM i2c OEM bus           	I2C adapter
i2c-8	i2c       	AMDGPU DM aux hw bus 0          	I2C adapter
i2c-9	i2c       	AMDGPU DM aux hw bus 1          	I2C adapter

It is, however, only the AMDGPU DM i2c OEM bus that has the RGB control. Attempting to randomly poke other i2c buses may put the GPU into some unexpected state and cause system instability and other issues. Recent relevant bug report: #4888

This MR adds a check of the i2c bus name against a list of known valid bus names. Bus names are set either by the kernel driver or OpenRGB so there should not be too much variety that would spin out of control.

Things to do:

  • Check functionality on Windows (Verified working)
  • Review that nothing would break on GPUs from vendors other that Sapphire as I cannot test this

Things to discuss:

  • This code uses the device_name member of the i2c_smbus_interface class to get the bus name. To make that useful on Linux, I had to change the "source" of the device_name from the path to the i2c device (/dev/i2c-XX) to the name exposed via /sys/bus/i2c/devices/i2c-XX/name. Could this be a problem? One possible annoyance is that this affects the content of the "Location" field on the "Information" tab, which is then a bit inconsistent with the rest of the devices. I can always add another member to the i2c_smbus_interface class if we want to preserve the /dev/i2c-XX path.
Edited by MadCatX

Merge request reports

Loading