Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

i2c: Fix oops on bus multiplexer driver loading

The two I2C bus multiplexer drivers (i2c-amd756-s4882 and
i2c-nforce2-s4985) make use of the bus they want to multiplex before
checking if it is really present. Swap the instructions to test for
presence first. This fixes a oops reported by Ingo Molnar.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Ingo Molnar <mingo@elte.hu>

authored by

Jean Delvare and committed by
Jean Delvare
399d6b26 796aadeb

+7 -7
+4 -5
drivers/i2c/busses/i2c-amd756-s4882.c
··· 155 155 int i, error; 156 156 union i2c_smbus_data ioconfig; 157 157 158 + if (!amd756_smbus.dev.parent) 159 + return -ENODEV; 160 + 158 161 /* Configure the PCA9556 multiplexer */ 159 162 ioconfig.byte = 0x00; /* All I/O to output mode */ 160 163 error = i2c_smbus_xfer(&amd756_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03, ··· 171 168 /* Unregister physical bus */ 172 169 error = i2c_del_adapter(&amd756_smbus); 173 170 if (error) { 174 - if (error == -EINVAL) 175 - error = -ENODEV; 176 - else 177 - dev_err(&amd756_smbus.dev, "Physical bus removal " 178 - "failed\n"); 171 + dev_err(&amd756_smbus.dev, "Physical bus removal failed\n"); 179 172 goto ERROR0; 180 173 } 181 174
+3 -2
drivers/i2c/busses/i2c-nforce2-s4985.c
··· 150 150 int i, error; 151 151 union i2c_smbus_data ioconfig; 152 152 153 + if (!nforce2_smbus) 154 + return -ENODEV; 155 + 153 156 /* Configure the PCA9556 multiplexer */ 154 157 ioconfig.byte = 0x00; /* All I/O to output mode */ 155 158 error = i2c_smbus_xfer(nforce2_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03, ··· 164 161 } 165 162 166 163 /* Unregister physical bus */ 167 - if (!nforce2_smbus) 168 - return -ENODEV; 169 164 error = i2c_del_adapter(nforce2_smbus); 170 165 if (error) { 171 166 dev_err(&nforce2_smbus->dev, "Physical bus removal failed\n");