Skip to content

Commit

Permalink
hwmon: (iio_hwmon) fix memory leak in name attribute
Browse files Browse the repository at this point in the history
The "name" variable's memory is now freed when the device is destructed
thanks to devm function.

Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>
Reported-by: Guenter Roeck <linux@roeck-us.net>
Fixes: e0f8a24 ("staging:iio::hwmon interface client driver.")
Fixes: 61bb53b ("hwmon: (iio_hwmon) Add support for humidity sensors")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
  • Loading branch information
Quentin Schulz authored and Guenter Roeck committed Jul 31, 2016
1 parent 4c8702b commit 5d17d3b
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions drivers/hwmon/iio_hwmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,24 +110,24 @@ static int iio_hwmon_probe(struct platform_device *pdev)

switch (type) {
case IIO_VOLTAGE:
a->dev_attr.attr.name = kasprintf(GFP_KERNEL,
"in%d_input",
in_i++);
a->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL,
"in%d_input",
in_i++);
break;
case IIO_TEMP:
a->dev_attr.attr.name = kasprintf(GFP_KERNEL,
"temp%d_input",
temp_i++);
a->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL,
"temp%d_input",
temp_i++);
break;
case IIO_CURRENT:
a->dev_attr.attr.name = kasprintf(GFP_KERNEL,
"curr%d_input",
curr_i++);
a->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL,
"curr%d_input",
curr_i++);
break;
case IIO_HUMIDITYRELATIVE:
a->dev_attr.attr.name = kasprintf(GFP_KERNEL,
"humidity%d_input",
humidity_i++);
a->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL,
"humidity%d_input",
humidity_i++);
break;
default:
ret = -EINVAL;
Expand Down

0 comments on commit 5d17d3b

Please sign in to comment.