* [PATCH 1/2 v2] gpio: gpio-grgpio: fix possible sleep-in-atomic-context bugs in grgpio_remove()
@ 2019-12-19 13:14 Jia-Ju Bai
2020-01-07 8:59 ` Linus Walleij
0 siblings, 1 reply; 2+ messages in thread
From: Jia-Ju Bai @ 2019-12-19 13:14 UTC (permalink / raw)
To: linus.walleij, bgolaszewski; +Cc: linux-gpio, linux-kernel, Jia-Ju Bai
drivers/gpio/gpiolib-sysfs.c, 796:
mutex_lock in gpiochip_sysfs_unregister
drivers/gpio/gpiolib.c, 1455:
gpiochip_sysfs_unregister in gpiochip_remove
drivers/gpio/gpio-grgpio.c, 460:
gpiochip_remove in grgpio_remove
drivers/gpio/gpio-grgpio.c, 449:
_raw_spin_lock_irqsave in grgpio_remove
kernel/irq/irqdomain.c, 243:
mutex_lock in irq_domain_remove
drivers/gpio/gpio-grgpio.c, 463:
irq_domain_remove in grgpio_remove
drivers/gpio/gpio-grgpio.c, 449:
_raw_spin_lock_irqsave in grgpio_remove
mutex_lock() can sleep at runtime.
To fix these bugs, the lock is dropped in grgpio_remove(), because there
is no need for locking in remove() callbacks.
These bugs are found by a static analysis tool STCheck written by
myself.
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
v2:
* Drop the lock instead of moving the calls to lock functions.
Thank Bartosz for good advice.
---
drivers/gpio/gpio-grgpio.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/drivers/gpio/gpio-grgpio.c b/drivers/gpio/gpio-grgpio.c
index 08234e64993a..a49f0711ca94 100644
--- a/drivers/gpio/gpio-grgpio.c
+++ b/drivers/gpio/gpio-grgpio.c
@@ -437,8 +437,6 @@ static int grgpio_remove(struct platform_device *ofdev)
int i;
int ret = 0;
- spin_lock_irqsave(&priv->gc.bgpio_lock, flags);
-
if (priv->domain) {
for (i = 0; i < GRGPIO_MAX_NGPIO; i++) {
if (priv->uirqs[i].refcnt != 0) {
@@ -454,8 +452,6 @@ static int grgpio_remove(struct platform_device *ofdev)
irq_domain_remove(priv->domain);
out:
- spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags);
-
return ret;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 1/2 v2] gpio: gpio-grgpio: fix possible sleep-in-atomic-context bugs in grgpio_remove()
2019-12-19 13:14 [PATCH 1/2 v2] gpio: gpio-grgpio: fix possible sleep-in-atomic-context bugs in grgpio_remove() Jia-Ju Bai
@ 2020-01-07 8:59 ` Linus Walleij
0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2020-01-07 8:59 UTC (permalink / raw)
To: Jia-Ju Bai; +Cc: Bartosz Golaszewski, open list:GPIO SUBSYSTEM, linux-kernel
On Thu, Dec 19, 2019 at 2:15 PM Jia-Ju Bai <baijiaju1990@gmail.com> wrote:
> drivers/gpio/gpiolib-sysfs.c, 796:
> mutex_lock in gpiochip_sysfs_unregister
> drivers/gpio/gpiolib.c, 1455:
> gpiochip_sysfs_unregister in gpiochip_remove
> drivers/gpio/gpio-grgpio.c, 460:
> gpiochip_remove in grgpio_remove
> drivers/gpio/gpio-grgpio.c, 449:
> _raw_spin_lock_irqsave in grgpio_remove
>
> kernel/irq/irqdomain.c, 243:
> mutex_lock in irq_domain_remove
> drivers/gpio/gpio-grgpio.c, 463:
> irq_domain_remove in grgpio_remove
> drivers/gpio/gpio-grgpio.c, 449:
> _raw_spin_lock_irqsave in grgpio_remove
>
> mutex_lock() can sleep at runtime.
>
> To fix these bugs, the lock is dropped in grgpio_remove(), because there
> is no need for locking in remove() callbacks.
>
> These bugs are found by a static analysis tool STCheck written by
> myself.
>
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
> v2:
> * Drop the lock instead of moving the calls to lock functions.
> Thank Bartosz for good advice.
Looks good to me, patch applied!
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-01-07 8:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-19 13:14 [PATCH 1/2 v2] gpio: gpio-grgpio: fix possible sleep-in-atomic-context bugs in grgpio_remove() Jia-Ju Bai
2020-01-07 8:59 ` Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).