aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2010-10-24 12:16:58 -0400
committerJean Delvare <khali@endymion.delvare>2010-10-24 12:16:58 -0400
commit51b54ba9bb16b9fc28ec88006778d330af00bf8b (patch)
treed6d6da1639ada491d731d7452f6fc9272451944e /drivers/i2c
parentd57558d0f3b41bb260aaa327150d49f1810461f5 (diff)
i2c: Optimize function i2c_detect()
Check the class flags before allocating the temporary i2c_client structure, to avoid allocating it when we don't need it. Also optimize the inner loop a bit. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/i2c-core.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index bdadfaf3fe10..d231f683f576 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1508,26 +1508,25 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver)
1508 if (!driver->detect || !address_list) 1508 if (!driver->detect || !address_list)
1509 return 0; 1509 return 0;
1510 1510
1511 /* Stop here if the classes do not match */
1512 if (!(adapter->class & driver->class))
1513 return 0;
1514
1511 /* Set up a temporary client to help detect callback */ 1515 /* Set up a temporary client to help detect callback */
1512 temp_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); 1516 temp_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
1513 if (!temp_client) 1517 if (!temp_client)
1514 return -ENOMEM; 1518 return -ENOMEM;
1515 temp_client->adapter = adapter; 1519 temp_client->adapter = adapter;
1516 1520
1517 /* Stop here if the classes do not match */
1518 if (!(adapter->class & driver->class))
1519 goto exit_free;
1520
1521 for (i = 0; address_list[i] != I2C_CLIENT_END; i += 1) { 1521 for (i = 0; address_list[i] != I2C_CLIENT_END; i += 1) {
1522 dev_dbg(&adapter->dev, "found normal entry for adapter %d, " 1522 dev_dbg(&adapter->dev, "found normal entry for adapter %d, "
1523 "addr 0x%02x\n", adap_id, address_list[i]); 1523 "addr 0x%02x\n", adap_id, address_list[i]);
1524 temp_client->addr = address_list[i]; 1524 temp_client->addr = address_list[i];
1525 err = i2c_detect_address(temp_client, driver); 1525 err = i2c_detect_address(temp_client, driver);
1526 if (err) 1526 if (unlikely(err))
1527 goto exit_free; 1527 break;
1528 } 1528 }
1529 1529
1530 exit_free:
1531 kfree(temp_client); 1530 kfree(temp_client);
1532 return err; 1531 return err;
1533} 1532}