From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Alexander Shiyan <eagle.alexander923@gmail.com>,
Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 4/6] i2c: allow creating siblings on demand while populating the bus
Date: Thu, 19 Nov 2026 19:58:14 +0100 [thread overview]
Message-ID: <20261119185828.92337-4-a.fatoum@barebox.org> (raw)
In-Reply-To: <20261119185828.92337-1-a.fatoum@barebox.org>
With deep probe, a device probed while its adapter populates the bus
may depend on a sibling that comes later in the device tree, e.g. a
GPIO expander whose vcc-supply is a PMIC regulator. To create the PMIC,
of_device_create_on_demand() rescans the controller, but the rescan
hook is only installed after population. So the PMIC node gets a
platform device without a driver instead, the bus then skips it as
already registered and the PMIC never probes.
Install the hook before populating the bus. Alone, that makes the
nested rescan register the expander again, recursing until the stack
overflows, because its node only gets its device after probe. So set
it before registering the client, like platform devices already do.
The nested rescan must also register only the requested node.
Otherwise, all later siblings are probed while the expander is still
probing, and one using the expander's GPIOs fails to get them.
Reported-by: Alexander Shiyan <eagle.alexander923@gmail.com>
Link: https://lore.barebox.org/CAP1tNvRtU8munqnUTiqU_zEP_rxdm_hb42u_oU1FVL93czrtFA@mail.gmail.com
Fixes: 7d8f15b36489 ("i2c: implement rescan")
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
drivers/i2c/i2c.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index ef92854eefe0..d0f9be826025 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -405,16 +405,17 @@ static struct i2c_client *i2c_new_device(struct i2c_adapter *adapter,
client->dev.parent = &adapter->dev;
+ /* claim the node before probe can rescan the bus */
+ of_node_set_dev(chip->of_node, &client->dev);
+
status = register_device(&client->dev);
if (status) {
+ of_node_set_dev(chip->of_node, NULL);
free(client);
return NULL;
}
devinfo_add(&client->dev, i2c_info);
- if (chip->of_node)
- chip->of_node->dev = &client->dev;
-
dev_dbg(&client->dev, "registered on bus %d, chip->addr 0x%02x\n",
adapter->nr, client->addr);
@@ -496,7 +497,12 @@ static void i2c_hw_rescan(struct device *dev, struct device_node *np)
for_each_i2c_adapter(adap) {
if (dev != adap->dev.parent)
continue;
- of_i2c_register_devices(adap);
+
+ if (!np)
+ of_i2c_register_devices(adap);
+ else if (np->parent == adap->dev.of_node &&
+ of_device_is_available(np))
+ of_i2c_register_device(adap, np);
break;
}
}
@@ -742,17 +748,18 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
slice_init(&adapter->slice, dev_name(&adapter->dev));
- /* populate children from any i2c device tables */
- scan_boardinfo(adapter);
-
- of_i2c_register_devices(adapter);
-
+ /* children probed below may need their siblings created on demand */
hw_dev = adapter->dev.parent;
if (hw_dev && dev_of_node(hw_dev)) {
if (!hw_dev->rescan)
hw_dev->rescan = i2c_hw_rescan;
}
+ /* populate children from any i2c device tables */
+ scan_boardinfo(adapter);
+
+ of_i2c_register_devices(adapter);
+
return 0;
}
EXPORT_SYMBOL(i2c_add_numbered_adapter);
--
2.47.3
next prev parent reply other threads:[~2026-11-19 18:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 18:58 [PATCH 1/6] spi: fix NULL pointer dereference for board info devices Ahmad Fatoum
2026-11-19 18:58 ` [PATCH 2/6] driver: pass the requested node to the rescan hook Ahmad Fatoum
2026-11-19 18:58 ` [PATCH 3/6] i2c: factor out of_i2c_register_device() Ahmad Fatoum
2026-11-19 18:58 ` Ahmad Fatoum [this message]
2026-11-20 11:04 ` [PATCH 4/6] i2c: allow creating siblings on demand while populating the bus Alexander Shiyan
2026-11-19 18:58 ` [PATCH 5/6] spi: factor out spi_of_register_slave() Ahmad Fatoum
2026-11-19 18:58 ` [PATCH 6/6] spi: allow creating siblings on demand while populating the bus Ahmad Fatoum
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=20261119185828.92337-4-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
--cc=eagle.alexander923@gmail.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