* [PATCH] gpio: swnode: restore the swnode-name-against-chip-label matching
@ 2026-02-10 9:48 Bartosz Golaszewski
2026-02-10 10:06 ` Andy Shevchenko
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2026-02-10 9:48 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Andy Shevchenko,
Greg Kroah-Hartman, Dmitry Torokhov, Arnd Bergmann, Hans de Goede,
Ilpo Järvinen
Cc: linux-gpio, linux-kernel, platform-driver-x86,
Bartosz Golaszewski, stable
Using the remote firmware node for software node lookup is the right
thing to do. The GPIO controller we want to resolve should have the
software node we scooped out of the reference attached to it. However,
there are existing users who abuse the software node API by creating
dummy swnodes whose name is set to the expected label string of the GPIO
controller whose pins they want to control and use them in their local
swnode references as GPIO properties.
This used to work when we compared the software node's name to the
chip's label. When we switched to using a real fwnode lookup, these
users broke down because the firmware nodes in question were never
attached to the controllers they were looking for.
Restore the label matching as a fallback to fix the broken users but add
a big FIXME urging for a better solution.
Link: https://lore.kernel.org/all/aYmV5Axyfo76D19T@smile.fi.intel.com/
Cc: stable@vger.kernel.org # v6.18, v6.19
Fixes: 216c12047571 ("gpio: swnode: allow referencing GPIO chips by firmware nodes")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
drivers/gpio/gpiolib-swnode.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/drivers/gpio/gpiolib-swnode.c b/drivers/gpio/gpiolib-swnode.c
index 21478b45c127d..c88313b0026b9 100644
--- a/drivers/gpio/gpiolib-swnode.c
+++ b/drivers/gpio/gpiolib-swnode.c
@@ -42,6 +42,25 @@ static struct gpio_device *swnode_get_gpio_device(struct fwnode_handle *fwnode)
fwnode_lookup:
gdev = gpio_device_find_by_fwnode(fwnode);
+ if (!gdev)
+ /*
+ * FIXME: We shouldn't need to compare the GPIO controller's
+ * label against the software node that is supposedly attached
+ * to it. However there are currently GPIO users that - knowing
+ * the expected label of the GPIO chip whose pins they want to
+ * control - set up dummy software nodes named after those GPIO
+ * controllers, which aren't actually attached to them. In this
+ * case gpio_device_find_by_fwnode() will fail as no device on
+ * the GPIO bus is actually associated with the fwnode we're
+ * looking for.
+ *
+ * As a fallback: continue checking the label if we have no
+ * match. However, the situation described above is an abuse
+ * of the software node API and should be phased out and the
+ * following line - eventually removed.
+ */
+ gdev = gpio_device_find_by_label(gdev_node->name);
+
return gdev ?: ERR_PTR(-EPROBE_DEFER);
}
--
2.47.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] gpio: swnode: restore the swnode-name-against-chip-label matching
2026-02-10 9:48 [PATCH] gpio: swnode: restore the swnode-name-against-chip-label matching Bartosz Golaszewski
@ 2026-02-10 10:06 ` Andy Shevchenko
2026-02-10 10:41 ` Hans de Goede
2026-02-10 19:10 ` Dan Carpenter
2 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2026-02-10 10:06 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Linus Walleij, Bartosz Golaszewski, Greg Kroah-Hartman,
Dmitry Torokhov, Arnd Bergmann, Hans de Goede, Ilpo Järvinen,
linux-gpio, linux-kernel, platform-driver-x86, stable
On Tue, Feb 10, 2026 at 10:48:06AM +0100, Bartosz Golaszewski wrote:
> Using the remote firmware node for software node lookup is the right
> thing to do. The GPIO controller we want to resolve should have the
> software node we scooped out of the reference attached to it. However,
> there are existing users who abuse the software node API by creating
> dummy swnodes whose name is set to the expected label string of the GPIO
> controller whose pins they want to control and use them in their local
> swnode references as GPIO properties.
>
> This used to work when we compared the software node's name to the
> chip's label. When we switched to using a real fwnode lookup, these
> users broke down because the firmware nodes in question were never
> attached to the controllers they were looking for.
>
> Restore the label matching as a fallback to fix the broken users but add
> a big FIXME urging for a better solution.
>
> Link: https://lore.kernel.org/all/aYmV5Axyfo76D19T@smile.fi.intel.com/
Should be
Link: https://lore.kernel.org/all/aYkdKfP5fg6iywgr@jekhomev/
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gpio: swnode: restore the swnode-name-against-chip-label matching
2026-02-10 9:48 [PATCH] gpio: swnode: restore the swnode-name-against-chip-label matching Bartosz Golaszewski
2026-02-10 10:06 ` Andy Shevchenko
@ 2026-02-10 10:41 ` Hans de Goede
2026-02-10 19:10 ` Dan Carpenter
2 siblings, 0 replies; 4+ messages in thread
From: Hans de Goede @ 2026-02-10 10:41 UTC (permalink / raw)
To: Bartosz Golaszewski, Linus Walleij, Bartosz Golaszewski,
Andy Shevchenko, Greg Kroah-Hartman, Dmitry Torokhov,
Arnd Bergmann, Ilpo Järvinen
Cc: linux-gpio, linux-kernel, platform-driver-x86, stable
Hi,
On 10-Feb-26 10:48, Bartosz Golaszewski wrote:
> Using the remote firmware node for software node lookup is the right
> thing to do. The GPIO controller we want to resolve should have the
> software node we scooped out of the reference attached to it. However,
> there are existing users who abuse the software node API by creating
> dummy swnodes whose name is set to the expected label string of the GPIO
> controller whose pins they want to control and use them in their local
> swnode references as GPIO properties.
>
> This used to work when we compared the software node's name to the
> chip's label. When we switched to using a real fwnode lookup, these
> users broke down because the firmware nodes in question were never
> attached to the controllers they were looking for.
>
> Restore the label matching as a fallback to fix the broken users but add
> a big FIXME urging for a better solution.
>
> Link: https://lore.kernel.org/all/aYmV5Axyfo76D19T@smile.fi.intel.com/
> Cc: stable@vger.kernel.org # v6.18, v6.19
> Fixes: 216c12047571 ("gpio: swnode: allow referencing GPIO chips by firmware nodes")
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
> ---
> drivers/gpio/gpiolib-swnode.c | 19 +++++++++++++++++++
> 1 file changed, 19 insertions(+)
>
> diff --git a/drivers/gpio/gpiolib-swnode.c b/drivers/gpio/gpiolib-swnode.c
> index 21478b45c127d..c88313b0026b9 100644
> --- a/drivers/gpio/gpiolib-swnode.c
> +++ b/drivers/gpio/gpiolib-swnode.c
> @@ -42,6 +42,25 @@ static struct gpio_device *swnode_get_gpio_device(struct fwnode_handle *fwnode)
>
> fwnode_lookup:
> gdev = gpio_device_find_by_fwnode(fwnode);
> + if (!gdev)
This needs to be:
if (!gdev && gdev_node->name)
gdev_node->name may be NULL and calling gpio_device_find_by_label()
with a NULL pointer does not end well.
Regards,
Hans
> + /*
> + * FIXME: We shouldn't need to compare the GPIO controller's
> + * label against the software node that is supposedly attached
> + * to it. However there are currently GPIO users that - knowing
> + * the expected label of the GPIO chip whose pins they want to
> + * control - set up dummy software nodes named after those GPIO
> + * controllers, which aren't actually attached to them. In this
> + * case gpio_device_find_by_fwnode() will fail as no device on
> + * the GPIO bus is actually associated with the fwnode we're
> + * looking for.
> + *
> + * As a fallback: continue checking the label if we have no
> + * match. However, the situation described above is an abuse
> + * of the software node API and should be phased out and the
> + * following line - eventually removed.
> + */
> + gdev = gpio_device_find_by_label(gdev_node->name);
> +
> return gdev ?: ERR_PTR(-EPROBE_DEFER);
> }
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gpio: swnode: restore the swnode-name-against-chip-label matching
2026-02-10 9:48 [PATCH] gpio: swnode: restore the swnode-name-against-chip-label matching Bartosz Golaszewski
2026-02-10 10:06 ` Andy Shevchenko
2026-02-10 10:41 ` Hans de Goede
@ 2026-02-10 19:10 ` Dan Carpenter
2 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2026-02-10 19:10 UTC (permalink / raw)
To: oe-kbuild, Bartosz Golaszewski, Linus Walleij,
Bartosz Golaszewski, Andy Shevchenko, Greg Kroah-Hartman,
Dmitry Torokhov, Arnd Bergmann, Hans de Goede, Ilpo Järvinen
Cc: lkp, oe-kbuild-all, linux-gpio, linux-kernel, platform-driver-x86,
stable
Hi Bartosz,
kernel test robot noticed the following build warnings:
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Bartosz-Golaszewski/gpio-swnode-restore-the-swnode-name-against-chip-label-matching/20260210-175012
base: https://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux.git gpio/for-next
patch link: https://lore.kernel.org/r/20260210094806.38146-1-bartosz.golaszewski%40oss.qualcomm.com
patch subject: [PATCH] gpio: swnode: restore the swnode-name-against-chip-label matching
config: nios2-randconfig-r071-20260210 (https://download.01.org/0day-ci/archive/20260211/202602110128.BInRI9un-lkp@intel.com/config)
compiler: nios2-linux-gcc (GCC) 8.5.0
smatch version: v0.5.0-8994-gd50c5a4c
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
| Closes: https://lore.kernel.org/r/202602110128.BInRI9un-lkp@intel.com/
smatch warnings:
drivers/gpio/gpiolib-swnode.c:62 swnode_get_gpio_device() error: we previously assumed 'gdev_node' could be null (see line 32)
vim +/gdev_node +62 drivers/gpio/gpiolib-swnode.c
b7b56e64a345e7 Bartosz Golaszewski 2023-09-27 26 static struct gpio_device *swnode_get_gpio_device(struct fwnode_handle *fwnode)
e7f9ff5dc90c38 Dmitry Torokhov 2022-11-11 27 {
b7b56e64a345e7 Bartosz Golaszewski 2023-09-27 28 const struct software_node *gdev_node;
b7b56e64a345e7 Bartosz Golaszewski 2023-09-27 29 struct gpio_device *gdev;
e7f9ff5dc90c38 Dmitry Torokhov 2022-11-11 30
b7b56e64a345e7 Bartosz Golaszewski 2023-09-27 31 gdev_node = to_software_node(fwnode);
6774a66d0e103d Bartosz Golaszewski 2025-12-15 @32 if (!gdev_node)
216c1204757190 Bartosz Golaszewski 2025-11-20 33 goto fwnode_lookup;
gdev_node is NULL
e7f9ff5dc90c38 Dmitry Torokhov 2022-11-11 34
9d50f95bc0d5df Charles Keepax 2024-04-16 35 /*
9d50f95bc0d5df Charles Keepax 2024-04-16 36 * Check for a special node that identifies undefined GPIOs, this is
9d50f95bc0d5df Charles Keepax 2024-04-16 37 * primarily used as a key for internal chip selects in SPI bindings.
9d50f95bc0d5df Charles Keepax 2024-04-16 38 */
9d50f95bc0d5df Charles Keepax 2024-04-16 39 if (IS_ENABLED(CONFIG_GPIO_SWNODE_UNDEFINED) &&
6774a66d0e103d Bartosz Golaszewski 2025-12-15 40 gdev_node == &swnode_gpio_undefined)
9d50f95bc0d5df Charles Keepax 2024-04-16 41 return ERR_PTR(-ENOENT);
9d50f95bc0d5df Charles Keepax 2024-04-16 42
216c1204757190 Bartosz Golaszewski 2025-11-20 43 fwnode_lookup:
e5d527be7e6984 Bartosz Golaszewski 2025-11-03 44 gdev = gpio_device_find_by_fwnode(fwnode);
4a61b0b6de0480 Bartosz Golaszewski 2026-02-10 45 if (!gdev)
4a61b0b6de0480 Bartosz Golaszewski 2026-02-10 46 /*
4a61b0b6de0480 Bartosz Golaszewski 2026-02-10 47 * FIXME: We shouldn't need to compare the GPIO controller's
4a61b0b6de0480 Bartosz Golaszewski 2026-02-10 48 * label against the software node that is supposedly attached
4a61b0b6de0480 Bartosz Golaszewski 2026-02-10 49 * to it. However there are currently GPIO users that - knowing
4a61b0b6de0480 Bartosz Golaszewski 2026-02-10 50 * the expected label of the GPIO chip whose pins they want to
4a61b0b6de0480 Bartosz Golaszewski 2026-02-10 51 * control - set up dummy software nodes named after those GPIO
4a61b0b6de0480 Bartosz Golaszewski 2026-02-10 52 * controllers, which aren't actually attached to them. In this
4a61b0b6de0480 Bartosz Golaszewski 2026-02-10 53 * case gpio_device_find_by_fwnode() will fail as no device on
4a61b0b6de0480 Bartosz Golaszewski 2026-02-10 54 * the GPIO bus is actually associated with the fwnode we're
4a61b0b6de0480 Bartosz Golaszewski 2026-02-10 55 * looking for.
4a61b0b6de0480 Bartosz Golaszewski 2026-02-10 56 *
4a61b0b6de0480 Bartosz Golaszewski 2026-02-10 57 * As a fallback: continue checking the label if we have no
4a61b0b6de0480 Bartosz Golaszewski 2026-02-10 58 * match. However, the situation described above is an abuse
4a61b0b6de0480 Bartosz Golaszewski 2026-02-10 59 * of the software node API and should be phased out and the
4a61b0b6de0480 Bartosz Golaszewski 2026-02-10 60 * following line - eventually removed.
4a61b0b6de0480 Bartosz Golaszewski 2026-02-10 61 */
4a61b0b6de0480 Bartosz Golaszewski 2026-02-10 @62 gdev = gpio_device_find_by_label(gdev_node->name);
^^^^^^^^^^^^^^^
Unchecked dereference
4a61b0b6de0480 Bartosz Golaszewski 2026-02-10 63
b7b56e64a345e7 Bartosz Golaszewski 2023-09-27 64 return gdev ?: ERR_PTR(-EPROBE_DEFER);
e7f9ff5dc90c38 Dmitry Torokhov 2022-11-11 65 }
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-02-10 19:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-10 9:48 [PATCH] gpio: swnode: restore the swnode-name-against-chip-label matching Bartosz Golaszewski
2026-02-10 10:06 ` Andy Shevchenko
2026-02-10 10:41 ` Hans de Goede
2026-02-10 19:10 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox