public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] iio: light: hid-sensor-prox: Fix memory leak in probe()
@ 2015-05-07 23:32 Fabio Estevam
  2015-05-08  0:23 ` Srinivas Pandruvada
  2015-05-08 13:55 ` Jonathan Cameron
  0 siblings, 2 replies; 3+ messages in thread
From: Fabio Estevam @ 2015-05-07 23:32 UTC (permalink / raw)
  To: jic23
  Cc: khoroshilov, daniel.baluta, linux-iio, srinivas.pandruvada,
	Fabio Estevam

From: Fabio Estevam <fabio.estevam@freescale.com>

'channels' is allocated via kmemdup and it is never freed.

Use 'indio_dev->channels' directly instead, so that we avoid such
memory leak problem.

Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Reported-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
Build-tested only. 

Changes since v2:
- Get rid of the channels and use indio_dev->channels instead.

 drivers/iio/light/hid-sensor-prox.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c
index 91ecc46..124a8f8 100644
--- a/drivers/iio/light/hid-sensor-prox.c
+++ b/drivers/iio/light/hid-sensor-prox.c
@@ -253,7 +253,6 @@ static int hid_prox_probe(struct platform_device *pdev)
 	struct iio_dev *indio_dev;
 	struct prox_state *prox_state;
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
-	struct iio_chan_spec *channels;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev,
 				sizeof(struct prox_state));
@@ -272,20 +271,21 @@ static int hid_prox_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	channels = kmemdup(prox_channels, sizeof(prox_channels), GFP_KERNEL);
-	if (!channels) {
+	indio_dev->channels = kmemdup(prox_channels, sizeof(prox_channels),
+				      GFP_KERNEL);
+	if (!indio_dev->channels) {
 		dev_err(&pdev->dev, "failed to duplicate channels\n");
 		return -ENOMEM;
 	}
 
-	ret = prox_parse_report(pdev, hsdev, channels,
+	ret = prox_parse_report(pdev, hsdev,
+				(struct iio_chan_spec *)indio_dev->channels,
 				HID_USAGE_SENSOR_PROX, prox_state);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup attributes\n");
 		goto error_free_dev_mem;
 	}
 
-	indio_dev->channels = channels;
 	indio_dev->num_channels =
 				ARRAY_SIZE(prox_channels);
 	indio_dev->dev.parent = &pdev->dev;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] iio: light: hid-sensor-prox: Fix memory leak in probe()
  2015-05-07 23:32 [PATCH v3] iio: light: hid-sensor-prox: Fix memory leak in probe() Fabio Estevam
@ 2015-05-08  0:23 ` Srinivas Pandruvada
  2015-05-08 13:55 ` Jonathan Cameron
  1 sibling, 0 replies; 3+ messages in thread
From: Srinivas Pandruvada @ 2015-05-08  0:23 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: jic23, khoroshilov, daniel.baluta, linux-iio, Fabio Estevam

On Thu, 2015-05-07 at 20:32 -0300, Fabio Estevam wrote:
> From: Fabio Estevam <fabio.estevam@freescale.com>
> 
> 'channels' is allocated via kmemdup and it is never freed.
> 
> Use 'indio_dev->channels' directly instead, so that we avoid such
> memory leak problem.
> 
> Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> Reported-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

Reviewed-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>

> ---
> Build-tested only. 
> 
> Changes since v2:
> - Get rid of the channels and use indio_dev->channels instead.
> 
>  drivers/iio/light/hid-sensor-prox.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c
> index 91ecc46..124a8f8 100644
> --- a/drivers/iio/light/hid-sensor-prox.c
> +++ b/drivers/iio/light/hid-sensor-prox.c
> @@ -253,7 +253,6 @@ static int hid_prox_probe(struct platform_device *pdev)
>  	struct iio_dev *indio_dev;
>  	struct prox_state *prox_state;
>  	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
> -	struct iio_chan_spec *channels;
>  
>  	indio_dev = devm_iio_device_alloc(&pdev->dev,
>  				sizeof(struct prox_state));
> @@ -272,20 +271,21 @@ static int hid_prox_probe(struct platform_device *pdev)
>  		return ret;
>  	}
>  
> -	channels = kmemdup(prox_channels, sizeof(prox_channels), GFP_KERNEL);
> -	if (!channels) {
> +	indio_dev->channels = kmemdup(prox_channels, sizeof(prox_channels),
> +				      GFP_KERNEL);
> +	if (!indio_dev->channels) {
>  		dev_err(&pdev->dev, "failed to duplicate channels\n");
>  		return -ENOMEM;
>  	}
>  
> -	ret = prox_parse_report(pdev, hsdev, channels,
> +	ret = prox_parse_report(pdev, hsdev,
> +				(struct iio_chan_spec *)indio_dev->channels,
>  				HID_USAGE_SENSOR_PROX, prox_state);
>  	if (ret) {
>  		dev_err(&pdev->dev, "failed to setup attributes\n");
>  		goto error_free_dev_mem;
>  	}
>  
> -	indio_dev->channels = channels;
>  	indio_dev->num_channels =
>  				ARRAY_SIZE(prox_channels);
>  	indio_dev->dev.parent = &pdev->dev;



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] iio: light: hid-sensor-prox: Fix memory leak in probe()
  2015-05-07 23:32 [PATCH v3] iio: light: hid-sensor-prox: Fix memory leak in probe() Fabio Estevam
  2015-05-08  0:23 ` Srinivas Pandruvada
@ 2015-05-08 13:55 ` Jonathan Cameron
  1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2015-05-08 13:55 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: khoroshilov, daniel.baluta, linux-iio, srinivas.pandruvada,
	Fabio Estevam

On 07/05/15 19:32, Fabio Estevam wrote:
> From: Fabio Estevam <fabio.estevam@freescale.com>
> 
> 'channels' is allocated via kmemdup and it is never freed.
> 
> Use 'indio_dev->channels' directly instead, so that we avoid such
> memory leak problem.
> 
> Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> Reported-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Applied to the fixes-togreg branch of iio.git

Thanks,

Jonathan
> ---
> Build-tested only. 
> 
> Changes since v2:
> - Get rid of the channels and use indio_dev->channels instead.
> 
>  drivers/iio/light/hid-sensor-prox.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c
> index 91ecc46..124a8f8 100644
> --- a/drivers/iio/light/hid-sensor-prox.c
> +++ b/drivers/iio/light/hid-sensor-prox.c
> @@ -253,7 +253,6 @@ static int hid_prox_probe(struct platform_device *pdev)
>  	struct iio_dev *indio_dev;
>  	struct prox_state *prox_state;
>  	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
> -	struct iio_chan_spec *channels;
>  
>  	indio_dev = devm_iio_device_alloc(&pdev->dev,
>  				sizeof(struct prox_state));
> @@ -272,20 +271,21 @@ static int hid_prox_probe(struct platform_device *pdev)
>  		return ret;
>  	}
>  
> -	channels = kmemdup(prox_channels, sizeof(prox_channels), GFP_KERNEL);
> -	if (!channels) {
> +	indio_dev->channels = kmemdup(prox_channels, sizeof(prox_channels),
> +				      GFP_KERNEL);
> +	if (!indio_dev->channels) {
>  		dev_err(&pdev->dev, "failed to duplicate channels\n");
>  		return -ENOMEM;
>  	}
>  
> -	ret = prox_parse_report(pdev, hsdev, channels,
> +	ret = prox_parse_report(pdev, hsdev,
> +				(struct iio_chan_spec *)indio_dev->channels,
>  				HID_USAGE_SENSOR_PROX, prox_state);
>  	if (ret) {
>  		dev_err(&pdev->dev, "failed to setup attributes\n");
>  		goto error_free_dev_mem;
>  	}
>  
> -	indio_dev->channels = channels;
>  	indio_dev->num_channels =
>  				ARRAY_SIZE(prox_channels);
>  	indio_dev->dev.parent = &pdev->dev;
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-05-08 18:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-07 23:32 [PATCH v3] iio: light: hid-sensor-prox: Fix memory leak in probe() Fabio Estevam
2015-05-08  0:23 ` Srinivas Pandruvada
2015-05-08 13:55 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox