public inbox for linux-gpio@vger.kernel.org
 help / color / mirror / Atom feed
From: Tzung-Bi Shih <tzungbi@kernel.org>
To: Linus Walleij <linusw@kernel.org>, Bartosz Golaszewski <brgl@kernel.org>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	tzungbi@kernel.org, Geert Uytterhoeven <geert@linux-m68k.org>
Subject: [PATCH] Revert "gpio: Access `gpio_bus_type` in gpiochip_setup_dev()"
Date: Fri, 13 Mar 2026 05:41:12 +0000	[thread overview]
Message-ID: <20260313054112.1248074-1-tzungbi@kernel.org> (raw)

This reverts commit cc11f4ef666fbca02c8a2f11d0184d57e6b75579.

Commit cc11f4ef666f ("gpio: Access `gpio_bus_type` in
gpiochip_setup_dev()") moved the bus type assignment from
gpiochip_add_data_with_key() to gpiochip_setup_dev().

This change introduced a bug where dev_printk() and friends might access
the bus name after gpiochip_add_data_with_key() but before
gpiochip_setup_dev() has run.  In this window, the bus type is not yet
initialized, leading to empty bus names in logs.

Move the bus type assignment back to gpiochip_add_data_with_key() to
ensure the bus name is available before any potential users like
dev_printk().

Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Closes: https://lore.kernel.org/all/CAMuHMdU0Xb=Moca5LUex+VxyHQa2-uYJgYf4hzHiSEjDCQQT=Q@mail.gmail.com/
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
Geert: I hadn't seen the revert patch, so I've sent out a version.

Bart: In any case, please feel free to pick this patch.

 drivers/gpio/gpiolib.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index bbb96e52197c..c1290ba20eac 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -903,8 +903,6 @@ static int gpiochip_setup_dev(struct gpio_chip *gc)
 	struct fwnode_handle *fwnode = dev_fwnode(&gdev->dev);
 	int ret;
 
-	gdev->dev.bus = &gpio_bus_type;
-
 	/*
 	 * If fwnode doesn't belong to another device, it's safe to clear its
 	 * initialized flag.
@@ -1095,6 +1093,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
 	 * then make sure they get free():ed there.
 	 */
 	gdev->dev.type = &gpio_dev_type;
+	gdev->dev.bus = &gpio_bus_type;
 	gdev->dev.parent = gc->parent;
 	device_set_node(&gdev->dev, gpiochip_choose_fwnode(gc));
 
@@ -1232,8 +1231,8 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
 	 * we get a device node entry in sysfs under
 	 * /sys/bus/gpio/devices/gpiochipN/dev that can be used for
 	 * coldplug of device nodes and other udev business.
-	 * We can do this only if gpiolib has been initialized
-	 * (i.e., `gpio_bus_type` is ready).  Otherwise, defer until later.
+	 * We can do this only if gpiolib has been initialized.
+	 * Otherwise, defer until later.
 	 */
 	if (gpiolib_initialized) {
 		ret = gpiochip_setup_dev(gc);
-- 
2.53.0.851.ga537e3e6e9-goog


             reply	other threads:[~2026-03-13  5:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-13  5:41 Tzung-Bi Shih [this message]
2026-03-16  9:11 ` [PATCH] Revert "gpio: Access `gpio_bus_type` in gpiochip_setup_dev()" Bartosz Golaszewski

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=20260313054112.1248074-1-tzungbi@kernel.org \
    --to=tzungbi@kernel.org \
    --cc=brgl@kernel.org \
    --cc=geert@linux-m68k.org \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@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