[PATCH 1/3] of: replace of_alias_get_highest_id() with of_alias_get_free_id()
Sascha Hauer
s.hauer at pengutronix.de
Wed Dec 17 06:51:53 PST 2025
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 at 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
More information about the barebox
mailing list