* [PATCH v2] pinctrl: fix deadlock in create_pinctrl() when handling -EPROBE_DEFER
@ 2024-06-04 8:58 Hagar Hemdan
2024-06-17 7:55 ` Linus Walleij
0 siblings, 1 reply; 2+ messages in thread
From: Hagar Hemdan @ 2024-06-04 8:58 UTC (permalink / raw)
Cc: Maximilian Heyne, Norbert Manthey, Hagar Hemdan, Linus Walleij,
Patrice Chotard, linux-gpio, linux-kernel
In create_pinctrl(), pinctrl_maps_mutex is acquired before calling
add_setting(). If add_setting() returns -EPROBE_DEFER, create_pinctrl()
calls pinctrl_free(). However, pinctrl_free() attempts to acquire
pinctrl_maps_mutex, which is already held by create_pinctrl(), leading to
a potential deadlock.
This patch resolves the issue by releasing pinctrl_maps_mutex before
calling pinctrl_free(), preventing the deadlock.
This bug was discovered and resolved using Coverity Static Analysis
Security Testing (SAST) by Synopsys, Inc.
Fixes: 42fed7ba44e4 ("pinctrl: move subsystem mutex to pinctrl_dev struct")
Suggested-by: Maximilian Heyne <mheyne@amazon.de>
Signed-off-by: Hagar Hemdan <hagarhem@amazon.com>
---
only compile tested
v2: Updated the commit msg.
---
drivers/pinctrl/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index cffeb869130d..f424a57f0013 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -1106,8 +1106,8 @@ static struct pinctrl *create_pinctrl(struct device *dev,
* an -EPROBE_DEFER later, as that is the worst case.
*/
if (ret == -EPROBE_DEFER) {
- pinctrl_free(p, false);
mutex_unlock(&pinctrl_maps_mutex);
+ pinctrl_free(p, false);
return ERR_PTR(ret);
}
}
--
2.40.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] pinctrl: fix deadlock in create_pinctrl() when handling -EPROBE_DEFER
2024-06-04 8:58 [PATCH v2] pinctrl: fix deadlock in create_pinctrl() when handling -EPROBE_DEFER Hagar Hemdan
@ 2024-06-17 7:55 ` Linus Walleij
0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2024-06-17 7:55 UTC (permalink / raw)
To: Hagar Hemdan
Cc: Maximilian Heyne, Norbert Manthey, Patrice Chotard, linux-gpio,
linux-kernel
On Tue, Jun 4, 2024 at 10:58 AM Hagar Hemdan <hagarhem@amazon.com> wrote:
> In create_pinctrl(), pinctrl_maps_mutex is acquired before calling
> add_setting(). If add_setting() returns -EPROBE_DEFER, create_pinctrl()
> calls pinctrl_free(). However, pinctrl_free() attempts to acquire
> pinctrl_maps_mutex, which is already held by create_pinctrl(), leading to
> a potential deadlock.
>
> This patch resolves the issue by releasing pinctrl_maps_mutex before
> calling pinctrl_free(), preventing the deadlock.
>
> This bug was discovered and resolved using Coverity Static Analysis
> Security Testing (SAST) by Synopsys, Inc.
>
> Fixes: 42fed7ba44e4 ("pinctrl: move subsystem mutex to pinctrl_dev struct")
> Suggested-by: Maximilian Heyne <mheyne@amazon.de>
> Signed-off-by: Hagar Hemdan <hagarhem@amazon.com>
Looks like a real issue so patch applied for fixes.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-06-17 7:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-04 8:58 [PATCH v2] pinctrl: fix deadlock in create_pinctrl() when handling -EPROBE_DEFER Hagar Hemdan
2024-06-17 7:55 ` 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).