From: Joe Hattori Date: Wed, 4 Dec 2024 11:13:42 +0000 (+0900) Subject: iio: inkern: call iio_device_put() only on mapped devices X-Git-Tag: v5.15.177~68 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d83ccca9e17eb738cb38292234590a510e8578df;p=thirdparty%2Fkernel%2Fstable.git iio: inkern: call iio_device_put() only on mapped devices commit 64f43895b4457532a3cc524ab250b7a30739a1b1 upstream. 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 Link: https://patch.msgid.link/20241204111342.1246706-1-joe@pf.is.s.u-tokyo.ac.jp Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index 16f25a2bede79..5eabb54c1fc72 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -469,7 +469,7 @@ struct iio_channel *iio_channel_get_all(struct device *dev) return chans; error_free_chans: - for (i = 0; i < nummaps; i++) + for (i = 0; i < mapind; i++) iio_device_put(chans[i].indio_dev); kfree(chans); error_ret: