diff mbox series

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

Message ID 20221024084511.815096-1-yangyingliang@huawei.com (mailing list archive)
State Accepted
Headers show
Series iio: adc: at91_adc: fix possible memory leak in at91_adc_allocate_trigger() | expand

Commit Message

Yang Yingliang Oct. 24, 2022, 8:45 a.m. UTC
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(-)

Comments

Jonathan Cameron Oct. 29, 2022, 12:47 p.m. UTC | #1
On Mon, 24 Oct 2022 16:45:11 +0800
Yang Yingliang <yangyingliang@huawei.com> wrote:

> 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>
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

> ---
>  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;
>  }
diff mbox series

Patch

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;
 }