提交 51b54ba9 编写于 作者: J Jean Delvare 提交者: Jean Delvare

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: NJean Delvare <khali@linux-fr.org>
Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
上级 d57558d0
...@@ -1508,26 +1508,25 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver) ...@@ -1508,26 +1508,25 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver)
if (!driver->detect || !address_list) if (!driver->detect || !address_list)
return 0; 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 */ /* Set up a temporary client to help detect callback */
temp_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); temp_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
if (!temp_client) if (!temp_client)
return -ENOMEM; return -ENOMEM;
temp_client->adapter = adapter; 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) { for (i = 0; address_list[i] != I2C_CLIENT_END; i += 1) {
dev_dbg(&adapter->dev, "found normal entry for adapter %d, " dev_dbg(&adapter->dev, "found normal entry for adapter %d, "
"addr 0x%02x\n", adap_id, address_list[i]); "addr 0x%02x\n", adap_id, address_list[i]);
temp_client->addr = address_list[i]; temp_client->addr = address_list[i];
err = i2c_detect_address(temp_client, driver); err = i2c_detect_address(temp_client, driver);
if (err) if (unlikely(err))
goto exit_free; break;
} }
exit_free:
kfree(temp_client); kfree(temp_client);
return err; return err;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册