Skip to contentSkip to conversation

i2c: core: Tidy up fwnode handling

PATCH Applied Andy Shevchenko 2 participants 7 messages Jan 12 – Jan 13

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover i2c: core: Tidy up fwnode handling

There are a few places in i2c core that can be amended when handling fwnode. Hence this miniseries.

Andy Shevchenko (3):
i2c: core: Check for error pointer for fwnode
i2c: core: Replace custom implementation of device_match_fwnode()
i2c: core: Use dev_fwnode()

 drivers/i2c/i2c-core-base.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Signature · 1 line
2.50.1
#1 lore raw

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

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.

---
 drivers/i2c/i2c-core-base.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/i2c-core-base.c +2 -2
index ae7e9c8b65a6..41c2e46ffb24 100644
@@ -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,
Signature · 1 line
2.50.1
Applied
#2 lore raw

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

Quoted 8 lines · Andy Shevchenko

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.

Applied to for-next, thanks!

#3 lore raw

PATCH 2/3 i2c: core: Replace custom implementation of device_match_fwnode()

In reply to Andy Shevchenko

Replace custom implementation of the device_match_fwnode().

---
 drivers/i2c/i2c-core-base.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/i2c-core-base.c +2 -2
index 41c2e46ffb24..b9b44bed3243 100644
@@ -1852,10 +1852,10 @@ EXPORT_SYMBOL_GPL(devm_i2c_add_adapter);
 
 static int i2c_dev_or_parent_fwnode_match(struct device *dev, const void *data)
 {
-	if (dev_fwnode(dev) == data)
+	if (device_match_fwnode(dev, data))
 		return 1;
 
-	if (dev->parent && dev_fwnode(dev->parent) == data)
+	if (dev->parent && device_match_fwnode(dev->parent, data))
 		return 1;
 
 	return 0;
Signature · 1 line
2.50.1
Applied
#4 lore raw

Re: [PATCH v1 2/3] i2c: core: Replace custom implementation of device_match_fwnode()

Quoted 3 lines · Andy Shevchenko

Replace custom implementation of the device_match_fwnode().

Applied to for-next, thanks!

#5 lore raw

PATCH 3/3 i2c: core: Use dev_fwnode()

In reply to Andy Shevchenko

irq_domain_create_linear() takes fwnode as the first argument. It can be extracted from the struct device using dev_fwnode() helper instead of using direct dereference().

So use the dev_fwnode() helper.

---
 drivers/i2c/i2c-core-base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/i2c-core-base.c +1 -1
index b9b44bed3243..f0fb0cfd56e0 100644
@@ -1476,7 +1476,7 @@ static int i2c_setup_host_notify_irq_domain(struct i2c_adapter *adap)
 	if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_HOST_NOTIFY))
 		return 0;
 
-	domain = irq_domain_create_linear(adap->dev.parent->fwnode,
+	domain = irq_domain_create_linear(dev_fwnode(adap->dev.parent),
 					  I2C_ADDR_7BITS_COUNT,
 					  &i2c_host_notify_irq_ops, adap);
 	if (!domain)
Signature · 1 line
2.50.1
Applied
#6 lore raw

Re: [PATCH v1 3/3] i2c: core: Use dev_fwnode()

Quoted 7 lines · Andy Shevchenko

irq_domain_create_linear() takes fwnode as the first argument. It can be extracted from the struct device using dev_fwnode() helper instead of using direct dereference().

So use the dev_fwnode() helper.

Applied to for-next, thanks!