From patchwork Thu May 22 15:30:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sascha Hauer X-Patchwork-Id: 4223901 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EF9AD9F36A for ; Thu, 22 May 2014 15:30:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C0CA12037A for ; Thu, 22 May 2014 15:30:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 933E420379 for ; Thu, 22 May 2014 15:30:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751893AbaEVPan (ORCPT ); Thu, 22 May 2014 11:30:43 -0400 Received: from metis.ext.pengutronix.de ([92.198.50.35]:60861 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751422AbaEVPan (ORCPT ); Thu, 22 May 2014 11:30:43 -0400 Received: from dude.hi.pengutronix.de ([2001:6f8:1178:2:a236:9fff:fe00:814]) by metis.ext.pengutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1WnUwr-0002Be-NU; Thu, 22 May 2014 17:30:25 +0200 Received: from sha by dude.hi.pengutronix.de with local (Exim 4.82) (envelope-from ) id 1WnUwx-0007dX-9o; Thu, 22 May 2014 17:30:31 +0200 From: Sascha Hauer To: linux-mmc@vger.kernel.org Cc: Dirk Behme , Fabio Estevam , ptx@pengutronix.de, Stephen Warren , Sascha Hauer Subject: [PATCH 1/2] of: Add helper for getting the maximum alias index for a stem Date: Thu, 22 May 2014 17:30:22 +0200 Message-Id: <1400772623-8390-2-git-send-email-s.hauer@pengutronix.de> X-Mailer: git-send-email 2.0.0.rc0 In-Reply-To: <1400772623-8390-1-git-send-email-s.hauer@pengutronix.de> References: <1400772623-8390-1-git-send-email-s.hauer@pengutronix.de> X-SA-Exim-Connect-IP: 2001:6f8:1178:2:a236:9fff:fe00:814 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-mmc@vger.kernel.org Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/of/base.c | 29 +++++++++++++++++++++++++++++ include/linux/of.h | 6 ++++++ 2 files changed, 35 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index f807d0e..f953b9d 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1758,6 +1758,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 * diff --git a/include/linux/of.h b/include/linux/of.h index 276c546..963e295 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -305,6 +305,7 @@ extern int of_count_phandle_with_args(const struct device_node *np, 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_max_index(const char *stem); extern int of_machine_is_compatible(const char *compat); @@ -532,6 +533,11 @@ static inline int of_alias_get_id(struct device_node *np, 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;