pinctrl: avoid unsafe code pattern in find_pinctrl()
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Wed, 20 Sep 2023 18:09:10 +0000 (11:09 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 19 Oct 2023 21:08:57 +0000 (23:08 +0200)
commit97306abdeaca8b75cae44e0eca928c78d72dadbd
treede0b08dcbe1f815350649f26be11e720fef3cbc9
parentd67b5a2b97b6e8959117ff71fc2daa30e66c8290
pinctrl: avoid unsafe code pattern in find_pinctrl()

commit c153a4edff6ab01370fcac8e46f9c89cca1060c2 upstream.

The code in find_pinctrl() takes a mutex and traverses a list of pinctrl
structures. Later the caller bumps up reference count on the found
structure. Such pattern is not safe as pinctrl that was found may get
deleted before the caller gets around to increasing the reference count.

Fix this by taking the reference count in find_pinctrl(), while it still
holds the mutex.

Cc: stable@vger.kernel.org
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Link: https://lore.kernel.org/r/ZQs1RgTKg6VJqmPs@google.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/pinctrl/core.c