From patchwork Thu Dec 13 16:49:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 1875711 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 4D45DDF23A for ; Thu, 13 Dec 2012 17:22:20 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TjCRF-0003Le-56; Thu, 13 Dec 2012 17:19:13 +0000 Received: from service87.mimecast.com ([91.220.42.44]) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TjBz1-0000kZ-3L for linux-arm-kernel@lists.infradead.org; Thu, 13 Dec 2012 16:50:03 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Thu, 13 Dec 2012 16:50:01 +0000 Received: from localhost.localdomain ([10.1.255.212]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.0); Thu, 13 Dec 2012 16:50:00 +0000 From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Subject: [RFCv2 1/2] of: add of_property_read_u32_index Date: Thu, 13 Dec 2012 16:49:27 +0000 Message-Id: <1355417368-6861-2-git-send-email-mark.rutland@arm.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1355417368-6861-1-git-send-email-mark.rutland@arm.com> References: <1355417368-6861-1-git-send-email-mark.rutland@arm.com> X-OriginalArrivalTime: 13 Dec 2012 16:50:00.0072 (UTC) FILETIME=[E3C7E880:01CDD951] X-MC-Unique: 112121316500108201 X-Bad-Reply: References and In-Reply-To but no 'Re:' in Subject. X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121213_115003_372582_C5F92E63 X-CRM114-Status: GOOD ( 13.41 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [91.220.42.44 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Mailman-Approved-At: Thu, 13 Dec 2012 12:18:34 -0500 Cc: Mark Rutland , Lorenzo.Pieralisi@arm.com, benh@kernel.crashing.org, devicetree-discuss@lists.ozlabs.org, Will.Deacon@arm.com, rob.herring@calxeda.com, grant.likely@secretlab.ca, tglx@linutronix.de X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Currently, we have to pre-allocate an array when reading multiple u32 values from a property using of_property_read_u32_array. This isn't very good for times when we want to iterate over elements of a list of arbitrary size. This patch adds a function to read a single u32 value from an arbitrary index in a list, making this case easier. Signed-off-by: Mark Rutland --- drivers/of/base.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/of.h | 11 +++++++++++ 2 files changed, 47 insertions(+), 0 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index af3b22a..5ad6830 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -707,6 +707,42 @@ int of_property_read_u32_array(const struct device_node *np, EXPORT_SYMBOL_GPL(of_property_read_u32_array); /** + * of_property_read_u32_index - Find and read a 32 bit integer from a multiple + * integer property. + * + * @np: device node from which the property value is to be read. + * @propname: name of the property to be searched. + * @out_value: pointer to return value, modified only if return value is 0. + * @index: index of the integer in the list of integers. + * + * Search for a property in a device node and read a 32-bit value from + * it. Returns 0 on success, -EINVAL if the property does not exist, + * -ENODATA if property does not have a value, and -EOVERFLOW if the + * index is beyond the range of data. + * + * The out_value is modified only if a valid u32 value can be decoded. + */ +int of_property_read_u32_index(const struct device_node *np, + const char *propname, u32 *out_value, + int idx) +{ + struct property *prop = of_find_property(np, propname, NULL); + const __be32 *val; + + if (!prop) + return -EINVAL; + if (!prop->value) + return -ENODATA; + if ((idx+1) * sizeof(*out_value) > prop->length) + return -EOVERFLOW; + + val = prop->value; + *out_value = be32_to_cpup(val + idx); + return 0; +} +EXPORT_SYMBOL_GPL(of_property_read_u32_index); + +/** * of_property_read_u64 - Find and read a 64 bit integer from a property * @np: device node from which the property value is to be read. * @propname: name of the property to be searched. diff --git a/include/linux/of.h b/include/linux/of.h index b4e50d5..37f6f67 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -227,6 +227,10 @@ extern int of_property_read_u32_array(const struct device_node *np, const char *propname, u32 *out_values, size_t sz); +extern int of_property_read_u32_index(const struct device_node *np, + const char *propname, + u32 *out_value, + int idx); extern int of_property_read_u64(const struct device_node *np, const char *propname, u64 *out_value); @@ -371,6 +375,13 @@ static inline int of_property_read_u32_array(const struct device_node *np, return -ENOSYS; } +static inline int of_property_read_u32_index(const struct device_node *np, + const char *propname, + u32 *out_value, int idx) +{ + return -ENOSYS; +} + static inline int of_property_read_string(struct device_node *np, const char *propname, const char **out_string)