aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2014-05-22 11:30:22 -0400
committerDong Aisheng <b29396@freescale.com>2014-06-24 02:11:52 -0400
commitc819acf447205b1040d21606271899e19f9ade05 (patch)
tree2b9b51ea327479defaec1c6c1887bdc18f26b4dc /drivers/of
parent9f82045316a36af3a4ea9a666f367de416a2237a (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 18ae7362e9822993436c1a544e49cfd58fa175b2)
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 c258df42b002..5e713b42621f 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1588,6 +1588,35 @@ static void of_alias_add(struct alias_prop *ap, struct device_node *np,
1588 ap->alias, ap->stem, ap->id, of_node_full_name(np)); 1588 ap->alias, ap->stem, ap->id, of_node_full_name(np));
1589} 1589}
1590 1590
1591/*
1592 * of_alias_max_index() - get the maximum index for a given alias stem
1593 * @stem: The alias stem for which the maximum index is searched for
1594 *
1595 * Given an alias stem (the alias without the number) this function
1596 * returns the maximum number for which an alias exists.
1597 *
1598 * Return: The maximum existing alias index or -ENODEV if no alias
1599 * exists for this stem.
1600 */
1601int of_alias_max_index(const char *stem)
1602{
1603 struct alias_prop *app;
1604 int max = -ENODEV;
1605
1606 mutex_lock(&of_aliases_mutex);
1607
1608 list_for_each_entry(app, &aliases_lookup, link) {
1609 if (strcmp(app->stem, stem))
1610 continue;
1611 if (app->id > max)
1612 max = app->id;
1613 }
1614
1615 mutex_unlock(&of_aliases_mutex);
1616
1617 return max;
1618}
1619
1591/** 1620/**
1592 * of_alias_scan - Scan all properties of 'aliases' node 1621 * of_alias_scan - Scan all properties of 'aliases' node
1593 * 1622 *