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 3/6] i2c: factor out of_i2c_register_device()
Date: Thu, 19 Nov 2026 19:58:13 +0100 [thread overview]
Message-ID: <20261119185828.92337-3-a.fatoum@barebox.org> (raw)
In-Reply-To: <20261119185828.92337-1-a.fatoum@barebox.org>
Let's move the registration of a single device node into its own
function. A follow-up commit will use it to register only the node
requested by the rescan hook.
No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
drivers/i2c/i2c.c | 72 +++++++++++++++++++++++++----------------------
1 file changed, 38 insertions(+), 34 deletions(-)
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index cfc340736309..ef92854eefe0 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -427,6 +427,42 @@ void i2c_unregister_device(struct i2c_client *client)
devinfo_del(&client->dev, i2c_info);
}
+static void of_i2c_register_device(struct i2c_adapter *adap,
+ struct device_node *n)
+{
+ struct i2c_board_info info = {};
+ struct i2c_client *result;
+ const __be32 *addr;
+ int len;
+
+ if (n->dev) {
+ dev_dbg(&adap->dev, "of_i2c: skipping already registered %s\n",
+ dev_name(n->dev));
+ return;
+ }
+
+ of_modalias_node(n, info.type, I2C_NAME_SIZE);
+
+ info.of_node = n;
+
+ addr = of_get_property(n, "reg", &len);
+ if (!addr || (len < sizeof(int))) {
+ dev_err(&adap->dev, "of_i2c: invalid reg on %pOF\n", n);
+ return;
+ }
+
+ info.addr = be32_to_cpup(addr);
+ if (info.addr > (1 << 10) - 1) {
+ dev_err(&adap->dev, "of_i2c: invalid addr=%x on %pOF\n",
+ info.addr, n);
+ return;
+ }
+
+ result = i2c_new_device(adap, &info);
+ if (!result)
+ dev_err(&adap->dev, "of_i2c: Failure registering %pOF\n", n);
+}
+
static void of_i2c_register_devices(struct i2c_adapter *adap)
{
struct device_node *n;
@@ -435,40 +471,8 @@ static void of_i2c_register_devices(struct i2c_adapter *adap)
if (!IS_ENABLED(CONFIG_OFDEVICE) || !adap->dev.of_node)
return;
- for_each_available_child_of_node(adap->dev.of_node, n) {
- struct i2c_board_info info = {};
- struct i2c_client *result;
- const __be32 *addr;
- int len;
-
- if (n->dev) {
- dev_dbg(&adap->dev, "of_i2c: skipping already registered %s\n",
- dev_name(n->dev));
- continue;
- }
-
- of_modalias_node(n, info.type, I2C_NAME_SIZE);
-
- info.of_node = n;
-
- addr = of_get_property(n, "reg", &len);
- if (!addr || (len < sizeof(int))) {
- dev_err(&adap->dev, "of_i2c: invalid reg on %pOF\n", n);
- continue;
- }
-
- info.addr = be32_to_cpup(addr);
- if (info.addr > (1 << 10) - 1) {
- dev_err(&adap->dev, "of_i2c: invalid addr=%x on %pOF\n",
- info.addr, n);
- continue;
- }
-
- result = i2c_new_device(adap, &info);
- if (!result)
- dev_err(&adap->dev, "of_i2c: Failure registering %pOF\n",
- n);
- }
+ for_each_available_child_of_node(adap->dev.of_node, n)
+ of_i2c_register_device(adap, n);
}
int of_i2c_register_devices_by_node(struct device_node *node)
--
2.47.3
next prev parent reply other threads:[~2026-11-19 19:00 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 ` Ahmad Fatoum [this message]
2026-11-19 18:58 ` [PATCH 4/6] i2c: allow creating siblings on demand while populating the bus Ahmad Fatoum
2026-11-20 11:04 ` 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-3-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