Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1450450 > unrolled thread
| Started by | Quentin Schulz <quentin.schulz@free-electrons.com> |
|---|---|
| First post | 2016-07-26 09:50 +0200 |
| Last post | 2016-07-26 18:00 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH] hwmon: iio_hwmon: fix memory leak in name attribute Quentin Schulz <quentin.schulz@free-electrons.com> - 2016-07-26 09:50 +0200
Re: [PATCH] hwmon: iio_hwmon: fix memory leak in name attribute Guenter Roeck <linux@roeck-us.net> - 2016-07-26 18:00 +0200
| From | Quentin Schulz <quentin.schulz@free-electrons.com> |
|---|---|
| Date | 2016-07-26 09:50 +0200 |
| Subject | [PATCH] hwmon: iio_hwmon: fix memory leak in name attribute |
| Message-ID | <rZ5hM-7Cz-23@gated-at.bofh.it> |
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>
---
drivers/hwmon/iio_hwmon.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
index 0a00bfb..777f2b5 100644
--- a/drivers/hwmon/iio_hwmon.c
+++ b/drivers/hwmon/iio_hwmon.c
@@ -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;
--
2.5.0
[toc] | [next] | [standalone]
| From | Guenter Roeck <linux@roeck-us.net> |
|---|---|
| Date | 2016-07-26 18:00 +0200 |
| Message-ID | <rZcVX-3LJ-9@gated-at.bofh.it> |
| In reply to | #1450450 |
On Tue, Jul 26, 2016 at 09:47:09AM +0200, Quentin Schulz wrote:
> 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>
Applied.
Thanks,
Guenter
> ---
> drivers/hwmon/iio_hwmon.c | 24 ++++++++++++------------
> 1 file changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
> index 0a00bfb..777f2b5 100644
> --- a/drivers/hwmon/iio_hwmon.c
> +++ b/drivers/hwmon/iio_hwmon.c
> @@ -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;
> --
> 2.5.0
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web