of: Add helper for getting the maximum alias index for a stem
authorSascha Hauer <s.hauer@pengutronix.de>
Thu, 22 May 2014 15:30:22 +0000 (17:30 +0200)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 19:48:47 +0000 (14:48 -0500)
of_alias_max_index will return the maximum number for which an
alias of a given stem exists. This is useful for frameworks
whishing to reserve a number of device slots from dynamic
allocation.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
(cherry picked from commit 5ce2ad39b36fd48b9f77249198655da7cbcc7ee5)

Conflicts:
include/linux/of.h

drivers/of/base.c
include/linux/of.h

index a0bccb5..5fbd492 100644 (file)
@@ -2049,6 +2049,35 @@ static void of_alias_add(struct alias_prop *ap, struct device_node *np,
                 ap->alias, ap->stem, ap->id, of_node_full_name(np));
 }
 
+/*
+ * of_alias_max_index() - get the maximum index for a given alias stem
+ * @stem:   The alias stem for which the maximum index is searched for
+ *
+ * Given an alias stem (the alias without the number) this function
+ * returns the maximum number for which an alias exists.
+ *
+ * Return: The maximum existing alias index or -ENODEV if no alias
+ *         exists for this stem.
+ */
+int of_alias_max_index(const char *stem)
+{
+       struct alias_prop *app;
+       int max = -ENODEV;
+
+       mutex_lock(&of_mutex);
+
+       list_for_each_entry(app, &aliases_lookup, link) {
+               if (strcmp(app->stem, stem))
+                       continue;
+               if (app->id > max)
+                       max = app->id;
+       }
+
+       mutex_unlock(&of_mutex);
+
+       return max;
+}
+
 /**
  * of_alias_scan - Scan all properties of the 'aliases' node
  *
index 299aeb1..fc12b43 100644 (file)
@@ -365,6 +365,7 @@ extern int of_phandle_iterator_args(struct of_phandle_iterator *it,
 extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align));
 extern int of_alias_get_id(struct device_node *np, const char *stem);
 extern int of_alias_get_highest_id(const char *stem);
+extern int of_alias_max_index(const char *stem);
 
 extern int of_machine_is_compatible(const char *compat);
 
@@ -783,6 +784,11 @@ static inline int of_alias_get_highest_id(const char *stem)
        return -ENOSYS;
 }
 
+static inline int of_alias_max_index(const char *stem)
+{
+       return -ENODEV;
+}
+
 static inline int of_machine_is_compatible(const char *compat)
 {
        return 0;