Linux IIO development
 help / color / mirror / Atom feed
* [PATCH] iio: adc: at91_adc: fix possible memory leak in at91_adc_allocate_trigger()
@ 2022-10-24  8:45 Yang Yingliang
  2022-10-29 12:47 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Yang Yingliang @ 2022-10-24  8:45 UTC (permalink / raw)
  To: linux-iio; +Cc: mripard, jic23, jonathan.cameron, yangyingliang

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-29 12:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-24  8:45 [PATCH] iio: adc: at91_adc: fix possible memory leak in at91_adc_allocate_trigger() Yang Yingliang
2022-10-29 12:47 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox