Commit 399d6b26 authored by Jean Delvare's avatar Jean Delvare Committed by Jean Delvare

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: default avatarJean Delvare <khali@linux-fr.org>
Cc: Ingo Molnar <mingo@elte.hu>
parent 796aadeb
...@@ -155,6 +155,9 @@ static int __init amd756_s4882_init(void) ...@@ -155,6 +155,9 @@ static int __init amd756_s4882_init(void)
int i, error; int i, error;
union i2c_smbus_data ioconfig; union i2c_smbus_data ioconfig;
if (!amd756_smbus.dev.parent)
return -ENODEV;
/* Configure the PCA9556 multiplexer */ /* Configure the PCA9556 multiplexer */
ioconfig.byte = 0x00; /* All I/O to output mode */ ioconfig.byte = 0x00; /* All I/O to output mode */
error = i2c_smbus_xfer(&amd756_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03, error = i2c_smbus_xfer(&amd756_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03,
...@@ -168,11 +171,7 @@ static int __init amd756_s4882_init(void) ...@@ -168,11 +171,7 @@ static int __init amd756_s4882_init(void)
/* Unregister physical bus */ /* Unregister physical bus */
error = i2c_del_adapter(&amd756_smbus); error = i2c_del_adapter(&amd756_smbus);
if (error) { if (error) {
if (error == -EINVAL) dev_err(&amd756_smbus.dev, "Physical bus removal failed\n");
error = -ENODEV;
else
dev_err(&amd756_smbus.dev, "Physical bus removal "
"failed\n");
goto ERROR0; goto ERROR0;
} }
......
...@@ -150,6 +150,9 @@ static int __init nforce2_s4985_init(void) ...@@ -150,6 +150,9 @@ static int __init nforce2_s4985_init(void)
int i, error; int i, error;
union i2c_smbus_data ioconfig; union i2c_smbus_data ioconfig;
if (!nforce2_smbus)
return -ENODEV;
/* Configure the PCA9556 multiplexer */ /* Configure the PCA9556 multiplexer */
ioconfig.byte = 0x00; /* All I/O to output mode */ ioconfig.byte = 0x00; /* All I/O to output mode */
error = i2c_smbus_xfer(nforce2_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03, error = i2c_smbus_xfer(nforce2_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03,
...@@ -161,8 +164,6 @@ static int __init nforce2_s4985_init(void) ...@@ -161,8 +164,6 @@ static int __init nforce2_s4985_init(void)
} }
/* Unregister physical bus */ /* Unregister physical bus */
if (!nforce2_smbus)
return -ENODEV;
error = i2c_del_adapter(nforce2_smbus); error = i2c_del_adapter(nforce2_smbus);
if (error) { if (error) {
dev_err(&nforce2_smbus->dev, "Physical bus removal failed\n"); dev_err(&nforce2_smbus->dev, "Physical bus removal failed\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment