[PATCH v1 1/3] i2c: core: Check for error pointer for fwnode

Andy Shevchenko posted 3 patches 3 weeks, 5 days ago
[PATCH v1 1/3] i2c: core: Check for error pointer for fwnode
Posted by Andy Shevchenko 3 weeks, 5 days ago
Theoretically it's possible that fwnode is returned by some API,
that may return an error pointer (and we have, for example,
fwnode_find_reference() which does that). If such an fwnode
is supplied to the i2c core APIs the functions will perform
unneeded loops and checks. Avoid this by preventively checking
for an error pointer and bail out immediately.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/i2c-core-base.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index ae7e9c8b65a6..41c2e46ffb24 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -1090,7 +1090,7 @@ struct i2c_client *i2c_find_device_by_fwnode(struct fwnode_handle *fwnode)
 	struct i2c_client *client;
 	struct device *dev;
 
-	if (!fwnode)
+	if (IS_ERR_OR_NULL(fwnode))
 		return NULL;
 
 	dev = bus_find_device_by_fwnode(&i2c_bus_type, fwnode);
@@ -1875,7 +1875,7 @@ struct i2c_adapter *i2c_find_adapter_by_fwnode(struct fwnode_handle *fwnode)
 	struct i2c_adapter *adapter;
 	struct device *dev;
 
-	if (!fwnode)
+	if (IS_ERR_OR_NULL(fwnode))
 		return NULL;
 
 	dev = bus_find_device(&i2c_bus_type, NULL, fwnode,
-- 
2.50.1
Re: [PATCH v1 1/3] i2c: core: Check for error pointer for fwnode
Posted by Wolfram Sang 3 weeks, 4 days ago
On Mon, Jan 12, 2026 at 02:22:40PM +0100, Andy Shevchenko wrote:
> Theoretically it's possible that fwnode is returned by some API,
> that may return an error pointer (and we have, for example,
> fwnode_find_reference() which does that). If such an fwnode
> is supplied to the i2c core APIs the functions will perform
> unneeded loops and checks. Avoid this by preventively checking
> for an error pointer and bail out immediately.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Applied to for-next, thanks!