Devicetree
 help / color / mirror / Atom feed
From: Philipp Zabel <p.zabel@pengutronix.de>
To: "Geert Uytterhoeven" <geert+renesas@glider.be>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Stephen Boyd" <sboyd@kernel.org>,
	"Brian Masney" <bmasney+clk@redhat.com>,
	"Jerome Brunet" <jbrunet+clk@baylibre.com>,
	"Sudeep Holla" <sudeep.holla@kernel.org>,
	"Cristian Marussi" <cristian.marussi@arm.com>,
	"Saravana Kannan" <saravanak@kernel.org>,
	"Ulf Hansson" <ulfh@kernel.org>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	"Marek Vasut" <marek.vasut+renesas@mailbox.org>,
	"Bartosz Golaszewski" <bartosz.golaszewski@oss.qualcomm.com>,
	"Konrad Dybcio" <konrad.dybcio@oss.qualcomm.com>,
	"Kevin Hilman" <khilman@baylibre.com>,
	"Vinod Koul" <vkoul@kernel.org>,
	"Wolfram Sang" <wsa+renesas@sang-engineering.com>,
	"Kuninori Morimoto" <kuninori.morimoto.gx@renesas.com>,
	"Clément Le Goffic" <clegoffic@baylibre.com>
Cc: devicetree@vger.kernel.org, arm-scmi@vger.kernel.org,
	 linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org,
	 linux-pm@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 06/12] reset: Extract __reset_control_get_from_provider()
Date: Thu, 03 Sep 2026 10:55:01 +0200	[thread overview]
Message-ID: <f3e365f5440cbd005df45410a89032dcf685258e.camel@pengutronix.de> (raw)
In-Reply-To: <2824c50f77aa287a3555533e4b9760109aae1741.1788338320.git.geert+renesas@glider.be>

On Mi, 2026-09-02 at 13:29 +0200, Geert Uytterhoeven wrote:
> Extract the code to create a reset_control structure from a given
> provider into its own function, so it can be reused later.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
> v3:
>   - New.
> ---
>  drivers/reset/core.c | 92 ++++++++++++++++++++++++--------------------
>  1 file changed, 50 insertions(+), 42 deletions(-)
> 
> diff --git a/drivers/reset/core.c b/drivers/reset/core.c
> index 38e189d04d09b270..8af7cd2e8a5029df 100644
> --- a/drivers/reset/core.c
> +++ b/drivers/reset/core.c
> @@ -1135,6 +1135,54 @@ __reset_find_rcdev(const struct fwnode_reference_args *args, bool gpio_fallback)
>  	return NULL;
>  }
>  
> +static struct reset_control *
> +__reset_control_get_from_provider(const struct fwnode_reference_args *args,
> +				  struct fwnode_handle *consumer, int index,
> +				  bool gpio_fallback,
> +				  enum reset_control_flags flags)
> +{
> +	struct reset_control *rstc = ERR_PTR(-EINVAL);
> +	struct reset_controller_dev *rcdev;
> +	int rstc_id = -EINVAL;
> +
> +	guard(mutex)(&reset_list_mutex);
> +
> +	rcdev = __reset_find_rcdev(args, gpio_fallback);
> +	if (!rcdev)
> +		return ERR_PTR(-EPROBE_DEFER);
> +
> +	if (WARN_ON(args->nargs != rcdev->fwnode_reset_n_cells))
> +		return ERR_PTR(-EINVAL);
> +
> +	if (rcdev->of_xlate && is_of_node(consumer)) {
> +		struct device_node *np = to_of_node(consumer);
> +		struct of_phandle_args of_args;
> +		int ret;
> +
> +		ret = of_parse_phandle_with_args(np,
> +					 gpio_fallback ? "reset-gpios" : "resets",
> +					 gpio_fallback ? "#gpio-cells" : "#reset-cells",
> +					 gpio_fallback ? 0 : index,
> +					 &of_args);
> +		if (ret)
> +			return ERR_PTR(ret);
> +
> +		rstc_id = rcdev->of_xlate(rcdev, &of_args);
> +		of_node_put(of_args.np);
> +	} else if (rcdev->fwnode_xlate) {
> +		rstc_id = rcdev->fwnode_xlate(rcdev, args);
> +	}
> +	if (rstc_id < 0)
> +		return ERR_PTR(rstc_id);
> +
> +	flags &= ~RESET_CONTROL_FLAGS_BIT_OPTIONAL;

This should stay in __fwnode_reset_control_get().

> +
> +	scoped_guard(mutex, &rcdev->lock)
> +		rstc = __reset_control_get_internal(rcdev, rstc_id, flags);
> +
> +	return rstc;

Just return __reset_control_get_internal(...) directly, the rstc local
variable is not needed.

> +}
> +
>  struct reset_control *
>  __fwnode_reset_control_get(struct fwnode_handle *fwnode, const char *id, int index,
>  			   enum reset_control_flags flags)
> @@ -1142,10 +1190,7 @@ __fwnode_reset_control_get(struct fwnode_handle *fwnode, const char *id, int ind
>  	bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
>  	bool gpio_fallback = false;
>  	struct reset_control *rstc = ERR_PTR(-EINVAL);
> -	struct reset_controller_dev *rcdev;
>  	struct fwnode_reference_args args;
> -	struct of_phandle_args of_args;
> -	int rstc_id = -EINVAL;
>  	int ret;
>  
>  	if (!fwnode)
> @@ -1185,46 +1230,9 @@ __fwnode_reset_control_get(struct fwnode_handle *fwnode, const char *id, int ind
>  		}
>  	}
>  
> -	guard(mutex)(&reset_list_mutex);
> -
> -	rcdev = __reset_find_rcdev(&args, gpio_fallback);
> -	if (!rcdev) {
> -		rstc = ERR_PTR(-EPROBE_DEFER);
> -		goto out_put;
> -	}
> -
> -	if (WARN_ON(args.nargs != rcdev->fwnode_reset_n_cells)) {
> -		rstc = ERR_PTR(-EINVAL);
> -		goto out_put;
> -	}
> -
> -	if (rcdev->of_xlate && is_of_node(fwnode)) {
> -		ret = of_parse_phandle_with_args(to_of_node(fwnode),
> -					 gpio_fallback ? "reset-gpios" : "resets",
> -					 gpio_fallback ? "#gpio-cells" : "#reset-cells",
> -					 gpio_fallback ? 0 : index,

Hmm, I think this gpio_fallback disambiguation is not needed. In the
gpio_fallback case (lookup via "reset-gpios") we should always get a
reset_gpio rcdev with fwnode_xlate, not of_xlate.
Not an issue for this refactor, though.

> -					 &of_args);
> -		if (ret) {
> -			rstc = ERR_PTR(ret);
> -			goto out_put;
> -		}
> -
> -		rstc_id = rcdev->of_xlate(rcdev, &of_args);
> -		of_node_put(of_args.np);
> -	} else if (rcdev->fwnode_xlate) {
> -		rstc_id = rcdev->fwnode_xlate(rcdev, &args);
> -	}
> -	if (rstc_id < 0) {
> -		rstc = ERR_PTR(rstc_id);
> -		goto out_put;
> -	}
> -
> -	flags &= ~RESET_CONTROL_FLAGS_BIT_OPTIONAL;

Keep this here.

> -
> -	scoped_guard(mutex, &rcdev->lock)
> -		rstc = __reset_control_get_internal(rcdev, rstc_id, flags);
> +	rstc = __reset_control_get_from_provider(&args, fwnode, index,
> +						 gpio_fallback, flags);
>  
> -out_put:
>  	fwnode_handle_put(args.fwnode);
>  
>  	return rstc;

With that,

Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>

regards
Philipp

  reply	other threads:[~2026-09-03  8:55 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02 11:29 [PATCH v3 00/12] R-Car X5H Ironhide CPG/MDLC SCMI remapping support Geert Uytterhoeven
2026-09-02 11:29 ` [PATCH v3 01/12] dt-bindings: clock: renesas,r8a78000-cpg: Add renesas,scmi-firmware property Geert Uytterhoeven
2026-09-04 14:03   ` Sudeep Holla
2026-09-04 14:42     ` Geert Uytterhoeven
2026-09-02 11:29 ` [PATCH v3 02/12] dt-bindings: power: renesas,r8a78000-mdlc: Add firmware property Geert Uytterhoeven
2026-09-04 14:03   ` Sudeep Holla
2026-09-02 11:29 ` [PATCH v3 03/12] firmware: arm_scmi: Add scmi_get_base_info() Geert Uytterhoeven
2026-09-02 11:29 ` [PATCH v3 04/12] of: property: fw_devlink: Add support for renesas,scmi-firmware Geert Uytterhoeven
2026-09-02 11:29 ` [PATCH v3 05/12] pmdomain: Make genpd_get_from_provider() public Geert Uytterhoeven
2026-09-02 11:40   ` sashiko-bot
2026-09-02 11:29 ` [PATCH v3 06/12] reset: Extract __reset_control_get_from_provider() Geert Uytterhoeven
2026-09-03  8:55   ` Philipp Zabel [this message]
2026-09-02 11:29 ` [PATCH v3 07/12] reset: Add reset_control_get_from_provider_exclusive() Geert Uytterhoeven
2026-09-02 11:38   ` sashiko-bot
2026-09-02 11:44   ` Geert Uytterhoeven
2026-09-03 10:03   ` Philipp Zabel
2026-09-02 11:29 ` [PATCH v3 08/12] clk: renesas: r8a78000: Add clk_hw to clk_map Geert Uytterhoeven
2026-09-02 11:29 ` [PATCH v3 09/12] clk: renesas: r8a78000: Add SCMI remapping support Geert Uytterhoeven
2026-09-02 11:41   ` sashiko-bot
2026-09-02 11:29 ` [PATCH v3 10/12] pmdomain: " Geert Uytterhoeven
2026-09-02 11:47   ` sashiko-bot
2026-09-02 11:29 ` [PATCH v3 11/12] arm64: dts: renesas: ironhide: Enable SCMI devpd, sys, clock, and reset Geert Uytterhoeven
2026-09-02 11:29 ` [PATCH v3 12/12] arm64: dts: renesas: ironhide: Add CPG/MDLC renesas,scmi-firmware properties Geert Uytterhoeven
2026-09-02 11:40   ` sashiko-bot

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=f3e365f5440cbd005df45410a89032dcf685258e.camel@pengutronix.de \
    --to=p.zabel@pengutronix.de \
    --cc=arm-scmi@vger.kernel.org \
    --cc=bartosz.golaszewski@oss.qualcomm.com \
    --cc=bmasney+clk@redhat.com \
    --cc=clegoffic@baylibre.com \
    --cc=conor+dt@kernel.org \
    --cc=cristian.marussi@arm.com \
    --cc=devicetree@vger.kernel.org \
    --cc=geert+renesas@glider.be \
    --cc=jbrunet+clk@baylibre.com \
    --cc=khilman@baylibre.com \
    --cc=konrad.dybcio@oss.qualcomm.com \
    --cc=krzk+dt@kernel.org \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=rafael@kernel.org \
    --cc=robh@kernel.org \
    --cc=saravanak@kernel.org \
    --cc=sboyd@kernel.org \
    --cc=sudeep.holla@kernel.org \
    --cc=ulfh@kernel.org \
    --cc=vkoul@kernel.org \
    --cc=wsa+renesas@sang-engineering.com \
    /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