From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBB85C4321A for ; Thu, 27 Jun 2019 21:47:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AB6FD2063F for ; Thu, 27 Jun 2019 21:47:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726502AbfF0VrC (ORCPT ); Thu, 27 Jun 2019 17:47:02 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:52154 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726441AbfF0VrC (ORCPT ); Thu, 27 Jun 2019 17:47:02 -0400 Received: from 79.184.254.216.ipv4.supernova.orange.pl (79.184.254.216) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.267) id db20b9a18c2deace; Thu, 27 Jun 2019 23:46:58 +0200 From: "Rafael J. Wysocki" To: Andy Shevchenko Cc: "Rafael J. Wysocki" , Heikki Krogerus , linux-kernel@vger.kernel.org, Sakari Ailus , linux-acpi@vger.kernel.org Subject: Re: [PATCH v2, resend] device property: Add helpers to count items in an array Date: Thu, 27 Jun 2019 23:46:58 +0200 Message-ID: <8241229.JvE1M4mS3H@kreacher> In-Reply-To: <20190613165951.64148-1-andriy.shevchenko@linux.intel.com> References: <20190613165951.64148-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org On Thursday, June 13, 2019 6:59:51 PM CEST Andy Shevchenko wrote: > The usual pattern to allocate the necessary space for an array of properties is > to count them first by calling: > > count = device_property_read_uXX_array(dev, propname, NULL, 0); > if (count < 0) > return count; > > Introduce helpers device_property_count_uXX() to count items by supplying hard > coded last two parameters to device_property_readXX_array(). > > Signed-off-by: Andy Shevchenko > Acked-by: Sakari Ailus > Reviewed-by: Heikki Krogerus > --- > include/linux/property.h | 44 ++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 44 insertions(+) > > diff --git a/include/linux/property.h b/include/linux/property.h > index 088d4db7e949..dbacf17fff2e 100644 > --- a/include/linux/property.h > +++ b/include/linux/property.h > @@ -148,6 +148,26 @@ static inline int device_property_read_u64(struct device *dev, > return device_property_read_u64_array(dev, propname, val, 1); > } > > +static inline int device_property_count_u8(struct device *dev, const char *propname) > +{ > + return device_property_read_u8_array(dev, propname, NULL, 0); > +} > + > +static inline int device_property_count_u16(struct device *dev, const char *propname) > +{ > + return device_property_read_u16_array(dev, propname, NULL, 0); > +} > + > +static inline int device_property_count_u32(struct device *dev, const char *propname) > +{ > + return device_property_read_u32_array(dev, propname, NULL, 0); > +} > + > +static inline int device_property_count_u64(struct device *dev, const char *propname) > +{ > + return device_property_read_u64_array(dev, propname, NULL, 0); > +} > + > static inline bool fwnode_property_read_bool(const struct fwnode_handle *fwnode, > const char *propname) > { > @@ -178,6 +198,30 @@ static inline int fwnode_property_read_u64(const struct fwnode_handle *fwnode, > return fwnode_property_read_u64_array(fwnode, propname, val, 1); > } > > +static inline int fwnode_property_count_u8(const struct fwnode_handle *fwnode, > + const char *propname) > +{ > + return fwnode_property_read_u8_array(fwnode, propname, NULL, 0); > +} > + > +static inline int fwnode_property_count_u16(const struct fwnode_handle *fwnode, > + const char *propname) > +{ > + return fwnode_property_read_u16_array(fwnode, propname, NULL, 0); > +} > + > +static inline int fwnode_property_count_u32(const struct fwnode_handle *fwnode, > + const char *propname) > +{ > + return fwnode_property_read_u32_array(fwnode, propname, NULL, 0); > +} > + > +static inline int fwnode_property_count_u64(const struct fwnode_handle *fwnode, > + const char *propname) > +{ > + return fwnode_property_read_u64_array(fwnode, propname, NULL, 0); > +} > + > /** > * struct property_entry - "Built-in" device property representation. > * @name: Name of the property. > Applied, thanks!