]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
iio: inkern: call iio_device_put() only on mapped devices
authorJoe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
Wed, 4 Dec 2024 11:13:42 +0000 (20:13 +0900)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 8 Dec 2024 16:49:09 +0000 (16:49 +0000)
In the error path of iio_channel_get_all(), iio_device_put() is called
on all IIO devices, which can cause a refcount imbalance. Fix this error
by calling iio_device_put() only on IIO devices whose refcounts were
previously incremented by iio_device_get().

Fixes: 314be14bb893 ("iio: Rename _st_ functions to loose the bit that meant the staging version.")
Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
Link: https://patch.msgid.link/20241204111342.1246706-1-joe@pf.is.s.u-tokyo.ac.jp
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/inkern.c

index 136b225b6bc8a128c5406b9e982f3668beafe142..9050a59129e699a909aa1b2fd71720e2ce758708 100644 (file)
@@ -500,7 +500,7 @@ struct iio_channel *iio_channel_get_all(struct device *dev)
        return_ptr(chans);
 
 error_free_chans:
-       for (i = 0; i < nummaps; i++)
+       for (i = 0; i < mapind; i++)
                iio_device_put(chans[i].indio_dev);
        return ERR_PTR(ret);
 }