All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Pufan Jin" <cyan2254650260@gmail.com>
Cc: linux-gpio@vger.kernel.org
Subject: Re: [PATCH v2 5/5] reset: core: translate GPIO specifier via gpio_device_find_by_fwnode_args()
Date: Sat, 05 Dec 2026 07:33:33 +0000	[thread overview]
Message-ID: <sashiko-outbox-251224@kernel.org> (raw)
In-Reply-To: <20261205064355.137581-6-cyan2254650260@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] reset: __reset_add_reset_gpio_device() breaks multi-bank OF
  deferral
- [Low] reset: reset_gpio_fwnode_xlate() narrows raw args[0] to signed
  int
--

commit d70530f0cba9c1ef9268f09aea4abc3962e72330
Author: Pufan Jin <cyan2254650260@gmail.com>

reset: core: translate GPIO specifier via gpio_device_find_by_fwnode_args()

This commit replaces manual parsing of reset-gpios arguments in
__reset_add_reset_gpio_device() with gpio_device_find_by_fwnode_args(),
removing the #gpio-cells == 2 and flag checks from the reset core.

> diff --git a/drivers/reset/core.c b/drivers/reset/core.c
> index 0bff49d9b5586..7281eb8b527d8 100644
> --- a/drivers/reset/core.c
> +++ b/drivers/reset/core.c

[ ... ]

> @@ -1126,27 +1117,10 @@ static int __reset_add_reset_gpio_device(struct fwnode_handle *fwnode,
[ ... ]
>  	struct gpio_device *gdev __free(gpio_device_put) =
> -			gpio_device_find_by_fwnode(args->fwnode);
> -	if (!gdev)
> -		return -EPROBE_DEFER;
> +		gpio_device_find_by_fwnode_args(args, &offset, &lflags);
> +	if (IS_ERR(gdev))
> +		return PTR_ERR(gdev);

[Severity: Medium]
Can returning PTR_ERR(gdev) here turn a probe deferral into a permanent
-EINVAL failure on multi-bank OF GPIO controllers?

Controllers that share one device_node across multiple gpio_chip instances,
such as spacemit_gpio_probe() in drivers/gpio/gpio-spacemit-k1.c, register
each bank sequentially via devm_gpiochip_add_data().

CPU0 (GPIO controller probe)      CPU1 (consumer probe)
spacemit_gpio_probe()
  spacemit_gpio_add_bank(..., 0)
    devm_gpiochip_add_data()
                                  __reset_add_reset_gpio_device()
                                    gpio_device_find_by_fwnode_args()
                                      of_gpio_device_find_by_fwnode_args()
                                        of_gpiochip_match_and_xlate()
                                          bank 0 of_xlate() -> -EINVAL
                                          ctx->err = -EINVAL
                                    return -EINVAL  <-- probe fails
  spacemit_gpio_add_bank(..., 1)

In of_gpio_device_find_by_fwnode_args(), ctx.err starts as -EPROBE_DEFER,
but of_gpiochip_match_and_xlate() overwrites ctx->err with ret whenever a
registered bank matching the device_node rejects the specifier.  When a
consumer targeting bank 1 probes before bank 1 finishes registering, it
receives -EINVAL instead of -EPROBE_DEFER and fails permanently.

By contrast, of_get_named_gpiod_flags() always returns -EPROBE_DEFER when
of_find_gpio_device_by_xlate() finds no matching bank.  Preserving
-EPROBE_DEFER in of_gpio_device_find_by_fwnode_args() when no registered
bank matches would avoid this probe-ordering regression.

[ ... ]

> @@ -1161,7 +1135,6 @@ static int __reset_add_reset_gpio_device(struct fwnode_handle *fwnode,
>  		}
>  	}
>  
> -	lflags = GPIO_PERSISTENT | (flags & GPIO_ACTIVE_LOW);
>  	parent = gpio_device_to_device(gdev);
>  	properties[prop++] = PROPERTY_ENTRY_STRING("compatible", "reset-gpio");
>  	properties[prop++] = PROPERTY_ENTRY_GPIO("reset-gpios", parent->fwnode, offset, lflags);

[Severity: Low]
Can decoupling the translated offset from raw args[0] cause
reset_gpio_fwnode_xlate() to return an invalid ERR_PTR()?

Previously, __reset_add_reset_gpio_device() required args->nargs == 2 and
passed raw args->args[0] as the GPIO offset, so reset_gpio_probe() bounded
args[0] against gdev->ngpio.  Now 3-cell controllers with custom of_xlate()
callbacks are accepted and only the translated offset is validated, while
reset_gpio_fwnode_xlate() still narrows raw u64 args[0] to a signed int:

drivers/reset/reset-gpio.c:reset_gpio_fwnode_xlate() {
	return reset_spec->nargs ? reset_spec->args[0] : 0;
}

In sunxi_pinctrl_gpio_of_xlate(), PINS_PER_BANK * gpiospec->args[0] wraps
modulo 2^32 for a malformed specifier with bit 31 set (such as
args[0] = 0x80000000), translating to pin 0 so reset_gpio_probe() succeeds.
reset_gpio_fwnode_xlate() then returns -2147483648, and
__fwnode_reset_control_get() converts any rstc_id < 0 directly into
ERR_PTR(rstc_id), producing a non-IS_ERR() invalid pointer that causes
callers to oops.

Since each reset-gpio device has nr_resets = 1 and ignores the id in its
ops, returning 0 unconditionally from reset_gpio_fwnode_xlate() avoids
the truncation.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205064355.137581-1-cyan2254650260@gmail.com?part=5

      reply	other threads:[~2026-12-05  7:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  6:43 [PATCH v2 0/5] gpiolib / reset: resolve GPIO specifiers via gpiolib Pufan Jin
2026-12-05  6:43 ` [PATCH v2 1/5] gpiolib: add gpio_device_find_by_fwnode_args() Pufan Jin
2026-12-05  7:07   ` sashiko-bot
2026-12-05  6:43 ` [PATCH v2 2/5] gpiolib: swnode: prefer matching parent gpio_device Pufan Jin
2026-12-05  6:43 ` [PATCH v2 3/5] gpiolib: shared: match reset-gpio against translated entry offset Pufan Jin
2026-12-05  7:18   ` sashiko-bot
2026-12-05  6:43 ` [PATCH v2 4/5] reset: gpio: derive fwnode_reset_n_cells from platform data Pufan Jin
2026-12-05  6:43 ` [PATCH v2 5/5] reset: core: translate GPIO specifier via gpio_device_find_by_fwnode_args() Pufan Jin
2026-12-05  7:33   ` sashiko-bot [this message]

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=sashiko-outbox-251224@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=cyan2254650260@gmail.com \
    --cc=linux-gpio@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.