Skip to content

Commit

Permalink
hwmon: (iio_hwmon) Do not duplicate or sanitize fixed string
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
groeck committed Oct 11, 2018
1 parent 0debe4d commit 86103cf
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions drivers/hwmon/iio_hwmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 86103cf

Please sign in to comment.