From: sashiko-bot@kernel.org
To: "Mehmet Fide" <mehmet.fide@gmail.com>
Cc: Frank.Li@kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH v4 2/3] gpiolib: add get_config() and gpiochip_generic_get_config()
Date: Thu, 03 Sep 2026 07:45:08 +0000 [thread overview]
Message-ID: <20260903074509.F36471F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260903073143.2068494-3-mehmet.fide@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] gpiochip_generic_get_config() returns an unpacked argument instead of the documented packed configuration format.
--
commit 76e13bb42cd8827a4ba44cd0214563286c510f1f
Author: Mehmet Fide <mehmet.fide@screeningeagle.com>
gpiolib: add get_config() and gpiochip_generic_get_config()
A chip with a pin control backend sets a line's configuration through
set_config() and gpiochip_generic_config(), but has no way to read one
back. gpio-mmio needs that to learn the direction of a line whose
direction lives in the pin controller.
> Add the optional get_config() callback, taking the packed parameter to
> query and returning the packed answer the way pinctrl_gpio_get_config()
> does, and gpiochip_generic_get_config() as the pin control backed
[Severity: Medium]
Does pinctrl_gpio_get_config() actually return a packed answer?
Looking at drivers/pinctrl/core.c, pinctrl_gpio_get_config() intentionally
strips the parameter and returns only the unpacked argument:
int pinctrl_gpio_get_config(...) {
...
*config = pinconf_to_config_argument(*config);
return 0;
}
[ ... ]
> diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
> index 17511434ed077..5c81cce691738 100644
> --- a/include/linux/gpio/driver.h
> +++ b/include/linux/gpio/driver.h
> @@ -359,6 +359,10 @@ struct gpio_irq_chip {
> * @set_config: optional hook for all kinds of settings. Uses the same
> * packed config format as generic pinconf. Must return 0 on success and
> * a negative error number on failure.
> + * @get_config: optional hook to read back a setting. Uses the same packed
> + * config format as generic pinconf: the parameter to query goes in, the
> + * packed parameter and argument come out. Must return 0 on success and a
> + * negative error number on failure.
[Severity: Medium]
Because pinctrl_gpio_get_config() unpacks the argument, does this documented
API contract contradict the actual implementation?
If a driver follows this documentation and parses the returned value using
pinconf_to_config_argument(), it will shift the already-unpacked value right
by 8 bits, yielding 0.
[ ... ]
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index ef8ccaf17c9ce..44328aed16465 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -2440,6 +2440,29 @@ int gpiochip_generic_config(struct gpio_chip *gc, unsigned int offset,
> }
> EXPORT_SYMBOL_GPL(gpiochip_generic_config);
>
> +/**
> + * gpiochip_generic_get_config() - read back the configuration of a pin
> + * @gc: the gpiochip owning the GPIO
> + * @offset: the offset of the GPIO to query
> + * @config: the packed parameter to query, replaced by the packed answer
> + *
> + * Returns:
> + * 0 on success, or negative errno on failure.
> + */
> +int gpiochip_generic_get_config(struct gpio_chip *gc, unsigned int offset,
> + unsigned long *config)
> +{
> +#ifdef CONFIG_PINCTRL
> + if (list_empty(&gc->gpiodev->pin_ranges))
> + return -ENOTSUPP;
> +
> + return pinctrl_gpio_get_config(gc, offset, config);
[Severity: Medium]
Will returning this unpacked value directly cause logic errors for drivers
expecting a packed configuration?
Returning the unpacked output of pinctrl_gpio_get_config() here finalizes
the API contract violation.
Any callers, such as the gpio-mmio driver in patch 3/3, that rely on the
actual returned unpacked value will bypass the documented API contract. If
the value was truly packed as documented, config would always evaluate to
true since the parameter is non-zero.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260903073143.2068494-1-mehmet.fide@gmail.com?part=2
next prev parent reply other threads:[~2026-09-03 7:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 7:31 [PATCH v4 0/3] gpio: mmio: report the line direction on chips without direction registers Mehmet Fide
2026-09-03 7:31 ` [PATCH v4 1/3] pinctrl: imx: answer OUTPUT_ENABLE/INPUT_ENABLE queries from the pad register Mehmet Fide
2026-09-03 7:43 ` sashiko-bot
2026-09-03 7:59 ` Mehmet Fide
2026-09-03 7:31 ` [PATCH v4 2/3] gpiolib: add get_config() and gpiochip_generic_get_config() Mehmet Fide
2026-09-03 7:45 ` sashiko-bot [this message]
2026-09-03 7:59 ` Mehmet Fide
2026-09-03 7:31 ` [PATCH v4 3/3] gpio: mmio: track the direction of chips without direction registers Mehmet Fide
2026-09-03 7:50 ` sashiko-bot
2026-09-03 7:59 ` Mehmet Fide
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=20260903074509.F36471F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=imx@lists.linux.dev \
--cc=mehmet.fide@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox