hwmon: (iio_hwmon) Do not duplicate or sanitize fixed string
authorGuenter Roeck <linux@roeck-us.net>
Tue, 28 Aug 2018 18:41:41 +0000 (11:41 -0700)
committerGuenter Roeck <linux@roeck-us.net>
Thu, 11 Oct 2018 03:37:13 +0000 (20:37 -0700)
Calling devm_kstrdup() on a fixed string is unnecessary, as is validating
its contents. Rearrange the code to avoid both.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/iio_hwmon.c

index 7566991..eed66e5 100644 (file)
@@ -137,14 +137,15 @@ static int iio_hwmon_probe(struct platform_device *pdev)
        st->attr_group.attrs = st->attrs;
        st->groups[0] = &st->attr_group;
 
-       if (dev->of_node)
+       if (dev->of_node) {
                sname = devm_kasprintf(dev, GFP_KERNEL, "%pOFn", dev->of_node);
-       else
-               sname = devm_kstrdup(dev, "iio_hwmon", GFP_KERNEL);
-       if (!sname)
-               return -ENOMEM;
+               if (!sname)
+                       return -ENOMEM;
+               strreplace(sname, '-', '_');
+       } else {
+               sname = "iio_hwmon";
+       }
 
-       strreplace(sname, '-', '_');
        hwmon_dev = devm_hwmon_device_register_with_groups(dev, sname, st,
                                                           st->groups);
        return PTR_ERR_OR_ZERO(hwmon_dev);