Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp869635rwr; Thu, 20 Apr 2023 07:18:30 -0700 (PDT) X-Google-Smtp-Source: AKy350ZmFUnLRzcqeGolxQSNbBhTggn7V+mPSGX73k3geCoYFh432S4mAOK6V9t2rFs9bRhky+Ir X-Received: by 2002:a05:6a20:3d1d:b0:f0:471f:4b03 with SMTP id y29-20020a056a203d1d00b000f0471f4b03mr2806068pzi.48.1682000309967; Thu, 20 Apr 2023 07:18:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682000309; cv=none; d=google.com; s=arc-20160816; b=VEHEk03p8LmvlUQX5wucRF24IEZU853ksjFhYwpEWighg1B032wbgkNSLpvDCZjvEx ClW8UbvGq7tCRIyuTEowvLJhgWYAIPo0BoKC4iHtNS575mN5u9Si+OWCdMP7OAYZFRlR poPLNjia++5Ba0fx1sgl36hXlxMUe5eZpcayDywZQjwJfIkYbc5xjRhTjwS/DKQ+ssVb I7ZYMIRdtmg/oheNmF+Jp1qwmIHxFIFEYEt8IVmKuiDwMROK3Ky0Q+1+BiunAnWrKljN Bd/aCvmrMKDAKORkdu6zIm1WmFAYFt+2QMO4yH0ES9yVx0kCYWl9stQlk70YT9fcemDJ wyZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=HGHj1A9JbSLsvMmhTurGV5BdGxZhdJymJaChORIhdDE=; b=G76FwnNW3V4Ih+EUneahsqzxi4W9iep+oIrYS6aHld5AjlHxbt80r++fMXWFSGyvvE fP1nVG9j1Oifx//0wVTW3V9Mo8Ihlha67GqymUGiypp/gf7tl+vEwWl4gxYI+AQSi78s M1EdUP3nl8g1EJvK8R3sT6S3ic6uA8z1J2aiyK0TBMgTCrZwMe7Dk9IF3N3sNuC/vhxs O/vRV96MWsfg/S/mWwOf0oL79sDYK8ScwVx+tNTlm24Z1Inv3Ie2pwGi+11LPFBFg+/s wAhXt83MLkiqfmw7F3quCMjWhOfCBQ87auBmR8ewlwR6mGzzayTRGX8Lojt0RGX6xaYw 572w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q19-20020a63f953000000b0051b3ea1f2a3si1666184pgk.211.2023.04.20.07.18.04; Thu, 20 Apr 2023 07:18:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231654AbjDTOG0 convert rfc822-to-8bit (ORCPT + 99 others); Thu, 20 Apr 2023 10:06:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229960AbjDTOGX (ORCPT ); Thu, 20 Apr 2023 10:06:23 -0400 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2ADE71BE3; Thu, 20 Apr 2023 07:06:21 -0700 (PDT) Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-506bcf9aa50so255456a12.1; Thu, 20 Apr 2023 07:06:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681999579; x=1684591579; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Jgg7OX/T96wNa/Haq/69/L0IA2HKROIWIem4E4UL828=; b=gLnSZXFo6V2i+tP664G3D1rrx6DXVFhongEIx0E40q+L/9ua5eluS8xX+X4mvFsJuU dHn9l7OaFiWlknnh7Agw5bUOSGGC/MCzIM0F5fZePcbeflSxmJeQfpB7jc+DsiZ5rrZl KKZgYijjfmNWI4OXqdtCyIeReoYO9ijIsFeCfuaq8ApIPzFwSikwTDWUMVkjb8t7SKGg 4pRILbNUFWTHqlqLxSvpPn1r/106xPES0xOHOx1um8QwyplamCJoIRlZ/eQfWEPCOCy2 o2VAH+EAY3j3SGNfS0vJFbUgKKtk7iL2S/oHNbo+7V5P4WKh39TNXjkfm7mxAatIAe9b XIhQ== X-Gm-Message-State: AAQBX9cPIAgeewwa8FeMB+1AvuALSuPUQ1SiGORgu/w+WqduEjWBLwga SvXlLSTqXJ4E87TWgmV1BJhfGFNMKf8g6U7P46ZTUK9t X-Received: by 2002:a17:906:35d1:b0:94f:4ec3:f0f5 with SMTP id p17-20020a17090635d100b0094f4ec3f0f5mr1583546ejb.4.1681999579416; Thu, 20 Apr 2023 07:06:19 -0700 (PDT) MIME-Version: 1.0 References: <20230419164127.3773278-1-linux@roeck-us.net> In-Reply-To: <20230419164127.3773278-1-linux@roeck-us.net> From: "Rafael J. Wysocki" Date: Thu, 20 Apr 2023 16:06:08 +0200 Message-ID: Subject: Re: [PATCH] device property: make device_property functions take const device * To: Guenter Roeck Cc: Greg Kroah-Hartman , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , "Rafael J . Wysocki" , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Chris Packham Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 19, 2023 at 6:41 PM Guenter Roeck wrote: > > device_property functions do not modify the device pointer passed to them. > The underlying of_device and fwnode_ functions actually already take > const * arguments. Mark the parameter constant to simplify conversion > from of_property to device_property functions, and to let the calling code > use const device pointers where possible. > > Cc: Chris Packham > Signed-off-by: Guenter Roeck Acked-by: Rafael J. Wysocki > --- > Found by Chris when trying to convert a driver from of_property_ to > device_property_ functions. I don't really see a reason why the device > parameter to device_property functions should not be const. > Please let me know if I am missing sonething. > > drivers/base/property.c | 16 ++++++++-------- > include/linux/property.h | 36 ++++++++++++++++++------------------ > 2 files changed, 26 insertions(+), 26 deletions(-) > > diff --git a/drivers/base/property.c b/drivers/base/property.c > index 083a95791d3b..21d7a5d13e05 100644 > --- a/drivers/base/property.c > +++ b/drivers/base/property.c > @@ -38,7 +38,7 @@ EXPORT_SYMBOL_GPL(__dev_fwnode_const); > * > * Check if property @propname is present in the device firmware description. > */ > -bool device_property_present(struct device *dev, const char *propname) > +bool device_property_present(const struct device *dev, const char *propname) > { > return fwnode_property_present(dev_fwnode(dev), propname); > } > @@ -86,7 +86,7 @@ EXPORT_SYMBOL_GPL(fwnode_property_present); > * %-EOVERFLOW if the size of the property is not as expected. > * %-ENXIO if no suitable firmware interface is present. > */ > -int device_property_read_u8_array(struct device *dev, const char *propname, > +int device_property_read_u8_array(const struct device *dev, const char *propname, > u8 *val, size_t nval) > { > return fwnode_property_read_u8_array(dev_fwnode(dev), propname, val, nval); > @@ -114,7 +114,7 @@ EXPORT_SYMBOL_GPL(device_property_read_u8_array); > * %-EOVERFLOW if the size of the property is not as expected. > * %-ENXIO if no suitable firmware interface is present. > */ > -int device_property_read_u16_array(struct device *dev, const char *propname, > +int device_property_read_u16_array(const struct device *dev, const char *propname, > u16 *val, size_t nval) > { > return fwnode_property_read_u16_array(dev_fwnode(dev), propname, val, nval); > @@ -142,7 +142,7 @@ EXPORT_SYMBOL_GPL(device_property_read_u16_array); > * %-EOVERFLOW if the size of the property is not as expected. > * %-ENXIO if no suitable firmware interface is present. > */ > -int device_property_read_u32_array(struct device *dev, const char *propname, > +int device_property_read_u32_array(const struct device *dev, const char *propname, > u32 *val, size_t nval) > { > return fwnode_property_read_u32_array(dev_fwnode(dev), propname, val, nval); > @@ -170,7 +170,7 @@ EXPORT_SYMBOL_GPL(device_property_read_u32_array); > * %-EOVERFLOW if the size of the property is not as expected. > * %-ENXIO if no suitable firmware interface is present. > */ > -int device_property_read_u64_array(struct device *dev, const char *propname, > +int device_property_read_u64_array(const struct device *dev, const char *propname, > u64 *val, size_t nval) > { > return fwnode_property_read_u64_array(dev_fwnode(dev), propname, val, nval); > @@ -198,7 +198,7 @@ EXPORT_SYMBOL_GPL(device_property_read_u64_array); > * %-EOVERFLOW if the size of the property is not as expected. > * %-ENXIO if no suitable firmware interface is present. > */ > -int device_property_read_string_array(struct device *dev, const char *propname, > +int device_property_read_string_array(const struct device *dev, const char *propname, > const char **val, size_t nval) > { > return fwnode_property_read_string_array(dev_fwnode(dev), propname, val, nval); > @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(device_property_read_string_array); > * %-EPROTO or %-EILSEQ if the property type is not a string. > * %-ENXIO if no suitable firmware interface is present. > */ > -int device_property_read_string(struct device *dev, const char *propname, > +int device_property_read_string(const struct device *dev, const char *propname, > const char **val) > { > return fwnode_property_read_string(dev_fwnode(dev), propname, val); > @@ -242,7 +242,7 @@ EXPORT_SYMBOL_GPL(device_property_read_string); > * %-EPROTO if the property is not an array of strings, > * %-ENXIO if no suitable firmware interface is present. > */ > -int device_property_match_string(struct device *dev, const char *propname, > +int device_property_match_string(const struct device *dev, const char *propname, > const char *string) > { > return fwnode_property_match_string(dev_fwnode(dev), propname, string); > diff --git a/include/linux/property.h b/include/linux/property.h > index 0a29db15ff34..66fe73ee430d 100644 > --- a/include/linux/property.h > +++ b/include/linux/property.h > @@ -40,20 +40,20 @@ struct fwnode_handle *__dev_fwnode(struct device *dev); > const struct device *: __dev_fwnode_const, \ > struct device *: __dev_fwnode)(dev) > > -bool device_property_present(struct device *dev, const char *propname); > -int device_property_read_u8_array(struct device *dev, const char *propname, > +bool device_property_present(const struct device *dev, const char *propname); > +int device_property_read_u8_array(const struct device *dev, const char *propname, > u8 *val, size_t nval); > -int device_property_read_u16_array(struct device *dev, const char *propname, > +int device_property_read_u16_array(const struct device *dev, const char *propname, > u16 *val, size_t nval); > -int device_property_read_u32_array(struct device *dev, const char *propname, > +int device_property_read_u32_array(const struct device *dev, const char *propname, > u32 *val, size_t nval); > -int device_property_read_u64_array(struct device *dev, const char *propname, > +int device_property_read_u64_array(const struct device *dev, const char *propname, > u64 *val, size_t nval); > -int device_property_read_string_array(struct device *dev, const char *propname, > +int device_property_read_string_array(const struct device *dev, const char *propname, > const char **val, size_t nval); > -int device_property_read_string(struct device *dev, const char *propname, > +int device_property_read_string(const struct device *dev, const char *propname, > const char **val); > -int device_property_match_string(struct device *dev, > +int device_property_match_string(const struct device *dev, > const char *propname, const char *string); > > bool fwnode_property_present(const struct fwnode_handle *fwnode, > @@ -143,57 +143,57 @@ int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name); > > unsigned int device_get_child_node_count(const struct device *dev); > > -static inline bool device_property_read_bool(struct device *dev, > +static inline bool device_property_read_bool(const struct device *dev, > const char *propname) > { > return device_property_present(dev, propname); > } > > -static inline int device_property_read_u8(struct device *dev, > +static inline int device_property_read_u8(const struct device *dev, > const char *propname, u8 *val) > { > return device_property_read_u8_array(dev, propname, val, 1); > } > > -static inline int device_property_read_u16(struct device *dev, > +static inline int device_property_read_u16(const struct device *dev, > const char *propname, u16 *val) > { > return device_property_read_u16_array(dev, propname, val, 1); > } > > -static inline int device_property_read_u32(struct device *dev, > +static inline int device_property_read_u32(const struct device *dev, > const char *propname, u32 *val) > { > return device_property_read_u32_array(dev, propname, val, 1); > } > > -static inline int device_property_read_u64(struct device *dev, > +static inline int device_property_read_u64(const struct device *dev, > const char *propname, u64 *val) > { > return device_property_read_u64_array(dev, propname, val, 1); > } > > -static inline int device_property_count_u8(struct device *dev, const char *propname) > +static inline int device_property_count_u8(const 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) > +static inline int device_property_count_u16(const 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) > +static inline int device_property_count_u32(const 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) > +static inline int device_property_count_u64(const struct device *dev, const char *propname) > { > return device_property_read_u64_array(dev, propname, NULL, 0); > } > > -static inline int device_property_string_array_count(struct device *dev, > +static inline int device_property_string_array_count(const struct device *dev, > const char *propname) > { > return device_property_read_string_array(dev, propname, NULL, 0); > -- > 2.39.2 >