* [Patch] iio: accel: bma400: Fix memory leak in bma400_get_steps_reg()
@ 2022-11-10 1:07 Dong Chenchen
2022-11-11 17:42 ` Jagath Jog J
0 siblings, 1 reply; 3+ messages in thread
From: Dong Chenchen @ 2022-11-10 1:07 UTC (permalink / raw)
To: dan, jic23, lars
Cc: jagathjog1996, linux-iio, linux-kernel, yuehaibing, Dong Chenchen
When regmap_bulk_read() fails, it does not free steps_raw,
which will cause a memory leak issue, this patch fixes it.
Fixes: d221de60eee3 ("iio: accel: bma400: Add separate channel for step counter")
Signed-off-by: Dong Chenchen <dongchenchen2@huawei.com>
---
drivers/iio/accel/bma400_core.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/accel/bma400_core.c b/drivers/iio/accel/bma400_core.c
index ad8fce3e08cd..43976cf5a91b 100644
--- a/drivers/iio/accel/bma400_core.c
+++ b/drivers/iio/accel/bma400_core.c
@@ -805,8 +805,10 @@ static int bma400_get_steps_reg(struct bma400_data *data, int *val)
ret = regmap_bulk_read(data->regmap, BMA400_STEP_CNT0_REG,
steps_raw, BMA400_STEP_RAW_LEN);
- if (ret)
+ if (ret) {
+ kfree(steps_raw);
return ret;
+ }
*val = get_unaligned_le24(steps_raw);
kfree(steps_raw);
return IIO_VAL_INT;
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [Patch] iio: accel: bma400: Fix memory leak in bma400_get_steps_reg()
2022-11-10 1:07 [Patch] iio: accel: bma400: Fix memory leak in bma400_get_steps_reg() Dong Chenchen
@ 2022-11-11 17:42 ` Jagath Jog J
2022-11-12 17:49 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Jagath Jog J @ 2022-11-11 17:42 UTC (permalink / raw)
To: Dong Chenchen; +Cc: dan, jic23, lars, linux-iio, linux-kernel, yuehaibing
On Thu, Nov 10, 2022 at 6:37 AM Dong Chenchen <dongchenchen2@huawei.com> wrote:
>
> When regmap_bulk_read() fails, it does not free steps_raw,
> which will cause a memory leak issue, this patch fixes it.
>
> Fixes: d221de60eee3 ("iio: accel: bma400: Add separate channel for step counter")
> Signed-off-by: Dong Chenchen <dongchenchen2@huawei.com>
Reviewed-by: Jagath Jog J <jagathjog1996@gmail.com>
Thanks for catching this
Regards,
Jagath
> ---
> drivers/iio/accel/bma400_core.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/accel/bma400_core.c b/drivers/iio/accel/bma400_core.c
> index ad8fce3e08cd..43976cf5a91b 100644
> --- a/drivers/iio/accel/bma400_core.c
> +++ b/drivers/iio/accel/bma400_core.c
> @@ -805,8 +805,10 @@ static int bma400_get_steps_reg(struct bma400_data *data, int *val)
>
> ret = regmap_bulk_read(data->regmap, BMA400_STEP_CNT0_REG,
> steps_raw, BMA400_STEP_RAW_LEN);
> - if (ret)
> + if (ret) {
> + kfree(steps_raw);
> return ret;
> + }
> *val = get_unaligned_le24(steps_raw);
> kfree(steps_raw);
> return IIO_VAL_INT;
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [Patch] iio: accel: bma400: Fix memory leak in bma400_get_steps_reg()
2022-11-11 17:42 ` Jagath Jog J
@ 2022-11-12 17:49 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2022-11-12 17:49 UTC (permalink / raw)
To: Jagath Jog J
Cc: Dong Chenchen, dan, lars, linux-iio, linux-kernel, yuehaibing
On Fri, 11 Nov 2022 23:12:32 +0530
Jagath Jog J <jagathjog1996@gmail.com> wrote:
> On Thu, Nov 10, 2022 at 6:37 AM Dong Chenchen <dongchenchen2@huawei.com> wrote:
> >
> > When regmap_bulk_read() fails, it does not free steps_raw,
> > which will cause a memory leak issue, this patch fixes it.
> >
> > Fixes: d221de60eee3 ("iio: accel: bma400: Add separate channel for step counter")
> > Signed-off-by: Dong Chenchen <dongchenchen2@huawei.com>
>
> Reviewed-by: Jagath Jog J <jagathjog1996@gmail.com>
>
> Thanks for catching this
Applied to the fixes-togreg branch of iio.git and marked for stable.
Thanks,
Jonathan
>
> Regards,
> Jagath
>
> > ---
> > drivers/iio/accel/bma400_core.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/iio/accel/bma400_core.c b/drivers/iio/accel/bma400_core.c
> > index ad8fce3e08cd..43976cf5a91b 100644
> > --- a/drivers/iio/accel/bma400_core.c
> > +++ b/drivers/iio/accel/bma400_core.c
> > @@ -805,8 +805,10 @@ static int bma400_get_steps_reg(struct bma400_data *data, int *val)
> >
> > ret = regmap_bulk_read(data->regmap, BMA400_STEP_CNT0_REG,
> > steps_raw, BMA400_STEP_RAW_LEN);
> > - if (ret)
> > + if (ret) {
> > + kfree(steps_raw);
> > return ret;
> > + }
> > *val = get_unaligned_le24(steps_raw);
> > kfree(steps_raw);
> > return IIO_VAL_INT;
> > --
> > 2.25.1
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-12 17:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-10 1:07 [Patch] iio: accel: bma400: Fix memory leak in bma400_get_steps_reg() Dong Chenchen
2022-11-11 17:42 ` Jagath Jog J
2022-11-12 17:49 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox