summaryrefslogtreecommitdiff
path: root/drivers/of
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2014-05-22 17:30:22 +0200
committerNitin Garg <nitin.garg@freescale.com>2015-09-17 08:58:22 -0500
commit2b94c0494a3e1cceeafd30f905107378938b8a8e (patch)
tree0db611b81834962a3d9f1832f8d7f390abbfb468 /drivers/of
parent7740576ff24fc5f842e0ed3c09e3c11e9d41a7d5 (diff)
of: Add helper for getting the maximum alias index for a stem
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)
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/base.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index e99f329c905e..974e3adcfebb 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1756,6 +1756,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_aliases_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_aliases_mutex);
+
+ return max;
+}
+
/**
* of_alias_scan - Scan all properties of 'aliases' node
*