linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: "Peter Chen (CIX)" <peter.chen@kernel.org>
To: Fedor Pchelkin <pchelkin@ispras.ru>
Cc: Frank Li <Frank.li@nxp.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>,
	Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>,
	Sebastian Reichel <sre@kernel.org>,
	Fabien Lahoudere <fabien.lahoudere@collabora.co.uk>,
	linux-usb@vger.kernel.org, imx@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v2 2/3] usb: chipidea: ci_hdrc_imx: fix call balance of regulator routines
Date: Mon, 17 Mar 2025 09:54:37 +0800	[thread overview]
Message-ID: <20250317015437.GB218167@nchen-desktop> (raw)
In-Reply-To: <20250316102658.490340-3-pchelkin@ispras.ru>

On 25-03-16 13:26:55, Fedor Pchelkin wrote:
> 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: 4d6141288c33 ("usb: chipidea: imx: pinctrl for HSIC is optional")
> Cc: stable@vger.kernel.org
> Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>

Acked-by: Peter Chen <peter.chen@kernel.org>


> ---
> v2: simplify the patch taking advantage of devm-helper (Frank Li)
> 
> It looks like devm_regulator_get_enable_optional() exists for this very
> use case utilized in the driver but it's not present in old supported
> stable kernels and I may say those dependency-patches wouldn't apply there
> cleanly. So fix the problem first, further code simplification is a
> subject to cleanup patch.
> 
>  drivers/usb/chipidea/ci_hdrc_imx.c | 25 +++++++++++++++++--------
>  1 file changed, 17 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c
> index 619779eef333..d942b3c72640 100644
> --- a/drivers/usb/chipidea/ci_hdrc_imx.c
> +++ b/drivers/usb/chipidea/ci_hdrc_imx.c
> @@ -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);
> -- 
> 2.48.1
> 

-- 

Best regards,
Peter


  reply	other threads:[~2025-03-17  1:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-16 10:26 [PATCH v2 0/3] usb: chipidea: ci_hdrc_imx: fix some issues in probe/remove Fedor Pchelkin
2025-03-16 10:26 ` [PATCH v2 1/3] usb: chipidea: ci_hdrc_imx: fix usbmisc handling Fedor Pchelkin
2025-03-17  1:53   ` Peter Chen (CIX)
2025-03-16 10:26 ` [PATCH v2 2/3] usb: chipidea: ci_hdrc_imx: fix call balance of regulator routines Fedor Pchelkin
2025-03-17  1:54   ` Peter Chen (CIX) [this message]
2025-03-16 10:26 ` [PATCH v2 3/3] usb: chipidea: ci_hdrc_imx: implement usb_phy_init() error handling Fedor Pchelkin
2025-03-17  1:56   ` Peter Chen (CIX)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250317015437.GB218167@nchen-desktop \
    --to=peter.chen@kernel.org \
    --cc=Frank.li@nxp.com \
    --cc=fabien.lahoudere@collabora.co.uk \
    --cc=festevam@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=imx@lists.linux.dev \
    --cc=joe@pf.is.s.u-tokyo.ac.jp \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=pchelkin@ispras.ru \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=sre@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).