Linux IIO development
 help / color / mirror / Atom feed
From: Dong Chenchen <dongchenchen2@huawei.com>
To: <dan@dlrobertson.com>, <jic23@kernel.org>, <lars@metafoo.de>
Cc: <jagathjog1996@gmail.com>, <linux-iio@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <yuehaibing@huawei.com>,
	Dong Chenchen <dongchenchen2@huawei.com>
Subject: [Patch] iio: accel: bma400: Fix memory leak in bma400_get_steps_reg()
Date: Thu, 10 Nov 2022 09:07:26 +0800	[thread overview]
Message-ID: <20221110010726.235601-1-dongchenchen2@huawei.com> (raw)

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


             reply	other threads:[~2022-11-10  1:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-10  1:07 Dong Chenchen [this message]
2022-11-11 17:42 ` [Patch] iio: accel: bma400: Fix memory leak in bma400_get_steps_reg() Jagath Jog J
2022-11-12 17:49   ` Jonathan Cameron

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=20221110010726.235601-1-dongchenchen2@huawei.com \
    --to=dongchenchen2@huawei.com \
    --cc=dan@dlrobertson.com \
    --cc=jagathjog1996@gmail.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yuehaibing@huawei.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