aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/i2c/i2c-core.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 96f01331544..af5172486fa 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -387,6 +387,27 @@ static int i2c_check_client_addr_validity(const struct i2c_client *client)
387 return 0; 387 return 0;
388} 388}
389 389
390/* And this is a strict address validity check, used when probing. If a
391 * device uses a reserved address, then it shouldn't be probed. 7-bit
392 * addressing is assumed, 10-bit address devices are rare and should be
393 * explicitly enumerated. */
394static int i2c_check_addr_validity(unsigned short addr)
395{
396 /*
397 * Reserved addresses per I2C specification:
398 * 0x00 General call address / START byte
399 * 0x01 CBUS address
400 * 0x02 Reserved for different bus format
401 * 0x03 Reserved for future purposes
402 * 0x04-0x07 Hs-mode master code
403 * 0x78-0x7b 10-bit slave addressing
404 * 0x7c-0x7f Reserved for future purposes
405 */
406 if (addr < 0x08 || addr > 0x77)
407 return -EINVAL;
408 return 0;
409}
410
390/** 411/**
391 * i2c_new_device - instantiate an i2c device 412 * i2c_new_device - instantiate an i2c device
392 * @adap: the adapter managing the device 413 * @adap: the adapter managing the device
@@ -1340,10 +1361,11 @@ static int i2c_detect_address(struct i2c_client *temp_client,
1340 int err; 1361 int err;
1341 1362
1342 /* Make sure the address is valid */ 1363 /* Make sure the address is valid */
1343 if (addr < 0x03 || addr > 0x77) { 1364 err = i2c_check_addr_validity(addr);
1365 if (err) {
1344 dev_warn(&adapter->dev, "Invalid probe address 0x%02x\n", 1366 dev_warn(&adapter->dev, "Invalid probe address 0x%02x\n",
1345 addr); 1367 addr);
1346 return -EINVAL; 1368 return err;
1347 } 1369 }
1348 1370
1349 /* Skip if already in use */ 1371 /* Skip if already in use */
@@ -1446,7 +1468,7 @@ i2c_new_probed_device(struct i2c_adapter *adap,
1446 1468
1447 for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) { 1469 for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) {
1448 /* Check address validity */ 1470 /* Check address validity */
1449 if (addr_list[i] < 0x03 || addr_list[i] > 0x77) { 1471 if (i2c_check_addr_validity(addr_list[i]) < 0) {
1450 dev_warn(&adap->dev, "Invalid 7-bit address " 1472 dev_warn(&adap->dev, "Invalid 7-bit address "
1451 "0x%02x\n", addr_list[i]); 1473 "0x%02x\n", addr_list[i]);
1452 continue; 1474 continue;