Skip to content

Commit 8031d79

Browse files
author
Jean Delvare
committed
i2c: Make i2c_default_probe self-sufficient
Make i2c_default_probe self-sufficient, so that callers don't have to do functionality checks themselves. This ensures everything is and will stay consistent. Signed-off-by: Jean Delvare <khali@linux-fr.org>
1 parent d670328 commit 8031d79

1 file changed

Lines changed: 10 additions & 22 deletions

File tree

‎drivers/i2c/i2c-core.c‎

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,13 +1378,17 @@ static int i2c_default_probe(struct i2c_adapter *adap, unsigned short addr)
13781378
I2C_SMBUS_BYTE_DATA, &dummy);
13791379
else
13801380
#endif
1381-
if ((addr & ~0x07) == 0x30 || (addr & ~0x0f) == 0x50
1382-
|| !i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK))
1383-
err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0,
1384-
I2C_SMBUS_BYTE, &dummy);
1385-
else
1381+
if (!((addr & ~0x07) == 0x30 || (addr & ~0x0f) == 0x50)
1382+
&& i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK))
13861383
err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_WRITE, 0,
13871384
I2C_SMBUS_QUICK, NULL);
1385+
else if (i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_BYTE))
1386+
err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0,
1387+
I2C_SMBUS_BYTE, &dummy);
1388+
else {
1389+
dev_warn(&adap->dev, "No suitable probing method supported\n");
1390+
err = -EOPNOTSUPP;
1391+
}
13881392

13891393
return err >= 0;
13901394
}
@@ -1465,16 +1469,6 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver)
14651469
if (!(adapter->class & driver->class))
14661470
goto exit_free;
14671471

1468-
/* Stop here if the bus doesn't support probing */
1469-
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE)) {
1470-
if (address_list[0] == I2C_CLIENT_END)
1471-
goto exit_free;
1472-
1473-
dev_warn(&adapter->dev, "Probing not supported\n");
1474-
err = -EOPNOTSUPP;
1475-
goto exit_free;
1476-
}
1477-
14781472
for (i = 0; address_list[i] != I2C_CLIENT_END; i += 1) {
14791473
dev_dbg(&adapter->dev, "found normal entry for adapter %d, "
14801474
"addr 0x%02x\n", adap_id, address_list[i]);
@@ -1504,14 +1498,8 @@ i2c_new_probed_device(struct i2c_adapter *adap,
15041498
{
15051499
int i;
15061500

1507-
if (!probe) {
1508-
/* Stop here if the bus doesn't support probing */
1509-
if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_BYTE)) {
1510-
dev_err(&adap->dev, "Probing not supported\n");
1511-
return NULL;
1512-
}
1501+
if (!probe)
15131502
probe = i2c_default_probe;
1514-
}
15151503

15161504
for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) {
15171505
/* Check address validity */

0 commit comments

Comments
 (0)