[PATCH v2 1/5] pinctrl: qcom: lpass-lpi: make mutex cleanup devm-managed

From: Prasad Kumpatla

Date: Mon Jul 13 2026 - 14:46:38 EST


The driver registers its pin controller using devm_pinctrl_register(),
which keeps the pinctrl device alive until devres teardown, after
.remove() returns. Explicitly destroying pctrl->lock in .remove() and
the probe error path leaves the mutex destroyed while the pinctrl
device is still accessible, risking a panic on concurrent debugfs
access during unbind.

Switch to devm_mutex_init() so the mutex lifetime is automatically
aligned with the devm-managed pinctrl device, and remove now
redundant mutex_destroy() calls and err_pinctrl label.

Signed-off-by: Prasad Kumpatla <prasad.kumpatla@xxxxxxxxxxxxxxxx>
---
drivers/pinctrl/qcom/pinctrl-lpass-lpi.c | 22 +++++++---------------
1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/drivers/pinctrl/qcom/pinctrl-lpass-lpi.c b/drivers/pinctrl/qcom/pinctrl-lpass-lpi.c
index 5fd4a4eba..b3e365470 100644
--- a/drivers/pinctrl/qcom/pinctrl-lpass-lpi.c
+++ b/drivers/pinctrl/qcom/pinctrl-lpass-lpi.c
@@ -559,31 +559,25 @@ int lpi_pinctrl_probe(struct platform_device *pdev)
pctrl->chip.label = dev_name(dev);
pctrl->chip.can_sleep = true;

- mutex_init(&pctrl->lock);
+ ret = devm_mutex_init(&pdev->dev, &pctrl->lock);
+ if (ret)
+ return ret;

pctrl->ctrl = devm_pinctrl_register(dev, &pctrl->desc, pctrl);
- if (IS_ERR(pctrl->ctrl)) {
- ret = PTR_ERR(pctrl->ctrl);
- dev_err(dev, "failed to add pin controller\n");
- goto err_pinctrl;
- }
+ if (IS_ERR(pctrl->ctrl))
+ return PTR_ERR(pctrl->ctrl);

ret = lpi_build_pin_desc_groups(pctrl);
if (ret)
- goto err_pinctrl;
+ return ret;

ret = devm_gpiochip_add_data(dev, &pctrl->chip, pctrl);
if (ret) {
dev_err(pctrl->dev, "can't add gpio chip\n");
- goto err_pinctrl;
+ return ret;
}

return 0;
-
-err_pinctrl:
- mutex_destroy(&pctrl->lock);
-
- return ret;
}
EXPORT_SYMBOL_GPL(lpi_pinctrl_probe);

@@ -592,8 +586,6 @@ void lpi_pinctrl_remove(struct platform_device *pdev)
struct lpi_pinctrl *pctrl = platform_get_drvdata(pdev);
int i;

- mutex_destroy(&pctrl->lock);
-
for (i = 0; i < pctrl->data->npins; i++)
pinctrl_generic_remove_group(pctrl->ctrl, i);
}
--
2.34.1