]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
gpiolib: fix reference leaks when removing GPIO chips still in use
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Fri, 11 Aug 2023 19:30:34 +0000 (21:30 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 13 Sep 2023 07:47:55 +0000 (09:47 +0200)
commit87d743fcfed106b9c9083c8e534b6f08d1b37836
tree1b2b4639028a32f28aa4a1d97b27b0cdd176829f
parent2e3f9bfe44f2aa3f1d6c8afbd15c08525d982d32
gpiolib: fix reference leaks when removing GPIO chips still in use

[ Upstream commit 3386fb86ecdef0d39ee3306aea8ec290e61b934f ]

After we remove a GPIO chip that still has some requested descriptors,
gpiod_free_commit() will fail and we will never put the references to the
GPIO device and the owning module in gpiod_free().

Rework this function to:
- not warn on desc == NULL as this is a use-case on which most free
  functions silently return
- put the references to desc->gdev and desc->gdev->owner unconditionally
  so that the release callback actually gets called when the remaining
  references are dropped by external GPIO users

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpio/gpiolib.c