From: Yang Yingliang <yangyingliang@huawei.com>
To: <linux-iio@vger.kernel.org>
Cc: <mripard@kernel.org>, <jic23@kernel.org>,
<jonathan.cameron@huawei.com>, <yangyingliang@huawei.com>
Subject: [PATCH] iio: adc: at91_adc: fix possible memory leak in at91_adc_allocate_trigger()
Date: Mon, 24 Oct 2022 16:45:11 +0800 [thread overview]
Message-ID: <20221024084511.815096-1-yangyingliang@huawei.com> (raw)
If iio_trigger_register() returns error, it should call iio_trigger_free()
to give up the reference that hold in iio_trigger_alloc(), so that it can
call iio_trig_release() to free memory when the refcount hit to 0.
Fixes: 0e589d5fb317 ("ARM: AT91: IIO: Add AT91 ADC driver.")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
drivers/iio/adc/at91_adc.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index 532daaa6f943..366e252ebeb0 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -634,8 +634,10 @@ static struct iio_trigger *at91_adc_allocate_trigger(struct iio_dev *idev,
trig->ops = &at91_adc_trigger_ops;
ret = iio_trigger_register(trig);
- if (ret)
+ if (ret) {
+ iio_trigger_free(trig);
return NULL;
+ }
return trig;
}
--
2.25.1
next reply other threads:[~2022-10-24 8:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-24 8:45 Yang Yingliang [this message]
2022-10-29 12:47 ` [PATCH] iio: adc: at91_adc: fix possible memory leak in at91_adc_allocate_trigger() 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=20221024084511.815096-1-yangyingliang@huawei.com \
--to=yangyingliang@huawei.com \
--cc=jic23@kernel.org \
--cc=jonathan.cameron@huawei.com \
--cc=linux-iio@vger.kernel.org \
--cc=mripard@kernel.org \
/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