linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hwmon: (iio_hwmon) Do not duplicate or sanitize fixed string
@ 2018-08-28 18:45 Guenter Roeck
  0 siblings, 0 replies; only message in thread
From: Guenter Roeck @ 2018-08-28 18:45 UTC (permalink / raw)
  To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck

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 | 13 +++++++------
 1 file 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);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2018-08-28 22:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-28 18:45 [PATCH] hwmon: (iio_hwmon) Do not duplicate or sanitize fixed string Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).