summaryrefslogtreecommitdiff
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2018-08-28 21:41:41 +0300
committerGuenter Roeck <linux@roeck-us.net>2018-10-11 06:37:13 +0300
commit86103cffe8834fef0a342fcac82585ff67cda569 (patch)
tree87c83be14d1c132fc94e17ee7a757736c20859cc /drivers/hwmon
parent0debe4d0b86afa5eb9192595c820ed980cabe38b (diff)
downloadlinux-86103cffe8834fef0a342fcac82585ff67cda569.tar.xz
hwmon: (iio_hwmon) Do not duplicate or sanitize fixed string
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>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/iio_hwmon.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
index 7566991f1c04..eed66e533ee2 100644
--- a/drivers/hwmon/iio_hwmon.c
+++ b/drivers/hwmon/iio_hwmon.c
@@ -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);