Commit cb202bb8 authored by Andrey Smirnov's avatar Andrey Smirnov Committed by Guenter Roeck

hwmon: (iio_hwmon) Simplify attr.name generation in iio_hwmon_probe()

Since every call to devm_kasprintf() in the switch statement is mostly
the same, we can move all of the shared code outside and capture
differencies with two helper variables. No functional change intended.
Signed-off-by: default avatarAndrey Smirnov <andrew.smirnov@gmail.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent 5aaa5873
...@@ -92,6 +92,9 @@ static int iio_hwmon_probe(struct platform_device *pdev) ...@@ -92,6 +92,9 @@ static int iio_hwmon_probe(struct platform_device *pdev)
return -ENOMEM; return -ENOMEM;
for (i = 0; i < st->num_channels; i++) { for (i = 0; i < st->num_channels; i++) {
const char *prefix;
int n;
a = devm_kzalloc(dev, sizeof(*a), GFP_KERNEL); a = devm_kzalloc(dev, sizeof(*a), GFP_KERNEL);
if (a == NULL) if (a == NULL)
return -ENOMEM; return -ENOMEM;
...@@ -103,28 +106,28 @@ static int iio_hwmon_probe(struct platform_device *pdev) ...@@ -103,28 +106,28 @@ static int iio_hwmon_probe(struct platform_device *pdev)
switch (type) { switch (type) {
case IIO_VOLTAGE: case IIO_VOLTAGE:
a->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL, n = in_i++;
"in%d_input", prefix = "in";
in_i++);
break; break;
case IIO_TEMP: case IIO_TEMP:
a->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL, n = temp_i++;
"temp%d_input", prefix = "temp";
temp_i++);
break; break;
case IIO_CURRENT: case IIO_CURRENT:
a->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL, n = curr_i++;
"curr%d_input", prefix = "curr";
curr_i++);
break; break;
case IIO_HUMIDITYRELATIVE: case IIO_HUMIDITYRELATIVE:
a->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL, n = humidity_i++;
"humidity%d_input", prefix = "humidity";
humidity_i++);
break; break;
default: default:
return -EINVAL; return -EINVAL;
} }
a->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL,
"%s%d_input",
prefix, n);
if (a->dev_attr.attr.name == NULL) if (a->dev_attr.attr.name == NULL)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment