Commit 8cab0e9a authored by Fedor Pchelkin's avatar Fedor Pchelkin Committed by Greg Kroah-Hartman
Browse files

usb: chipidea: ci_hdrc_imx: fix call balance of regulator routines



Upon encountering errors during the HSIC pinctrl handling section the
regulator should be disabled.

Use devm_add_action_or_reset() to let the regulator-disabling routine be
handled by device resource management stack.

Found by Linux Verification Center (linuxtesting.org).

Fixes: 4d614128 ("usb: chipidea: imx: pinctrl for HSIC is optional")
Cc: stable <stable@kernel.org>
Signed-off-by: default avatarFedor Pchelkin <pchelkin@ispras.ru>
Acked-by: default avatarPeter Chen <peter.chen@kernel.org>
Link: https://lore.kernel.org/r/20250316102658.490340-3-pchelkin@ispras.ru


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 4e28f79e
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -336,6 +336,13 @@ static int ci_hdrc_imx_notify_event(struct ci_hdrc *ci, unsigned int event)
	return ret;
}

static void ci_hdrc_imx_disable_regulator(void *arg)
{
	struct ci_hdrc_imx_data *data = arg;

	regulator_disable(data->hsic_pad_regulator);
}

static int ci_hdrc_imx_probe(struct platform_device *pdev)
{
	struct ci_hdrc_imx_data *data;
@@ -394,6 +401,13 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
					"Failed to enable HSIC pad regulator\n");
				goto err_put;
			}
			ret = devm_add_action_or_reset(dev,
					ci_hdrc_imx_disable_regulator, data);
			if (ret) {
				dev_err(dev,
					"Failed to add regulator devm action\n");
				goto err_put;
			}
		}
	}

@@ -432,11 +446,11 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)

	ret = imx_get_clks(dev);
	if (ret)
		goto disable_hsic_regulator;
		goto qos_remove_request;

	ret = imx_prepare_enable_clks(dev);
	if (ret)
		goto disable_hsic_regulator;
		goto qos_remove_request;

	ret = clk_prepare_enable(data->clk_wakeup);
	if (ret)
@@ -526,10 +540,7 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
	clk_disable_unprepare(data->clk_wakeup);
err_wakeup_clk:
	imx_disable_unprepare_clks(dev);
disable_hsic_regulator:
	if (data->hsic_pad_regulator)
		/* don't overwrite original ret (cf. EPROBE_DEFER) */
		regulator_disable(data->hsic_pad_regulator);
qos_remove_request:
	if (pdata.flags & CI_HDRC_PMQOS)
		cpu_latency_qos_remove_request(&data->pm_qos_req);
	data->ci_pdev = NULL;
@@ -557,8 +568,6 @@ static void ci_hdrc_imx_remove(struct platform_device *pdev)
		clk_disable_unprepare(data->clk_wakeup);
		if (data->plat_data->flags & CI_HDRC_PMQOS)
			cpu_latency_qos_remove_request(&data->pm_qos_req);
		if (data->hsic_pad_regulator)
			regulator_disable(data->hsic_pad_regulator);
	}
	if (data->usbmisc_data)
		put_device(data->usbmisc_data->dev);