From: Jonathan Cameron <jic23@kernel.org>
To: Fabio Estevam <festevam@gmail.com>
Cc: khoroshilov@ispras.ru, daniel.baluta@intel.com,
linux-iio@vger.kernel.org, srinivas.pandruvada@linux.intel.com,
Fabio Estevam <fabio.estevam@freescale.com>
Subject: Re: [PATCH v3] iio: light: hid-sensor-prox: Fix memory leak in probe()
Date: Fri, 08 May 2015 09:55:48 -0400 [thread overview]
Message-ID: <554CC064.7020209@kernel.org> (raw)
In-Reply-To: <1431041524-14113-1-git-send-email-festevam@gmail.com>
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;
>
prev parent reply other threads:[~2015-05-08 18:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=554CC064.7020209@kernel.org \
--to=jic23@kernel.org \
--cc=daniel.baluta@intel.com \
--cc=fabio.estevam@freescale.com \
--cc=festevam@gmail.com \
--cc=khoroshilov@ispras.ru \
--cc=linux-iio@vger.kernel.org \
--cc=srinivas.pandruvada@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox