From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 1/3] of: replace of_alias_get_highest_id() with of_alias_get_free_id()
Date: Wed, 17 Dec 2025 15:51:53 +0100 [thread overview]
Message-ID: <20251217145156.1581678-1-s.hauer@pengutronix.de> (raw)
of_alias_get_highest_id() returns the highest alias id used for a stem.
This return value is not what the callers actually need. They need the
first free ID instead. Replace of_alias_get_highest_id() with
of_alias_get_free_id() which returns that value. This variant doesn't
need to handle the special case when no alias for a stem is found
in the device tree. In this case of_alias_get_highest_id() returned a
negative error code which must be handled. The new function is more
handy for the callers, it just returns 0 which can be used as a free
id.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/eeprom/at24.c | 2 +-
drivers/i2c/i2c.c | 16 +---------------
drivers/of/base.c | 10 +++++-----
include/of.h | 6 +++---
4 files changed, 10 insertions(+), 24 deletions(-)
diff --git a/drivers/eeprom/at24.c b/drivers/eeprom/at24.c
index 5dc1980097..508ddbc7b3 100644
--- a/drivers/eeprom/at24.c
+++ b/drivers/eeprom/at24.c
@@ -429,7 +429,7 @@ static int at24_probe(struct device *dev)
} else {
devname = "eeprom";
devid = get_free_deviceid_from(devname,
- of_alias_get_highest_id(devname) + 1);
+ of_alias_get_free_id(devname));
}
writable = !(chip.flags & AT24_FLAG_READONLY);
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 7b11c35039..0f294a93bf 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -685,20 +685,6 @@ void i2c_parse_fw_timings(struct device *dev, struct i2c_timings *t,
}
EXPORT_SYMBOL_GPL(i2c_parse_fw_timings);
-/**
- * i2c_first_nonreserved_index() - get the first index that is not reserved
- */
-static int i2c_first_nonreserved_index(void)
-{
- int max;
-
- max = of_alias_get_highest_id("i2c");
- if (max < 0)
- return 0;
-
- return max + 1;
-}
-
/**
* i2c_add_numbered_adapter - declare i2c adapter, use static bus number
* @adapter: the adapter to register (with adap->nr initialized)
@@ -725,7 +711,7 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
if (adapter->nr < 0) {
int nr;
- for (nr = i2c_first_nonreserved_index();
+ for (nr = of_alias_get_free_id("i2c");
i2c_get_adapter(nr); nr++)
;
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 0a7704ca10..ebedd7c56f 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -273,16 +273,16 @@ int of_alias_get_id(struct device_node *np, const char *stem)
EXPORT_SYMBOL_GPL(of_alias_get_id);
/**
- * of_alias_get_highest_id - Get highest alias id for the given stem
+ * of_alias_get_free_id - Get lowest free alias id for the given stem
* @stem: Alias stem to be examined
*
* The function travels the lookup table to get the highest alias id for the
- * given alias stem. It returns the alias id if found.
+ * given alias stem. It returns the lowest free alias id.
*/
-int of_alias_get_highest_id(const char *stem)
+int of_alias_get_free_id(const char *stem)
{
struct alias_prop *app;
- int id = -ENODEV;
+ int id = -1;
list_for_each_entry(app, &aliases_lookup, link) {
if (strcmp(app->stem, stem) != 0)
@@ -292,7 +292,7 @@ int of_alias_get_highest_id(const char *stem)
id = app->id;
}
- return id;
+ return id + 1;
}
EXPORT_SYMBOL_GPL(of_alias_get_highest_id);
diff --git a/include/of.h b/include/of.h
index d1efab13c7..a40f8bdd9d 100644
--- a/include/of.h
+++ b/include/of.h
@@ -410,7 +410,7 @@ extern void of_alias_scan(void);
extern int of_alias_get_id(struct device_node *np, const char *stem);
extern int of_alias_get_id_from(struct device_node *root, struct device_node *np,
const char *stem);
-extern int of_alias_get_highest_id(const char *stem);
+extern int of_alias_get_free_id(const char *stem);
extern const char *of_alias_get(struct device_node *np);
extern int of_modalias_node(struct device_node *node, char *modalias, int len);
@@ -1084,9 +1084,9 @@ static inline int of_alias_get_id_from(struct device_node *root, struct device_n
return -ENOSYS;
}
-static inline int of_alias_get_highest_id(const char *stem)
+static inline int of_alias_get_free_id(const char *stem)
{
- return -ENOSYS;
+ return 0;
}
static inline const char *of_alias_get(struct device_node *np)
--
2.47.3
next reply other threads:[~2025-12-17 14:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-17 14:51 Sascha Hauer [this message]
2025-12-17 14:51 ` [PATCH 2/3] i2c: implement i2c_unregister_device() Sascha Hauer
2025-12-17 14:51 ` [PATCH 3/3] eeprom: at24: unregister devices in error path Sascha Hauer
2025-12-18 8:40 ` [PATCH 1/3] of: replace of_alias_get_highest_id() with of_alias_get_free_id() Sascha Hauer
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=20251217145156.1581678-1-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.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