pinctrl: fix deadlock in create_pinctrl() when handling -EPROBE_DEFER
Subsystems (2)
PATCH v2 1/1 pinctrl: fix deadlock in create_pinctrl() when handling -EPROBE_DEFER
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.
---
only compile tested
v2: Updated the commit msg.
--- drivers/pinctrl/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/core.c +1 -1
@@ -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); } }
Signature · 1 line
2.40.1
Quoted 9 lines · Hagar Hemdan
In
create_pinctrl(),pinctrl_maps_mutexis acquired before callingadd_setting(). Ifadd_setting()returns -EPROBE_DEFER,create_pinctrl()callspinctrl_free(). However,pinctrl_free()attempts to acquirepinctrl_maps_mutex, which is already held bycreate_pinctrl(), leading to a potential deadlock.This patch resolves the issue by releasing
pinctrl_maps_mutexbefore callingpinctrl_free(), preventing the deadlock.
Quoted 6 lines
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 <[email protected]>Signed-off-by Hagar Hemdan <[email protected]>
Looks like a real issue so patch applied for fixes.
Yours,
Linus Walleij