From patchwork Fri Apr 8 18:48:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12807118 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D0D5C433EF for ; Fri, 8 Apr 2022 18:49:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238956AbiDHSvm (ORCPT ); Fri, 8 Apr 2022 14:51:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233108AbiDHSvk (ORCPT ); Fri, 8 Apr 2022 14:51:40 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C39791CA13B; Fri, 8 Apr 2022 11:49:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649443775; x=1680979775; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=daPwwK0cfexVVreME76t5ptpRPDPiAG+S6sEydOhfxY=; b=JGaKDt/JaI4db+ZwLiJLGGlGjLdS55E2XMqWRHvxzB+PX+OlAuzeZFsB uX4enU52ksMigvPp/WW+stbVPflOWvX6EDkGYs6qHV/3z4Om3H47PO63V /bDfppa0fv7Zz0MwSYp/tAkcWFK9OJSzk2QVZvy7fND4JJvCu6TxiogUW 9AYnlMcedEanlCBc1hZxQ8yvSi1oXL+ztF8ETEbCow3mueFftQr3x20c0 OmjMhKuk7EV8ewSUdBZ7Oqty9WGGS9Yq7QnvMauTdEXPC51YR0yUlfprG VBHrePoI7z029+lClNjWs41QB7Uhpw1yTLmZvbqX+UF7bn6pZANzMsXtJ Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10311"; a="348099328" X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="348099328" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2022 11:49:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="852173965" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga005.fm.intel.com with ESMTP; 08 Apr 2022 11:49:31 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 2969C144; Fri, 8 Apr 2022 21:48:46 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Rob Herring , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Len Brown , =?utf-8?q?Nuno_S=C3=A1?= , Michael Walle Subject: [PATCH v6 1/5] device property: Allow error pointer to be passed to fwnode APIs Date: Fri, 8 Apr 2022 21:48:40 +0300 Message-Id: <20220408184844.22829-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Some of the fwnode APIs might return an error pointer instead of NULL or valid fwnode handle. The result of such API call may be considered optional and hence the test for it is usually done in a form of fwnode = fwnode_find_reference(...); if (IS_ERR(fwnode)) ...error handling... Nevertheless the resulting fwnode may have bumped the reference count and hence caller of the above API is obliged to call fwnode_handle_put(). Since fwnode may be not valid either as NULL or error pointer the check has to be performed there. This approach uglifies the code and adds a point of making a mistake, i.e. forgetting about error point case. To prevent this, allow an error pointer to be passed to the fwnode APIs. Fixes: 83b34afb6b79 ("device property: Introduce fwnode_find_reference()") Reported-by: Nuno Sá Tested-by: Nuno Sá Acked-by: Nuno Sá Reviewed-by: Sakari Ailus Reviewed-by: Heikki Krogerus Signed-off-by: Andy Shevchenko Tested-by: Michael Walle --- v6: added tag (Michael), avoid shadowing error code (Michael) drivers/base/property.c | 89 +++++++++++++++++++++++------------------ include/linux/fwnode.h | 10 ++--- 2 files changed, 56 insertions(+), 43 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index 3560c4419d11..6ecc1398b0ba 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -47,12 +47,14 @@ bool fwnode_property_present(const struct fwnode_handle *fwnode, { bool ret; + if (IS_ERR_OR_NULL(fwnode)) + return false; + ret = fwnode_call_bool_op(fwnode, property_present, propname); - if (ret == false && !IS_ERR_OR_NULL(fwnode) && - !IS_ERR_OR_NULL(fwnode->secondary)) - ret = fwnode_call_bool_op(fwnode->secondary, property_present, - propname); - return ret; + if (ret) + return ret; + + return fwnode_call_bool_op(fwnode->secondary, property_present, propname); } EXPORT_SYMBOL_GPL(fwnode_property_present); @@ -232,15 +234,16 @@ static int fwnode_property_read_int_array(const struct fwnode_handle *fwnode, { int ret; + if (IS_ERR_OR_NULL(fwnode)) + return -EINVAL; + ret = fwnode_call_int_op(fwnode, property_read_int_array, propname, elem_size, val, nval); - if (ret == -EINVAL && !IS_ERR_OR_NULL(fwnode) && - !IS_ERR_OR_NULL(fwnode->secondary)) - ret = fwnode_call_int_op( - fwnode->secondary, property_read_int_array, propname, - elem_size, val, nval); + if (ret != -EINVAL) + return ret; - return ret; + return fwnode_call_int_op(fwnode->secondary, property_read_int_array, propname, + elem_size, val, nval); } /** @@ -371,14 +374,16 @@ int fwnode_property_read_string_array(const struct fwnode_handle *fwnode, { int ret; + if (IS_ERR_OR_NULL(fwnode)) + return -EINVAL; + ret = fwnode_call_int_op(fwnode, property_read_string_array, propname, val, nval); - if (ret == -EINVAL && !IS_ERR_OR_NULL(fwnode) && - !IS_ERR_OR_NULL(fwnode->secondary)) - ret = fwnode_call_int_op(fwnode->secondary, - property_read_string_array, propname, - val, nval); - return ret; + if (ret != -EINVAL) + return ret; + + return fwnode_call_int_op(fwnode->secondary, property_read_string_array, propname, + val, nval); } EXPORT_SYMBOL_GPL(fwnode_property_read_string_array); @@ -480,15 +485,19 @@ int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode, { int ret; + if (IS_ERR_OR_NULL(fwnode)) + return -ENOENT; + ret = fwnode_call_int_op(fwnode, get_reference_args, prop, nargs_prop, nargs, index, args); + if (ret == 0) + return ret; - if (ret < 0 && !IS_ERR_OR_NULL(fwnode) && - !IS_ERR_OR_NULL(fwnode->secondary)) - ret = fwnode_call_int_op(fwnode->secondary, get_reference_args, - prop, nargs_prop, nargs, index, args); + if (IS_ERR_OR_NULL(fwnode->secondary)) + return ret; - return ret; + return fwnode_call_int_op(fwnode->secondary, get_reference_args, prop, nargs_prop, + nargs, index, args); } EXPORT_SYMBOL_GPL(fwnode_property_get_reference_args); @@ -635,12 +644,13 @@ EXPORT_SYMBOL_GPL(fwnode_count_parents); struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwnode, unsigned int depth) { - unsigned int i; - fwnode_handle_get(fwnode); - for (i = 0; i < depth && fwnode; i++) + do { + if (depth-- == 0) + break; fwnode = fwnode_get_next_parent(fwnode); + } while (fwnode); return fwnode; } @@ -659,17 +669,17 @@ EXPORT_SYMBOL_GPL(fwnode_get_nth_parent); bool fwnode_is_ancestor_of(struct fwnode_handle *test_ancestor, struct fwnode_handle *test_child) { - if (!test_ancestor) + if (IS_ERR_OR_NULL(test_ancestor)) return false; fwnode_handle_get(test_child); - while (test_child) { + do { if (test_child == test_ancestor) { fwnode_handle_put(test_child); return true; } test_child = fwnode_get_next_parent(test_child); - } + } while (test_child); return false; } @@ -698,7 +708,7 @@ fwnode_get_next_available_child_node(const struct fwnode_handle *fwnode, { struct fwnode_handle *next_child = child; - if (!fwnode) + if (IS_ERR_OR_NULL(fwnode)) return NULL; do { @@ -722,16 +732,16 @@ struct fwnode_handle *device_get_next_child_node(struct device *dev, const struct fwnode_handle *fwnode = dev_fwnode(dev); struct fwnode_handle *next; + if (IS_ERR_OR_NULL(fwnode)) + return NULL; + /* Try to find a child in primary fwnode */ next = fwnode_get_next_child_node(fwnode, child); if (next) return next; /* When no more children in primary, continue with secondary */ - if (fwnode && !IS_ERR_OR_NULL(fwnode->secondary)) - next = fwnode_get_next_child_node(fwnode->secondary, child); - - return next; + return fwnode_get_next_child_node(fwnode->secondary, child); } EXPORT_SYMBOL_GPL(device_get_next_child_node); @@ -798,6 +808,9 @@ EXPORT_SYMBOL_GPL(fwnode_handle_put); */ bool fwnode_device_is_available(const struct fwnode_handle *fwnode) { + if (IS_ERR_OR_NULL(fwnode)) + return false; + if (!fwnode_has_op(fwnode, device_is_available)) return true; @@ -958,14 +971,14 @@ fwnode_graph_get_next_endpoint(const struct fwnode_handle *fwnode, parent = fwnode_graph_get_port_parent(prev); else parent = fwnode; + if (IS_ERR_OR_NULL(parent)) + return NULL; ep = fwnode_call_ptr_op(parent, graph_get_next_endpoint, prev); + if (ep) + return ep; - if (IS_ERR_OR_NULL(ep) && - !IS_ERR_OR_NULL(parent) && !IS_ERR_OR_NULL(parent->secondary)) - ep = fwnode_graph_get_next_endpoint(parent->secondary, NULL); - - return ep; + return fwnode_graph_get_next_endpoint(parent->secondary, NULL); } EXPORT_SYMBOL_GPL(fwnode_graph_get_next_endpoint); diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h index 6ab69871b06d..9a81c4410b9f 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -153,12 +153,12 @@ struct fwnode_operations { int (*add_links)(struct fwnode_handle *fwnode); }; -#define fwnode_has_op(fwnode, op) \ - ((fwnode) && (fwnode)->ops && (fwnode)->ops->op) +#define fwnode_has_op(fwnode, op) \ + (!IS_ERR_OR_NULL(fwnode) && (fwnode)->ops && (fwnode)->ops->op) + #define fwnode_call_int_op(fwnode, op, ...) \ - (fwnode ? (fwnode_has_op(fwnode, op) ? \ - (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \ - -EINVAL) + (fwnode_has_op(fwnode, op) ? \ + (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : (IS_ERR_OR_NULL(fwnode) ? -EINVAL : -ENXIO)) #define fwnode_call_bool_op(fwnode, op, ...) \ (fwnode_has_op(fwnode, op) ? \ From patchwork Fri Apr 8 18:48:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12807122 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E26FC4332F for ; Fri, 8 Apr 2022 18:49:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238993AbiDHSvq (ORCPT ); Fri, 8 Apr 2022 14:51:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238968AbiDHSvl (ORCPT ); Fri, 8 Apr 2022 14:51:41 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56BB51C7BB4; Fri, 8 Apr 2022 11:49:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649443777; x=1680979777; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=l8z8ftbks1EAwb7W96SGXJ+GE4XMqxepqwuGNCmGlpA=; b=C8scYBY8v/c43OMKZGlWwCSFgvsTwPzpbxalQyYhawuxRq5zjsdabrhj BWeN2yP0veQefdd+GJadijwMO1nU5fBPy1+wjtDym4WLqRqfyW/3DsCpI 1gGsYihaNxB5P7KvT1CDoV8vYTXmgyamDJ5g8Rhn39wPwmIJFdsVdoR7j 8B1M/2is1z/PhZ7MfkESmS8SbkbRksQVUVUaM4i5q7X+TCDdAV6mm6uJk uUBArkVZNGdG16d3RHhJLMKoFDbPNLsCGLPkXhkVUSTdLADmOjeFiXYz8 vWGO8A3oHHlGLvOSq+sTjKKK3o+375hrpiL5IToRb51rsg4y4D/296+ij g==; X-IronPort-AV: E=McAfee;i="6400,9594,10311"; a="241602056" X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="241602056" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2022 11:49:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="557883587" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 08 Apr 2022 11:49:31 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 3C321120; Fri, 8 Apr 2022 21:48:46 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Rob Herring , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Len Brown Subject: [PATCH v6 2/5] device property: Introduce fwnode_for_each_parent_node() Date: Fri, 8 Apr 2022 21:48:41 +0300 Message-Id: <20220408184844.22829-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220408184844.22829-1-andriy.shevchenko@linux.intel.com> References: <20220408184844.22829-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org In a few cases the functionality of fwnode_for_each_parent_node() is already in use. Introduce a common helper macro for it. It may be used by others as well in the future. Signed-off-by: Andy Shevchenko Reviewed-by: Sakari Ailus --- v6: added tag (Sakari) drivers/base/property.c | 56 +++++++++++++++++++++------------------- include/linux/property.h | 9 +++++-- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index 6ecc1398b0ba..f0ac31d28798 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -596,17 +596,17 @@ EXPORT_SYMBOL_GPL(fwnode_get_next_parent); */ struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode) { + struct fwnode_handle *parent; struct device *dev; - fwnode_handle_get(fwnode); - do { - fwnode = fwnode_get_next_parent(fwnode); - if (!fwnode) - return NULL; + fwnode_for_each_parent_node(fwnode, parent) { dev = get_dev_from_fwnode(fwnode); - } while (!dev); - fwnode_handle_put(fwnode); - return dev; + if (dev) { + fwnode_handle_put(parent); + return dev; + } + } + return NULL; } /** @@ -617,13 +617,11 @@ struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode) */ unsigned int fwnode_count_parents(const struct fwnode_handle *fwnode) { - struct fwnode_handle *__fwnode; - unsigned int count; - - __fwnode = fwnode_get_parent(fwnode); + struct fwnode_handle *parent; + unsigned int count = 0; - for (count = 0; __fwnode; count++) - __fwnode = fwnode_get_next_parent(__fwnode); + fwnode_for_each_parent_node(fwnode, parent) + count++; return count; } @@ -644,15 +642,16 @@ EXPORT_SYMBOL_GPL(fwnode_count_parents); struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwnode, unsigned int depth) { - fwnode_handle_get(fwnode); + struct fwnode_handle *parent; - do { - if (depth-- == 0) - break; - fwnode = fwnode_get_next_parent(fwnode); - } while (fwnode); + if (depth == 0) + return fwnode_handle_get(fwnode); - return fwnode; + fwnode_for_each_parent_node(fwnode, parent) { + if (--depth == 0) + return parent; + } + return NULL; } EXPORT_SYMBOL_GPL(fwnode_get_nth_parent); @@ -669,17 +668,20 @@ EXPORT_SYMBOL_GPL(fwnode_get_nth_parent); bool fwnode_is_ancestor_of(struct fwnode_handle *test_ancestor, struct fwnode_handle *test_child) { + struct fwnode_handle *parent; + if (IS_ERR_OR_NULL(test_ancestor)) return false; - fwnode_handle_get(test_child); - do { - if (test_child == test_ancestor) { - fwnode_handle_put(test_child); + if (test_child == test_ancestor) + return true; + + fwnode_for_each_parent_node(test_child, parent) { + if (parent == test_ancestor) { + fwnode_handle_put(parent); return true; } - test_child = fwnode_get_next_parent(test_child); - } while (test_child); + } return false; } diff --git a/include/linux/property.h b/include/linux/property.h index 4cd4b326941f..15d6863ae962 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -83,9 +83,14 @@ struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode, const char *fwnode_get_name(const struct fwnode_handle *fwnode); const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode); + struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode); -struct fwnode_handle *fwnode_get_next_parent( - struct fwnode_handle *fwnode); +struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode); + +#define fwnode_for_each_parent_node(fwnode, parent) \ + for (parent = fwnode_get_parent(fwnode); parent; \ + parent = fwnode_get_next_parent(parent)) + struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode); unsigned int fwnode_count_parents(const struct fwnode_handle *fwn); struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn, From patchwork Fri Apr 8 18:48:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12807121 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C69DFC433EF for ; Fri, 8 Apr 2022 18:49:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238982AbiDHSvp (ORCPT ); Fri, 8 Apr 2022 14:51:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231219AbiDHSvk (ORCPT ); Fri, 8 Apr 2022 14:51:40 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B1021CA392; Fri, 8 Apr 2022 11:49:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649443776; x=1680979776; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IOK0eBB42zfrFsk9z68bt/8zGkVc4UZHBRMEjnKHHS8=; b=eRvVZSrQa3sYARtU2XxDXzoaSXdA74GF0VxTfm2AykwDIH07lcNioMUE 53JP405zzMi5VWFKYx+UNL6GDarepkoFdcFeBaqz4ME3SA0LU36WQELvu G2yLypYFi4x6wMrwBfuIBbuMMZ2J6AKLU6kVUSUwuuTglNhMNIzwMzliX RDGFewDd5fO906D1lgB9/2oRlJ+rX7sjwRDS95MTjqTVopBTG6K4nkQHA MLnJtiQw+QCUB9ktt7q38xritZOTx54bok1B8TqxwHY+Iw4IHebtu+rQv Ub0AploKyKQV/+8X42wjGs2K4RI6m4zM6XyBNxz9W10qHKgJS8uccaPTq g==; X-IronPort-AV: E=McAfee;i="6400,9594,10311"; a="261841908" X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="261841908" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2022 11:49:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="524881630" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 08 Apr 2022 11:49:32 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 47FB318E; Fri, 8 Apr 2022 21:48:46 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Rob Herring , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Len Brown Subject: [PATCH v6 3/5] device property: Drop 'test' prefix in parameters of fwnode_is_ancestor_of() Date: Fri, 8 Apr 2022 21:48:42 +0300 Message-Id: <20220408184844.22829-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220408184844.22829-1-andriy.shevchenko@linux.intel.com> References: <20220408184844.22829-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The part 'is' in the function name implies the test against something. Drop unnecessary 'test' prefix in the fwnode_is_ancestor_of() parameters. No functional change intended. Signed-off-by: Andy Shevchenko Reviewed-by: Sakari Ailus --- v6: added tag (Sakari) drivers/base/property.c | 20 +++++++++----------- include/linux/property.h | 3 +-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index f0ac31d28798..36401cfe432c 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -656,28 +656,26 @@ struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwnode, EXPORT_SYMBOL_GPL(fwnode_get_nth_parent); /** - * fwnode_is_ancestor_of - Test if @test_ancestor is ancestor of @test_child - * @test_ancestor: Firmware which is tested for being an ancestor - * @test_child: Firmware which is tested for being the child + * fwnode_is_ancestor_of - Test if @ancestor is ancestor of @child + * @ancestor: Firmware which is tested for being an ancestor + * @child: Firmware which is tested for being the child * * A node is considered an ancestor of itself too. * - * Returns true if @test_ancestor is an ancestor of @test_child. - * Otherwise, returns false. + * Returns true if @ancestor is an ancestor of @child. Otherwise, returns false. */ -bool fwnode_is_ancestor_of(struct fwnode_handle *test_ancestor, - struct fwnode_handle *test_child) +bool fwnode_is_ancestor_of(struct fwnode_handle *ancestor, struct fwnode_handle *child) { struct fwnode_handle *parent; - if (IS_ERR_OR_NULL(test_ancestor)) + if (IS_ERR_OR_NULL(ancestor)) return false; - if (test_child == test_ancestor) + if (child == ancestor) return true; - fwnode_for_each_parent_node(test_child, parent) { - if (parent == test_ancestor) { + fwnode_for_each_parent_node(child, parent) { + if (parent == ancestor) { fwnode_handle_put(parent); return true; } diff --git a/include/linux/property.h b/include/linux/property.h index 15d6863ae962..fc24d45632eb 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -95,8 +95,7 @@ struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode); unsigned int fwnode_count_parents(const struct fwnode_handle *fwn); struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn, unsigned int depth); -bool fwnode_is_ancestor_of(struct fwnode_handle *test_ancestor, - struct fwnode_handle *test_child); +bool fwnode_is_ancestor_of(struct fwnode_handle *ancestor, struct fwnode_handle *child); struct fwnode_handle *fwnode_get_next_child_node( const struct fwnode_handle *fwnode, struct fwnode_handle *child); struct fwnode_handle *fwnode_get_next_available_child_node( From patchwork Fri Apr 8 18:48:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12807120 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E1C5C433F5 for ; Fri, 8 Apr 2022 18:49:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238976AbiDHSvn (ORCPT ); Fri, 8 Apr 2022 14:51:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234574AbiDHSvk (ORCPT ); Fri, 8 Apr 2022 14:51:40 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 506871CA385; Fri, 8 Apr 2022 11:49:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649443776; x=1680979776; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/L4XLibjcZhivIukWvKIpgtxKvWbpx+6gdYLGgMSaY8=; b=jZmWaEcjDVKhvg/++X+D/Xia3Zvz7HSMlUg2l8x6KZrV595E06JpGqOF eunmW0zDMNmw+jGOUF6b7BDbLEHN39wpfbpLoQP1/PGlq9CNsJVSablVA 7pBlVX2SQGTNuiD5sIGkQAlxqkh0SJxrjwp+v+r99iNGKp6IADNoZMldS 6Jb476GC2wXSVQm/eUB6qkZVlfAKR+xHhMGNmCkXnjj9GarSJ72MrWyql Q9sKQThQ/fBapchwKobQp2+2nnrG0u5yq8GWqVX2KuXkYFNJotUucHUEt MMgMnYeb25BqVgnq7+XLfjIMZUJXoMx9SAY33HThKPhdYh6eo9WpWOqVP Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10311"; a="242258599" X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="242258599" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2022 11:49:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="698279335" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 08 Apr 2022 11:49:32 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 4E763328; Fri, 8 Apr 2022 21:48:46 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Rob Herring , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Len Brown Subject: [PATCH v6 4/5] device property: Constify fwnode_handle_get() Date: Fri, 8 Apr 2022 21:48:43 +0300 Message-Id: <20220408184844.22829-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220408184844.22829-1-andriy.shevchenko@linux.intel.com> References: <20220408184844.22829-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org As to_of_node() suggests and the way the code in the OF and software node back ends actually uses the fwnode handle, it may be constified. Do this for good. Signed-off-by: Andy Shevchenko Reported-by: kernel test robot Reported-by: kernel test robot --- v6: new patch drivers/base/property.c | 2 +- drivers/base/swnode.c | 2 +- drivers/of/property.c | 2 +- include/linux/fwnode.h | 2 +- include/linux/property.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index 36401cfe432c..1ad4b37cd312 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -776,7 +776,7 @@ EXPORT_SYMBOL_GPL(device_get_named_child_node); * * Returns the fwnode handle. */ -struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode) +struct fwnode_handle *fwnode_handle_get(const struct fwnode_handle *fwnode) { if (!fwnode_has_op(fwnode, get)) return fwnode; diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index b0bbd1805970..84a11008ffb8 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -363,7 +363,7 @@ EXPORT_SYMBOL_GPL(property_entries_free); /* -------------------------------------------------------------------------- */ /* fwnode operations */ -static struct fwnode_handle *software_node_get(struct fwnode_handle *fwnode) +static struct fwnode_handle *software_node_get(const struct fwnode_handle *fwnode) { struct swnode *swnode = to_swnode(fwnode); diff --git a/drivers/of/property.c b/drivers/of/property.c index 9a50ad25906e..8d06282af8e4 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -858,7 +858,7 @@ struct device_node *of_graph_get_remote_node(const struct device_node *node, } EXPORT_SYMBOL(of_graph_get_remote_node); -static struct fwnode_handle *of_fwnode_get(struct fwnode_handle *fwnode) +static struct fwnode_handle *of_fwnode_get(const struct fwnode_handle *fwnode) { return of_fwnode_handle(of_node_get(to_of_node(fwnode))); } diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h index 9a81c4410b9f..a94bd47192a3 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -108,7 +108,7 @@ struct fwnode_reference_args { * zero on success, a negative error code otherwise. */ struct fwnode_operations { - struct fwnode_handle *(*get)(struct fwnode_handle *fwnode); + struct fwnode_handle *(*get)(const struct fwnode_handle *fwnode); void (*put)(struct fwnode_handle *fwnode); bool (*device_is_available)(const struct fwnode_handle *fwnode); const void *(*device_get_match_data)(const struct fwnode_handle *fwnode, diff --git a/include/linux/property.h b/include/linux/property.h index fc24d45632eb..c631ee7fd161 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -121,7 +121,7 @@ struct fwnode_handle *fwnode_get_named_child_node( struct fwnode_handle *device_get_named_child_node(struct device *dev, const char *childname); -struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode); +struct fwnode_handle *fwnode_handle_get(const struct fwnode_handle *fwnode); void fwnode_handle_put(struct fwnode_handle *fwnode); int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index); From patchwork Fri Apr 8 18:48:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12807119 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DCDDC433EF for ; Fri, 8 Apr 2022 18:49:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238971AbiDHSvm (ORCPT ); Fri, 8 Apr 2022 14:51:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238958AbiDHSvk (ORCPT ); Fri, 8 Apr 2022 14:51:40 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B4C81C9B5C; Fri, 8 Apr 2022 11:49:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649443775; x=1680979775; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MJFpHccOxFxoyHrddoOZl2W35Dl1fotu10a86Vp+YiQ=; b=RkGAViThbAlNmub91Fze1Vbp/vO8U+3RZcRQvSXMKKCcGWa5q0AYnv59 7n9JxtxpUWWaUxwEPYrRQNGuMwRpsiCjgI5V32r3gcySHFJe7dCYIM5zI KQ9t+28Au64lbhD8GnKzj2CxSFXTfjxwJOdBpfIMa2RXzCgBYnMn8kAbT 5pGJuieLU6zmGdoMuSjg/fFs4eJoSGt8K9HMMm9l/SNllIYfspN3Jmq8y Z6BevQy2TmWV5BIQ74G5KA/aHg35yvXniKwMfDOLp3W8pYgdHww30Auvb NAcOS0cBzNWz4CvTfuBUtHs53mWvAaTvi2EG6H1Z6R46Ja1M2WUedVi8x Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10311"; a="241602058" X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="241602058" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2022 11:49:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="557883589" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 08 Apr 2022 11:49:32 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 5F7B6449; Fri, 8 Apr 2022 21:48:46 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Rob Herring , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Len Brown Subject: [PATCH v6 5/5] device property: Constify fwnode APIs that uses fwnode_get_next_parent() Date: Fri, 8 Apr 2022 21:48:44 +0300 Message-Id: <20220408184844.22829-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220408184844.22829-1-andriy.shevchenko@linux.intel.com> References: <20220408184844.22829-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Due to fwnode_get_next_parent() used to be called against the parameters of some of fwnode APIs those parameters have no const qualifier. However, after switching to fwnode_for_each_parent_node() API now it's possible to constify the parameters. Do it for good. The affected functions are: fwnode_get_next_parent_dev() fwnode_get_nth_parent() fwnode_is_ancestor_of() Signed-off-by: Andy Shevchenko Reviewed-by: Sakari Ailus --- v6: added tag (Sakari), since previous patch no warnings anymore (LKP) drivers/base/property.c | 7 +++---- include/linux/property.h | 9 ++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index 1ad4b37cd312..f289f582209c 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -594,7 +594,7 @@ EXPORT_SYMBOL_GPL(fwnode_get_next_parent); * The caller of this function is expected to call put_device() on the returned * device when they are done. */ -struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode) +struct device *fwnode_get_next_parent_dev(const struct fwnode_handle *fwnode) { struct fwnode_handle *parent; struct device *dev; @@ -639,8 +639,7 @@ EXPORT_SYMBOL_GPL(fwnode_count_parents); * The caller is responsible for calling fwnode_handle_put() for the returned * node. */ -struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwnode, - unsigned int depth) +struct fwnode_handle *fwnode_get_nth_parent(const struct fwnode_handle *fwnode, unsigned int depth) { struct fwnode_handle *parent; @@ -664,7 +663,7 @@ EXPORT_SYMBOL_GPL(fwnode_get_nth_parent); * * Returns true if @ancestor is an ancestor of @child. Otherwise, returns false. */ -bool fwnode_is_ancestor_of(struct fwnode_handle *ancestor, struct fwnode_handle *child) +bool fwnode_is_ancestor_of(const struct fwnode_handle *ancestor, const struct fwnode_handle *child) { struct fwnode_handle *parent; diff --git a/include/linux/property.h b/include/linux/property.h index c631ee7fd161..e3390401dd63 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -91,11 +91,10 @@ struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode); for (parent = fwnode_get_parent(fwnode); parent; \ parent = fwnode_get_next_parent(parent)) -struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode); -unsigned int fwnode_count_parents(const struct fwnode_handle *fwn); -struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn, - unsigned int depth); -bool fwnode_is_ancestor_of(struct fwnode_handle *ancestor, struct fwnode_handle *child); +struct device *fwnode_get_next_parent_dev(const struct fwnode_handle *fwnode); +unsigned int fwnode_count_parents(const struct fwnode_handle *fwnode); +struct fwnode_handle *fwnode_get_nth_parent(const struct fwnode_handle *fwnode, unsigned int depth); +bool fwnode_is_ancestor_of(const struct fwnode_handle *ancestor, const struct fwnode_handle *child); struct fwnode_handle *fwnode_get_next_child_node( const struct fwnode_handle *fwnode, struct fwnode_handle *child); struct fwnode_handle *fwnode_get_next_available_child_node(