]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
iio: adc: at91_adc: fix possible memory leak in at91_adc_allocate_trigger()
authorYang Yingliang <yangyingliang@huawei.com>
Mon, 24 Oct 2022 08:45:11 +0000 (16:45 +0800)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 14 Dec 2022 12:59:30 +0000 (13:59 +0100)
commit 65f20301607d07ee279b0804d11a05a62a6c1a1c upstream.

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>
Link: https://lore.kernel.org/r/20221024084511.815096-1-yangyingliang@huawei.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 1bf8c0aff8fb5c4edf3ba6728e6bedbd610d7f4b)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
drivers/iio/adc/at91_adc.c

index 5a7d3a3a5fa82f12a5f18ad7bb36cf9394273ca6..d61b8ce643a80592a3a039c158cf47fbf98b7ac8 100644 (file)
@@ -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;
 }