Skip to content

Commit 399d6b2

Browse files
Jean DelvareJean Delvare
authored andcommitted
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>
1 parent 796aade commit 399d6b2

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

drivers/i2c/busses/i2c-amd756-s4882.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ static int __init amd756_s4882_init(void)
155155
int i, error;
156156
union i2c_smbus_data ioconfig;
157157

158+
if (!amd756_smbus.dev.parent)
159+
return -ENODEV;
160+
158161
/* Configure the PCA9556 multiplexer */
159162
ioconfig.byte = 0x00; /* All I/O to output mode */
160163
error = i2c_smbus_xfer(&amd756_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03,
@@ -168,11 +171,7 @@ static int __init amd756_s4882_init(void)
168171
/* Unregister physical bus */
169172
error = i2c_del_adapter(&amd756_smbus);
170173
if (error) {
171-
if (error == -EINVAL)
172-
error = -ENODEV;
173-
else
174-
dev_err(&amd756_smbus.dev, "Physical bus removal "
175-
"failed\n");
174+
dev_err(&amd756_smbus.dev, "Physical bus removal failed\n");
176175
goto ERROR0;
177176
}
178177

drivers/i2c/busses/i2c-nforce2-s4985.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ static int __init nforce2_s4985_init(void)
150150
int i, error;
151151
union i2c_smbus_data ioconfig;
152152

153+
if (!nforce2_smbus)
154+
return -ENODEV;
155+
153156
/* Configure the PCA9556 multiplexer */
154157
ioconfig.byte = 0x00; /* All I/O to output mode */
155158
error = i2c_smbus_xfer(nforce2_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03,
@@ -161,8 +164,6 @@ static int __init nforce2_s4985_init(void)
161164
}
162165

163166
/* Unregister physical bus */
164-
if (!nforce2_smbus)
165-
return -ENODEV;
166167
error = i2c_del_adapter(nforce2_smbus);
167168
if (error) {
168169
dev_err(&nforce2_smbus->dev, "Physical bus removal failed\n");

0 commit comments

Comments
 (0)