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

From: Konrad Dybcio

Date: Thu Jul 16 2026 - 05:49:33 EST


On 7/13/26 8:45 PM, Prasad Kumpatla wrote:
> 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);

You can retain the error message with 'return dev_err_probe'

Konrad