* [RFC] i2c: Skip i2c_for_each_dev() when detection is not supported
@ 2025-06-20 17:31 Abd-Alrhman Masalkhi
0 siblings, 0 replies; only message in thread
From: Abd-Alrhman Masalkhi @ 2025-06-20 17:31 UTC (permalink / raw)
To: wsa+renesas, linux-i2c, linux-kernel
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-06-20 17:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-20 17:31 [RFC] i2c: Skip i2c_for_each_dev() when detection is not supported Abd-Alrhman Masalkhi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).