diff options
author | Jean Delvare <khali@linux-fr.org> | 2010-10-24 20:16:58 +0400 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2010-10-24 20:16:58 +0400 |
commit | 51b54ba9bb16b9fc28ec88006778d330af00bf8b (patch) | |
tree | d6d6da1639ada491d731d7452f6fc9272451944e /drivers/i2c | |
parent | d57558d0f3b41bb260aaa327150d49f1810461f5 (diff) | |
download | linux-51b54ba9bb16b9fc28ec88006778d330af00bf8b.tar.xz |
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.c | 13 |
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) if (!driver->detect || !address_list) return 0; + /* Stop here if the classes do not match */ + if (!(adapter->class & driver->class)) + return 0; + /* Set up a temporary client to help detect callback */ temp_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); if (!temp_client) return -ENOMEM; temp_client->adapter = adapter; - /* Stop here if the classes do not match */ - if (!(adapter->class & driver->class)) - goto exit_free; - for (i = 0; address_list[i] != I2C_CLIENT_END; i += 1) { dev_dbg(&adapter->dev, "found normal entry for adapter %d, " "addr 0x%02x\n", adap_id, address_list[i]); temp_client->addr = address_list[i]; err = i2c_detect_address(temp_client, driver); - if (err) - goto exit_free; + if (unlikely(err)) + break; } - exit_free: kfree(temp_client); return err; } |