From patchwork Sun Feb 25 14:27:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13570834 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3576214280; Sun, 25 Feb 2024 14:27:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708871258; cv=none; b=lozC34kN4ME3mu4ouBayGd626KnOKvMHV4Fa0TO6pt9J9KSiQpMF6LUK/6CZa+6usaDdbrE58kHngL04QJ5Lfc4YpSfW+YAVSQTE8Z54VXhMkbb5VuBoi46WRX99s3cJp1Mvyipi86e0FF7jOEqwcULPV19wdBcqjTG1RfgAu4A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708871258; c=relaxed/simple; bh=HAT98xnSwLDAnpvodaMTdqxT64M67j1g0X6shQNezLg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZF7olYEI7dZiRzbO+QRdpI38BN+HZAemE+yOgfgHpxXcLaC2P05xst2MD8ed4VTYC5sNuJSBoxF3bCv6A9V3ZpUxVsSk4AQdrjQYFUfSpDlLS6eNRkvmyuOZmIDsrG66wc61hubUO2vng1l0FcZZyuO9wmB3ewV7/7oiGjXQsuY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EIbuUKf4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EIbuUKf4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53840C43390; Sun, 25 Feb 2024 14:27:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708871257; bh=HAT98xnSwLDAnpvodaMTdqxT64M67j1g0X6shQNezLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EIbuUKf4y/pyYsjG9hm5YQtRuJ+jRGEDKz0LyJSGSgCYl7GMGtEKsNgSvlyhPE7VT gjg1AGMvcM9tkJTDSjtJAaRWLUDHJe7+eRIYtGe1/Ba3DzDztt0FUjxFuEnGDzHBRo ckofUhmRYZQY9angGKOPvspLMtrocVDHCl4KRa9sojUOn/oYbzZYRp4JoIvPzmhTR8 E2Z5Rwfu+oQi26eKAo2/Iw1g/jI/MBDZfnWpFBJ3nt1LExcck6xa3oTZGSBPuAgfgb UQsCsHrT1UysEFxyvUxOIZUtZo5t/vcli98lJY22HTRLk8CPVt2cv3++RInceSR4S2 jFYjQ75vN5zsQ== From: Jonathan Cameron To: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org, Julia Lawall Cc: Peter Zijlstra , Andy Shevchenko , Greg Kroah-Hartman , marek.vasut@gmail.com, Jonathan Cameron Subject: [RESEND PATCH v2 1/4] of: Add cleanup.h based auto release via __free(device_node) markings. Date: Sun, 25 Feb 2024 14:27:11 +0000 Message-ID: <20240225142714.286440-2-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240225142714.286440-1-jic23@kernel.org> References: <20240225142714.286440-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron The recent addition of scope based cleanup support to the kernel provides a convenient tool to reduce the chances of leaking reference counts where of_node_put() should have been called in an error path. This enables struct device_node *child __free(device_node) = NULL; for_each_child_of_node(np, child) { if (test) return test; } with no need for a manual call of of_node_put(). A following patch will reduce the scope of the child variable to the for loop, to avoid an issues with ordering of autocleanup, and make it obvious when this assigned a non NULL value. In this simple example the gains are small but there are some very complex error handling cases buried in these loops that will be greatly simplified by enabling early returns with out the need for this manual of_node_put() call. Note that there are coccinelle checks in scripts/coccinelle/iterators/for_each_child.cocci to detect a failure to call of_node_put(). This new approach does not cause false positives. Longer term we may want to add scripting to check this new approach is done correctly with no double of_node_put() calls being introduced due to the auto cleanup. It may also be useful to script finding places this new approach is useful. Signed-off-by: Jonathan Cameron --- include/linux/of.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/of.h b/include/linux/of.h index 6a9ddf20e79a..50e882ee91da 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -13,6 +13,7 @@ */ #include #include +#include #include #include #include @@ -134,6 +135,7 @@ static inline struct device_node *of_node_get(struct device_node *node) } static inline void of_node_put(struct device_node *node) { } #endif /* !CONFIG_OF_DYNAMIC */ +DEFINE_FREE(device_node, struct device_node *, if (_T) of_node_put(_T)) /* Pointer for first entry in chain of all nodes. */ extern struct device_node *of_root; From patchwork Sun Feb 25 14:27:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13570835 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D925014F62; Sun, 25 Feb 2024 14:27:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708871263; cv=none; b=NLbmsoUOrIEZo/QR1aKKc76EmC0AQm6OYzgYukF9iohH/EoYejEp+KO+Ha9E6g5piCUb1n8GMA4rXDkl5724x2dHhe+0/v0+oJQ9yYDlEQxWVETYSTMwyVkslq24GZaBNVX+37qBvkzOOGxFBOinlLJDrZkHLgaiNfcyNfcDHj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708871263; c=relaxed/simple; bh=JrxvOnnekqmZH3ajB2UIPWqOc4Gn4lKhT3b0ty+A5S8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qvYh1AIEtKpQ2M96CL9WsWhrkAc2Odn5l+luXWzwbTjWr4Q5dCxT0QI06qc4QLBR5UHluotnyw03v8578vrv0amNY8z8yTKfFL632Poztj7KR96dMeXQFQ/3fdQNyfLme9mA/SNH2tlKqKe/XDA+XI3HHL7Oy2YWs8BfU0JZycI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ICAhHYMD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ICAhHYMD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5430CC43394; Sun, 25 Feb 2024 14:27:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708871262; bh=JrxvOnnekqmZH3ajB2UIPWqOc4Gn4lKhT3b0ty+A5S8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ICAhHYMDXJlaFwdl0M9SxF2WSfiL+8mnR/YOiI670MrkWnJY7o5CdDZ8EyAfWy8Yw zJ7Qyvnvsiiw6YrMRN9e5rVbq9TFAmAWcOCH84LPhQtqHrC3IOgg5F5AAFcnTcNvQB WvXiIC1wkr/40zKn8zihJf3wEhhwxje2gjXvAogBPkSCuhcTDSyEA/M5xkrcw4SrDO sNAhlIrAaD5ItV5GP34OJQD1Hg3dP4d/NVw0HDi0DMM/RD/iY8DIMHmGjSyPhuobX4 iuyEu9+QMvwIxDKdjLtK42XAsISWGfn60HEI8Jn9N5Y+nZ/f1fwwurTEfALt1JwOSM G7lvr6gZ51kyQ== From: Jonathan Cameron To: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org, Julia Lawall Cc: Peter Zijlstra , Andy Shevchenko , Greg Kroah-Hartman , marek.vasut@gmail.com, Jonathan Cameron Subject: [RESEND PATCH v2 2/4] of: Introduce for_each_*_child_of_node_scoped() to automate of_node_put() handling Date: Sun, 25 Feb 2024 14:27:12 +0000 Message-ID: <20240225142714.286440-3-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240225142714.286440-1-jic23@kernel.org> References: <20240225142714.286440-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron To avoid issues with out of order cleanup, or ambiguity about when the auto freed data is first instantiated, do it within the for loop definition. The disadvantage is that the struct device_node *child variable creation is not immediately obvious where this is used. However, in many cases, if there is another definition of struct device_node *child; the compiler / static analysers will notify us that it is unused, or uninitialized. Note that, in the vast majority of cases, the _available_ form should be used and as code is converted to these scoped handers, we should confirm that any cases that do not check for available have a good reason not to. Signed-off-by: Jonathan Cameron --- include/linux/of.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/of.h b/include/linux/of.h index 50e882ee91da..024dda54b9c7 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1430,10 +1430,23 @@ static inline int of_property_read_s32(const struct device_node *np, #define for_each_child_of_node(parent, child) \ for (child = of_get_next_child(parent, NULL); child != NULL; \ child = of_get_next_child(parent, child)) + +#define for_each_child_of_node_scoped(parent, child) \ + for (struct device_node *child __free(device_node) = \ + of_get_next_child(parent, NULL); \ + child != NULL; \ + child = of_get_next_child(parent, child)) + #define for_each_available_child_of_node(parent, child) \ for (child = of_get_next_available_child(parent, NULL); child != NULL; \ child = of_get_next_available_child(parent, child)) +#define for_each_available_child_of_node_scoped(parent, child) \ + for (struct device_node *child __free(device_node) = \ + of_get_next_available_child(parent, NULL); \ + child != NULL; \ + child = of_get_next_available_child(parent, child)) + #define for_each_of_cpu_node(cpu) \ for (cpu = of_get_next_cpu_node(NULL); cpu != NULL; \ cpu = of_get_next_cpu_node(cpu)) From patchwork Sun Feb 25 14:27:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13570836 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E923317579; Sun, 25 Feb 2024 14:27:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708871267; cv=none; b=i/FW5lnaTLVaea9twjxeIvTOFFHpz9d2ZRc6PPewC+pAG5hp3Ps4TNoJf5z8H9CU+c8m/a9tgzwjmXUnINCI5ejPscxKSLgI/cqDTa2fcMDwk4vWrA1wAIKDoFI5WbN/0L60mLumH+U88W1JuFf/zt6ZTIOFP++HeqH2OxLZTsU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708871267; c=relaxed/simple; bh=cy3xgv+zOTeCfTawrekO50j/BQnaTUqEu6LMlwDPXkg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sthZvdpeyNhFLDh8vQdyv/tuAg31UxW2A+ZMDg7qBiOvxX9KtjHG8Zr48viSz9lKbcgjzPBuK2CT1gO9Lr1RPQZzr6gC8rZNTFZ5JcNn9gXmscFzlpvWTalOyThqwhxdewIJAmhNBxA1nkBl3lo99I0S4EfcVh4mbPkx6w9mbKI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DihQqm1c; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DihQqm1c" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4E28C433F1; Sun, 25 Feb 2024 14:27:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708871266; bh=cy3xgv+zOTeCfTawrekO50j/BQnaTUqEu6LMlwDPXkg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DihQqm1cO4S4hEX3mO7srDwzf8AMPmNm9EXTEwCUb5Ft61bHiQ/1Ti6VC3WR4TSt0 C2VD+yTN7u2+bDQISJ+ctCCUE/NkwCiU0/44ISX3U/OQjEK9Oy0LczGoor0eHlMCf+ lU8DVnp61JzDLpAIiUV6x51vVmXtjtRVKMxci84kwkJ4f9vYDLyiuiPzMeRjaXH/9O BGmTIx5qtzD9+05iKnUJKA/fCGOcYlo3JMAc5hjfITNSRzZnZGz3dr649kKpmSKkeB kwSNQp00qkqbm8g+kaVgvvk5KInutdjD7x67aAoUKdFq/qY1pz9FYHXqOyCNH7A2im 907Ychz4iLJIw== From: Jonathan Cameron To: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org, Julia Lawall Cc: Peter Zijlstra , Andy Shevchenko , Greg Kroah-Hartman , marek.vasut@gmail.com, Jonathan Cameron Subject: [RESEND PATCH v2 3/4] of: unittest: Use for_each_child_of_node_scoped() Date: Sun, 25 Feb 2024 14:27:13 +0000 Message-ID: <20240225142714.286440-4-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240225142714.286440-1-jic23@kernel.org> References: <20240225142714.286440-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron A simple example of the utility of this autocleanup approach to handling of_node_put(). In this particular case some of the nodes needed for the test are not available and the _available_ version would cause them to be skipped resulting in a test failure. Signed-off-by: Jonathan Cameron --- drivers/of/unittest.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index cfd60e35a899..d353327767b3 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -233,27 +233,22 @@ static void __init of_unittest_dynamic(void) static int __init of_unittest_check_node_linkage(struct device_node *np) { - struct device_node *child; int count = 0, rc; - for_each_child_of_node(np, child) { + for_each_child_of_node_scoped(np, child) { if (child->parent != np) { pr_err("Child node %pOFn links to wrong parent %pOFn\n", child, np); - rc = -EINVAL; - goto put_child; + return -EINVAL; } rc = of_unittest_check_node_linkage(child); if (rc < 0) - goto put_child; + return rc; count += rc; } return count + 1; -put_child: - of_node_put(child); - return rc; } static void __init of_unittest_check_tree_linkage(void) From patchwork Sun Feb 25 14:27:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13570837 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3F28175BC; Sun, 25 Feb 2024 14:27:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708871270; cv=none; b=V/wvoRqQFmDx5AObb9c4qyzNQRqfO8R21AgaOr/u47+sYOtoZuX0Ab6cz8uhU++7nLImGzVMzUVC9LXEhOh1TQ6Whv3nRIbriyw4nG2OXdyaU9vJNRTy+wZVSukzQNm/8P9jtg0651Xj2BxIPUNFrlzbbeJM5f78ty9QVteWhWA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708871270; c=relaxed/simple; bh=FqXiRDMNp8tTGWD6g9YkejKEc8q+OEjl8zHNs3d6IoU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t+Znc4WrOrXb+TpUt4VmTXVoPwRTivwW5hJo9iFzd2QeaPn7QEFgGVnLvu9PCXqHEyyYHtP3fGXtzQ9+Bwzjki8J69v+XJ1zI9WQZn7Mt64+/SdRHKKL7XtOY2yUoUHHyA6kCgDlZFs58VJ0cxkn4BUBmTCIA5meTSCYf5hTTwU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=re8r5oJN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="re8r5oJN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FF42C433F1; Sun, 25 Feb 2024 14:27:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708871270; bh=FqXiRDMNp8tTGWD6g9YkejKEc8q+OEjl8zHNs3d6IoU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=re8r5oJNr4bsZl9Uw7G61ebplfEtdtt99hYivWytcHnU04kO99xj0WMHxrr6reaFv nmDN0hWSpVR3FW+1A3imLl4aL7lI9OdFIWZPtsPVQnqcZj7eELmv7RbgONjjUeKeW8 oHNIA7iaFJErWJHuRbNk36FTkOw2KSA3ROxaY9dpMXjtfzs1v6HkU9BCdMt/cCLIXH vcr2/C3NipA+0mWwJDzi83LhQl6qrR5e8vZ5Yh5fuJkbnOILEAdiqAY3ZdfTgeJveu Bxgz2JkCa10NJrvF+vbUUh7WMNj+5n5mSBvLe4OBmWMmdTuDefB8qyQT9MOYpY57mv eRdrY2HvYL8cw== From: Jonathan Cameron To: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org, Julia Lawall Cc: Peter Zijlstra , Andy Shevchenko , Greg Kroah-Hartman , marek.vasut@gmail.com, Jonathan Cameron Subject: [RESEND PATCH v2 4/4] iio: adc: rcar-gyroadc: use for_each_available_child_node_scoped() Date: Sun, 25 Feb 2024 14:27:14 +0000 Message-ID: <20240225142714.286440-5-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240225142714.286440-1-jic23@kernel.org> References: <20240225142714.286440-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Using automated cleanup to replace of_node_put() handling allows for a simplfied flow by enabling direct returns on errors. Non available child nodes should never have been considered; that is ones where status != okay and was defined. Signed-off-by: Jonathan Cameron --- drivers/iio/adc/rcar-gyroadc.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/drivers/iio/adc/rcar-gyroadc.c b/drivers/iio/adc/rcar-gyroadc.c index d524f2e8e927..15a21d2860e7 100644 --- a/drivers/iio/adc/rcar-gyroadc.c +++ b/drivers/iio/adc/rcar-gyroadc.c @@ -318,7 +318,6 @@ static int rcar_gyroadc_parse_subdevs(struct iio_dev *indio_dev) struct rcar_gyroadc *priv = iio_priv(indio_dev); struct device *dev = priv->dev; struct device_node *np = dev->of_node; - struct device_node *child; struct regulator *vref; unsigned int reg; unsigned int adcmode = -1, childmode; @@ -326,7 +325,7 @@ static int rcar_gyroadc_parse_subdevs(struct iio_dev *indio_dev) unsigned int num_channels; int ret, first = 1; - for_each_child_of_node(np, child) { + for_each_available_child_of_node_scoped(np, child) { of_id = of_match_node(rcar_gyroadc_child_match, child); if (!of_id) { dev_err(dev, "Ignoring unsupported ADC \"%pOFn\".", @@ -352,7 +351,7 @@ static int rcar_gyroadc_parse_subdevs(struct iio_dev *indio_dev) num_channels = ARRAY_SIZE(rcar_gyroadc_iio_channels_3); break; default: - goto err_e_inval; + return -EINVAL; } /* @@ -369,7 +368,7 @@ static int rcar_gyroadc_parse_subdevs(struct iio_dev *indio_dev) dev_err(dev, "Failed to get child reg property of ADC \"%pOFn\".\n", child); - goto err_of_node_put; + return ret; } /* Channel number is too high. */ @@ -377,7 +376,7 @@ static int rcar_gyroadc_parse_subdevs(struct iio_dev *indio_dev) dev_err(dev, "Only %i channels supported with %pOFn, but reg = <%i>.\n", num_channels, child, reg); - goto err_e_inval; + return -EINVAL; } } @@ -386,7 +385,7 @@ static int rcar_gyroadc_parse_subdevs(struct iio_dev *indio_dev) dev_err(dev, "Channel %i uses different ADC mode than the rest.\n", reg); - goto err_e_inval; + return -EINVAL; } /* Channel is valid, grab the regulator. */ @@ -396,8 +395,7 @@ static int rcar_gyroadc_parse_subdevs(struct iio_dev *indio_dev) if (IS_ERR(vref)) { dev_dbg(dev, "Channel %i 'vref' supply not connected.\n", reg); - ret = PTR_ERR(vref); - goto err_of_node_put; + return PTR_ERR(vref); } priv->vref[reg] = vref; @@ -422,7 +420,6 @@ static int rcar_gyroadc_parse_subdevs(struct iio_dev *indio_dev) * we can stop parsing here. */ if (childmode == RCAR_GYROADC_MODE_SELECT_1_MB88101A) { - of_node_put(child); break; } } @@ -433,12 +430,6 @@ static int rcar_gyroadc_parse_subdevs(struct iio_dev *indio_dev) } return 0; - -err_e_inval: - ret = -EINVAL; -err_of_node_put: - of_node_put(child); - return ret; } static void rcar_gyroadc_deinit_supplies(struct iio_dev *indio_dev)