]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
i2c: core: Drop duplicate check before calling OF APIs
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Wed, 16 Apr 2025 07:01:31 +0000 (10:01 +0300)
committerWolfram Sang <wsa+renesas@sang-engineering.com>
Wed, 16 Apr 2025 16:05:21 +0000 (18:05 +0200)
OF APIs are usually NULL-aware and return an error in case when
device node is not present or supported. We already have a check
for the returned value, no need to check for the parameter.

Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
drivers/i2c/i2c-core-base.c

index 7ad1ad5c8c3f56943b627254b1fdbf8f787afdb5..c14ffd6190d3343c1e0888e6631d07a37088d4af 100644 (file)
@@ -1209,11 +1209,9 @@ struct i2c_client *i2c_new_ancillary_device(struct i2c_client *client,
        u32 addr = default_addr;
        int i;
 
-       if (np) {
-               i = of_property_match_string(np, "reg-names", name);
-               if (i >= 0)
-                       of_property_read_u32_index(np, "reg", i, &addr);
-       }
+       i = of_property_match_string(np, "reg-names", name);
+       if (i >= 0)
+               of_property_read_u32_index(np, "reg", i, &addr);
 
        dev_dbg(&client->adapter->dev, "Address for %s : 0x%x\n", name, addr);
        return i2c_new_dummy_device(client->adapter, addr);
@@ -1651,12 +1649,10 @@ int i2c_add_adapter(struct i2c_adapter *adapter)
        struct device *dev = &adapter->dev;
        int id;
 
-       if (dev->of_node) {
-               id = of_alias_get_id(dev->of_node, "i2c");
-               if (id >= 0) {
-                       adapter->nr = id;
-                       return __i2c_add_numbered_adapter(adapter);
-               }
+       id = of_alias_get_id(dev->of_node, "i2c");
+       if (id >= 0) {
+               adapter->nr = id;
+               return __i2c_add_numbered_adapter(adapter);
        }
 
        mutex_lock(&core_lock);