Skip to contentSkip to conversation

iio: adc: at91_adc: fix possible memory leak in at91_adc_allocate_trigger()

PATCH Applied Yang Yingliang 2 participants 2 messages Oct 24, 2022 – Oct 29, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: adc: at91_adc: fix possible memory leak in at91_adc_allocate_trigger()

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.")
---
 drivers/iio/adc/at91_adc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/at91_adc.c +3 -1
index 532daaa6f943..366e252ebeb0 100644
@@ -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;
 }
Signature · 1 line
2.25.1
maintainer Applied
#1 lore raw
Quoted 6 lines · On Mon, 24 Oct 2022 16:45:11 +0800 Yang Yingliang <[email protected]>…

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.")

Seems straight forward so I'm not that bothered about getting extra tags on this.

Applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan

Quoted 20 lines
---
 drivers/iio/adc/at91_adc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/at91_adc.c +3 -1
index 532daaa6f943..366e252ebeb0 100644
@@ -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;
 }