* [PATCH] iio: hid-sensors: Fix memory leak on failure path in hid_prox_probe() @ 2015-05-06 21:48 Alexey Khoroshilov 2015-05-06 22:00 ` Fabio Estevam 0 siblings, 1 reply; 7+ messages in thread From: Alexey Khoroshilov @ 2015-05-06 21:48 UTC (permalink / raw) To: Jonathan Cameron Cc: Alexey Khoroshilov, Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald, linux-iio, linux-kernel, ldv-project If prox_parse_report() fails, memory allocated for channels is not deallocated, since it is still in local variable channels while kfree() is called with indio_dev->channels. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru> --- drivers/iio/light/hid-sensor-prox.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c index 91ecc46ffeaa..d0d188108a11 100644 --- a/drivers/iio/light/hid-sensor-prox.c +++ b/drivers/iio/light/hid-sensor-prox.c @@ -281,8 +281,9 @@ static int hid_prox_probe(struct platform_device *pdev) ret = prox_parse_report(pdev, hsdev, channels, HID_USAGE_SENSOR_PROX, prox_state); if (ret) { + kfree(channels); dev_err(&pdev->dev, "failed to setup attributes\n"); - goto error_free_dev_mem; + return ret; } indio_dev->channels = channels; -- 1.9.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] iio: hid-sensors: Fix memory leak on failure path in hid_prox_probe() 2015-05-06 21:48 [PATCH] iio: hid-sensors: Fix memory leak on failure path in hid_prox_probe() Alexey Khoroshilov @ 2015-05-06 22:00 ` Fabio Estevam 2015-05-06 22:14 ` Alexey Khoroshilov 2015-05-07 7:43 ` Daniel Baluta 0 siblings, 2 replies; 7+ messages in thread From: Fabio Estevam @ 2015-05-06 22:00 UTC (permalink / raw) To: Alexey Khoroshilov Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald, linux-iio, linux-kernel, ldv-project On Wed, May 6, 2015 at 6:48 PM, Alexey Khoroshilov <khoroshilov@ispras.ru> wrote: > If prox_parse_report() fails, memory allocated for channels is not > deallocated, since it is still in local variable channels > while kfree() is called with indio_dev->channels. > > Found by Linux Driver Verification project (linuxtesting.org). > > Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru> > --- > drivers/iio/light/hid-sensor-prox.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c > index 91ecc46ffeaa..d0d188108a11 100644 > --- a/drivers/iio/light/hid-sensor-prox.c > +++ b/drivers/iio/light/hid-sensor-prox.c > @@ -281,8 +281,9 @@ static int hid_prox_probe(struct platform_device *pdev) > ret = prox_parse_report(pdev, hsdev, channels, > HID_USAGE_SENSOR_PROX, prox_state); > if (ret) { > + kfree(channels); > dev_err(&pdev->dev, "failed to setup attributes\n"); > - goto error_free_dev_mem; > + return ret; Then the other calls to error_free_dev_mem will also miss to call 'kfree(channels)'. What about this fix instead? --- a/drivers/iio/light/hid-sensor-prox.c +++ b/drivers/iio/light/hid-sensor-prox.c @@ -332,7 +332,7 @@ error_remove_trigger: error_unreg_buffer_funcs: iio_triggered_buffer_cleanup(indio_dev); error_free_dev_mem: - kfree(indio_dev->channels); + kfree(channels); return ret; } Regards, Fabio Estevam ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] iio: hid-sensors: Fix memory leak on failure path in hid_prox_probe() 2015-05-06 22:00 ` Fabio Estevam @ 2015-05-06 22:14 ` Alexey Khoroshilov 2015-05-06 22:32 ` Fabio Estevam 2015-05-07 7:43 ` Daniel Baluta 1 sibling, 1 reply; 7+ messages in thread From: Alexey Khoroshilov @ 2015-05-06 22:14 UTC (permalink / raw) To: Fabio Estevam Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald, linux-iio, linux-kernel, ldv-project On 07.05.2015 01:00, Fabio Estevam wrote: > On Wed, May 6, 2015 at 6:48 PM, Alexey Khoroshilov > <khoroshilov@ispras.ru> wrote: >> If prox_parse_report() fails, memory allocated for channels is not >> deallocated, since it is still in local variable channels >> while kfree() is called with indio_dev->channels. >> >> Found by Linux Driver Verification project (linuxtesting.org). >> >> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru> >> --- >> drivers/iio/light/hid-sensor-prox.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c >> index 91ecc46ffeaa..d0d188108a11 100644 >> --- a/drivers/iio/light/hid-sensor-prox.c >> +++ b/drivers/iio/light/hid-sensor-prox.c >> @@ -281,8 +281,9 @@ static int hid_prox_probe(struct platform_device *pdev) >> ret = prox_parse_report(pdev, hsdev, channels, >> HID_USAGE_SENSOR_PROX, prox_state); >> if (ret) { >> + kfree(channels); >> dev_err(&pdev->dev, "failed to setup attributes\n"); >> - goto error_free_dev_mem; >> + return ret; > > Then the other calls to error_free_dev_mem will also miss to call > 'kfree(channels)'. > Not exactly. Other calls are after indio_dev->channels = channels; So, error_free_dev_mem: kfree(indio_dev->channels); works for them well. -- Alexey ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] iio: hid-sensors: Fix memory leak on failure path in hid_prox_probe() 2015-05-06 22:14 ` Alexey Khoroshilov @ 2015-05-06 22:32 ` Fabio Estevam 2015-05-06 23:13 ` Alexey Khoroshilov 0 siblings, 1 reply; 7+ messages in thread From: Fabio Estevam @ 2015-05-06 22:32 UTC (permalink / raw) To: Alexey Khoroshilov Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald, linux-iio, linux-kernel, ldv-project On Wed, May 6, 2015 at 7:14 PM, Alexey Khoroshilov <khoroshilov@ispras.ru> wrote: > Not exactly. Other calls are after > indio_dev->channels = channels; > So, > error_free_dev_mem: > kfree(indio_dev->channels); > works for them well. indio_dev is allocated using devm_ , so you don't need to free it. Your patch is not correct because you only kfree(channels) in the prox_parse_report() error case, but you missed the other subsequent functions. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] iio: hid-sensors: Fix memory leak on failure path in hid_prox_probe() 2015-05-06 22:32 ` Fabio Estevam @ 2015-05-06 23:13 ` Alexey Khoroshilov 0 siblings, 0 replies; 7+ messages in thread From: Alexey Khoroshilov @ 2015-05-06 23:13 UTC (permalink / raw) To: Fabio Estevam Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald, linux-iio, linux-kernel, ldv-project On 07.05.2015 01:32, Fabio Estevam wrote: > On Wed, May 6, 2015 at 7:14 PM, Alexey Khoroshilov > <khoroshilov@ispras.ru> wrote: > >> Not exactly. Other calls are after >> indio_dev->channels = channels; >> So, >> error_free_dev_mem: >> kfree(indio_dev->channels); >> works for them well. > > indio_dev is allocated using devm_ , so you don't need to free it. > > Your patch is not correct because you only kfree(channels) in the > prox_parse_report() error case, but you missed the other subsequent > functions. > No! The other subsequent functions are AFTER (prox_parse_report() error case is the only BEFORE) indio_dev->channels = channels; and all consequent error cases comes to error_free_dev_mem, where error_free_dev_mem: kfree(indio_dev->channels); that is equivalent to kfree(channels); -- Alexey ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] iio: hid-sensors: Fix memory leak on failure path in hid_prox_probe() 2015-05-06 22:00 ` Fabio Estevam 2015-05-06 22:14 ` Alexey Khoroshilov @ 2015-05-07 7:43 ` Daniel Baluta 2015-05-07 9:18 ` Jonathan Cameron 1 sibling, 1 reply; 7+ messages in thread From: Daniel Baluta @ 2015-05-07 7:43 UTC (permalink / raw) To: Fabio Estevam Cc: Alexey Khoroshilov, Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald, linux-iio@vger.kernel.org, linux-kernel, ldv-project On Thu, May 7, 2015 at 1:00 AM, Fabio Estevam <festevam@gmail.com> wrote: > On Wed, May 6, 2015 at 6:48 PM, Alexey Khoroshilov > <khoroshilov@ispras.ru> wrote: >> If prox_parse_report() fails, memory allocated for channels is not >> deallocated, since it is still in local variable channels >> while kfree() is called with indio_dev->channels. >> >> Found by Linux Driver Verification project (linuxtesting.org). >> >> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru> >> --- >> drivers/iio/light/hid-sensor-prox.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c >> index 91ecc46ffeaa..d0d188108a11 100644 >> --- a/drivers/iio/light/hid-sensor-prox.c >> +++ b/drivers/iio/light/hid-sensor-prox.c >> @@ -281,8 +281,9 @@ static int hid_prox_probe(struct platform_device *pdev) >> ret = prox_parse_report(pdev, hsdev, channels, >> HID_USAGE_SENSOR_PROX, prox_state); >> if (ret) { >> + kfree(channels); >> dev_err(&pdev->dev, "failed to setup attributes\n"); >> - goto error_free_dev_mem; >> + return ret; > > Then the other calls to error_free_dev_mem will also miss to call > 'kfree(channels)'. > > What about this fix instead? > > --- a/drivers/iio/light/hid-sensor-prox.c > +++ b/drivers/iio/light/hid-sensor-prox.c > @@ -332,7 +332,7 @@ error_remove_trigger: > error_unreg_buffer_funcs: > iio_triggered_buffer_cleanup(indio_dev); > error_free_dev_mem: > - kfree(indio_dev->channels); > + kfree(channels); > return ret; > } Both patches are correct and I think we should go with Fabio's version since it's consistent with the rest of the code. thanks, Daniel. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] iio: hid-sensors: Fix memory leak on failure path in hid_prox_probe() 2015-05-07 7:43 ` Daniel Baluta @ 2015-05-07 9:18 ` Jonathan Cameron 0 siblings, 0 replies; 7+ messages in thread From: Jonathan Cameron @ 2015-05-07 9:18 UTC (permalink / raw) To: Daniel Baluta, Fabio Estevam Cc: Alexey Khoroshilov, Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald, linux-iio@vger.kernel.org, linux-kernel, ldv-project On 07/05/15 08:43, Daniel Baluta wrote: > On Thu, May 7, 2015 at 1:00 AM, Fabio Estevam <festevam@gmail.com> wrote: >> On Wed, May 6, 2015 at 6:48 PM, Alexey Khoroshilov >> <khoroshilov@ispras.ru> wrote: >>> If prox_parse_report() fails, memory allocated for channels is not >>> deallocated, since it is still in local variable channels >>> while kfree() is called with indio_dev->channels. >>> >>> Found by Linux Driver Verification project (linuxtesting.org). >>> >>> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru> >>> --- >>> drivers/iio/light/hid-sensor-prox.c | 3 ++- >>> 1 file changed, 2 insertions(+), 1 deletion(-) >>> >>> diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c >>> index 91ecc46ffeaa..d0d188108a11 100644 >>> --- a/drivers/iio/light/hid-sensor-prox.c >>> +++ b/drivers/iio/light/hid-sensor-prox.c >>> @@ -281,8 +281,9 @@ static int hid_prox_probe(struct platform_device *pdev) >>> ret = prox_parse_report(pdev, hsdev, channels, >>> HID_USAGE_SENSOR_PROX, prox_state); >>> if (ret) { >>> + kfree(channels); >>> dev_err(&pdev->dev, "failed to setup attributes\n"); >>> - goto error_free_dev_mem; >>> + return ret; >> >> Then the other calls to error_free_dev_mem will also miss to call >> 'kfree(channels)'. >> >> What about this fix instead? >> >> --- a/drivers/iio/light/hid-sensor-prox.c >> +++ b/drivers/iio/light/hid-sensor-prox.c >> @@ -332,7 +332,7 @@ error_remove_trigger: >> error_unreg_buffer_funcs: >> iio_triggered_buffer_cleanup(indio_dev); >> error_free_dev_mem: >> - kfree(indio_dev->channels); >> + kfree(channels); >> return ret; >> } > > Both patches are correct and I think we should go > with Fabio's version since it's consistent with the > rest of the code. > > thanks, > Daniel. > Agreed. I'm travelling (again, yawn) for the next few days but Fabio, could you send a formal version of your patch with signoffs etc and a reported by for Alexey (or under the circumstances Alexey, feel free to sign off on it as well). Thanks, Jonathan ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-05-07 9:18 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-05-06 21:48 [PATCH] iio: hid-sensors: Fix memory leak on failure path in hid_prox_probe() Alexey Khoroshilov 2015-05-06 22:00 ` Fabio Estevam 2015-05-06 22:14 ` Alexey Khoroshilov 2015-05-06 22:32 ` Fabio Estevam 2015-05-06 23:13 ` Alexey Khoroshilov 2015-05-07 7:43 ` Daniel Baluta 2015-05-07 9:18 ` Jonathan Cameron
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox