Commit 4ddc761c authored by Joe Hattori's avatar Joe Hattori Committed by Wen Zhiwei
Browse files

iio: inkern: call iio_device_put() only on mapped devices

stable inclusion
from stable-v6.6.72
commit 91dd568e3ff92ba70f10c38dcd3e888fb9db7b88
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBQN9L

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=91dd568e3ff92ba70f10c38dcd3e888fb9db7b88



--------------------------------

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: 314be14b ("iio: Rename _st_ functions to loose the bit that meant the staging version.")
Signed-off-by: default avatarJoe 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: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarWen Zhiwei <wenzhiwei@kylinos.cn>
parent c270db95
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -514,7 +514,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: