i2c: Skip i2c_for_each_dev() when detection is not supported
While reviewing the I2C core, I noticed that i2c_for_each_dev() is invoked in i2c_register_driver() regardless of whether the driver actually supports device detection, as follow:
/* When registration returns, the driver core
* will have called probe() for all matching-dbut-unbound devices.
*/
res = driver_register(&driver->driver);
if (res)
return res;
pr_debug("driver [%s] registered\n", driver->driver.name);
i2c_for_each_dev(driver, __process_new_driver);However, the first check inside i2c_detect() is:
if (!driver->detect || !address_list)
return 0;This check happens only after iterating over all registered I2C devices via i2c_for_each_dev(). Unless I am missing something, this seems to me just wasting processing time for drivers that do not support detection.
To avoid this, I propose guarding the call to i2c_for_each_dev() like this:
/* When registration returns, the driver core
* will have called probe() for all matching-dbut-unbound devices.
*/
res = driver_register(&driver->driver);
if (res)
return res;
pr_debug("driver [%s] registered\n", driver->driver.name);
if (driver->detect && driver->address_list)
i2c_for_each_dev(driver, __process_new_driver);This would ensure that i2c_detect() is only called when there is an actual possibility of detection succeeding, making the driver registration path more efficient.
Please let me know if this change makes sense. I would be happy to submit a patch.
Best regards,
Abd-Alrhman Masalkhi