From patchwork Sun Jan 28 16:05:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 767250 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 338CF2C850; Sun, 28 Jan 2024 16:06:08 +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=1706457969; cv=none; b=R/ihIY1Tr94nNWDcm6pypm3nQbF03n0u+zaw2qZ8c71pqEXJmyUOmHVp53LKVG78gL5Uimg6zL0IHWACGJ/kXpDbTtrodP33TGwn6xwmOJASFipID3kxVybaytVu7lIItBQ/SOJMltkoCnPrZnt88tLGWv3+xVKLbt7RWdyXxgw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706457969; c=relaxed/simple; bh=yeij2zd0BfAatAVK4xbn+gh4HqFxqVbeELw/h09d40M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=itT9UpRPTikvLRkXfQGUIMe1TTTqYLvYgRhTnwr2gZgB9yK2whr07cC4bE0puKsbHDasnWW8nq3D7rOQQv4K2r1mN85cfqOa2I9THbfMGF0tCnLMZuiGam7XoJG1fRQEN2KWds8kUTiZCGChkCFy6vaLqb2zcvEPfNZaYz6ygCg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jb2HZ1kE; 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="jb2HZ1kE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A14FBC433C7; Sun, 28 Jan 2024 16:06:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706457968; bh=yeij2zd0BfAatAVK4xbn+gh4HqFxqVbeELw/h09d40M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jb2HZ1kEkbL0DLPQcYUxBWFWA7qb8nt71qZmUTAr5BnSXXpsHKdsiClKo21MNV6RI bBUGqmXuF6hfD06WHH9DiGveI40ItBUmgxLczStwAVBciTKvjJ9Gglrkki2xCkcmh7 fvl9qg9PolIQflEtnDyLyheTTTBWPJVeNa/Z0gzoC6+BhAiSmF1vI2fQjNhvU61gVy OqA8fRmohjQxuB/C5hknO1wWRPvUT39YxvAycjzTrzJaiS9li3WvEF4Dad+UOI81Wx UMXRWSu46uoMJdmr5u6S6dk5ZMUIDNmpfwPWkJVMUABsg/mh4u64103CkX8UBYq5MK cmJYh1bVV6oUg== From: Jonathan Cameron To: linux-iio@vger.kernel.org, Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org Cc: Julia Lawall , Nicolas Palix , Sumera Priyadarsini , "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , =?utf-8?q?Nuno_S=C3=A1?= , Jonathan Cameron Subject: [RFC PATCH 1/5] of: Add cleanup.h based auto release via __free(device_node) markings. Date: Sun, 28 Jan 2024 16:05:38 +0000 Message-ID: <20240128160542.178315-2-jic23@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240128160542.178315-1-jic23@kernel.org> References: <20240128160542.178315-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@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 Jan 28 16:05:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 768891 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 B37B32E644; Sun, 28 Jan 2024 16:06:12 +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=1706457972; cv=none; b=mDe7Fm+MLDygoinMqoVydFBKYTa6dheuWwcmjK1vTmPM9UGgATITtsI1WXReLppsRNDloZALV+Eaep2NFBokCIeGWZZdkN19iTPOlRUGwCkLvHDqgxnJDzhSw18MxpUX4qdPKsYJq3NzFMUb+2AJ24qdjmsHcO1L2/pwzCQUkXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706457972; c=relaxed/simple; bh=1UnqaSq6US/sXw4AotStqr/RUKhvvYzhNHwicWeq4pM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M3N3Bz+2ouBQ++XLHf2K7A0Sx7SLmii5qKHjPOC19xRIGB4wHf47vTnzKkWU8ZrUrHQKKayRLGLYFsbCxd/fpxXINihazidr3/J10Ui+a6uFDyMBwO55O85Bl3N5C7ozb7SdcW3/aelpDDn1AKKUh/KLlXZ7m4L8+8yeeWf26i0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qfMWcqXQ; 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="qfMWcqXQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BA3CC43394; Sun, 28 Jan 2024 16:06:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706457972; bh=1UnqaSq6US/sXw4AotStqr/RUKhvvYzhNHwicWeq4pM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qfMWcqXQJuyNNX7HTwLclM8TLDtUP6uRfAE1TNMORFXG8gztAiXwty3tUBRAD6G2w 1UEZwjtVgOM+bZFNxdcukilsqEA6dzQ+Qq70YCR/Ze57qbGW10O/CkLpgbP65ElTaC dDwM85Z+swUBxO5/RquDc23ErRWPiFKm3njXeRm8YNbQcN4Foi7Bg275xOCzOE+/me MX3NURYzHj/GYCcWB5bRqzifBc80oe7k84cb5kX8pdLuXgaR+KdC8Yq9yX2WIY1QvA lzaJUBfoTwrHZKwVCAOVVELKTozQl8zKw2kV4rKZWvgZ9NS9zM1Cnda79ZcqPjLOLZ V3O5iVUHsBbBQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org, Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org Cc: Julia Lawall , Nicolas Palix , Sumera Priyadarsini , "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , =?utf-8?q?Nuno_S=C3=A1?= , Jonathan Cameron Subject: [RFC PATCH 2/5] of: Introduce for_each_child_of_node_scoped() to automate of_node_put() handling Date: Sun, 28 Jan 2024 16:05:39 +0000 Message-ID: <20240128160542.178315-3-jic23@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240128160542.178315-1-jic23@kernel.org> References: <20240128160542.178315-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@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. Signed-off-by: Jonathan Cameron --- include/linux/of.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/linux/of.h b/include/linux/of.h index 50e882ee91da..f822226eac6d 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1434,6 +1434,12 @@ static inline int of_property_read_s32(const struct device_node *np, for (child = of_get_next_available_child(parent, NULL); child != NULL; \ child = of_get_next_available_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_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 Jan 28 16:05:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 767249 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 98F7F2EB1D; Sun, 28 Jan 2024 16:06:16 +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=1706457976; cv=none; b=jZv8d6tAm1eeznrd/QFU5y2+u8Ha2/5rtOnoXlUCymcjM9VIpFCSB/OENeOtcsFf8F34nC6iPb+dVUCi1x1B/cVqI4s9gKWM3EmBxKNvW7JqIAaqUj4WUoPpETk2YT52B0gC7pipU65ke9T7lyc8cp4rqYOx9rrjWpAAQfSJGKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706457976; c=relaxed/simple; bh=tUG4O+PgRfdAjKLE8Z/uNA5hf36Y7t+Ym1/UMNDsPG8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lx9M6dpqQf0KrFZDD01k5/l7qDzA+Xj0ekaDiUCSUyA0VUlSUSLcviG0Aho9vyAGS4qA9JBb7UT0vlZdfaZn/Whs2qptOpHLGqrN0++np5f7eseVI1e8gxQkmLXbaRcbKGvVeM0FkA8UJtgaPglMQdE7uy7VL7yKrW/0tOUplZo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BThAZpoj; 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="BThAZpoj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B20E4C43390; Sun, 28 Jan 2024 16:06:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706457976; bh=tUG4O+PgRfdAjKLE8Z/uNA5hf36Y7t+Ym1/UMNDsPG8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BThAZpojLE/4qW5yzHzRBtAaQ7rhFO+NUqYv44ES20PUvjB5NGz6RUOcWp2AZpJEi qh6gbkaCh1mhTHsXgcs6vFa9oIhl1NsB06Eo1RZMKuqES4qwTMgF4hJiAXNNX17XBG /FwgagQbrKgDiZaSaWoh5tsP+QZrOF+PssTTauB1B3OpK1a46p64iYEx+9Mv5BA0dp G4kV060SGIsaS6iCxRHsIPpPDahgWoLz9ro9uK5yiWO/NT22nOlDSabvhRobvlUrKm op9U9XtMFY79DF6z+ETw+paZ9C435G9B4tLCHCIcUB9HaAEEx4qo4edkoX2GrHqrPV gTQ5BaBELC9Xw== From: Jonathan Cameron To: linux-iio@vger.kernel.org, Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org Cc: Julia Lawall , Nicolas Palix , Sumera Priyadarsini , "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , =?utf-8?q?Nuno_S=C3=A1?= , Jonathan Cameron Subject: [RFC PATCH 3/5] of: unittest: Use for_each_child_of_node_scoped() Date: Sun, 28 Jan 2024 16:05:40 +0000 Message-ID: <20240128160542.178315-4-jic23@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240128160542.178315-1-jic23@kernel.org> References: <20240128160542.178315-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@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() 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 Jan 28 16:05:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 768890 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 9EA473309E; Sun, 28 Jan 2024 16:06:20 +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=1706457980; cv=none; b=AAkQVW+YHTF/0zMMX71ZlH0FPEvJD3JXxePoFHVENFtEEW/sHiSTnJsUK9pdzv/RTSB1VXGuZboyci+pCvDZnuZnRhDA/5w5Zvr2PSqIewvBUi20vMQzjSLYHiphKjvk2tCKGK1DtFPs3mkncCkxdcN05f3LSZzxHNR86u+DvvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706457980; c=relaxed/simple; bh=3Y2fe3v8fv82hwf99UNXqMFEmGi13fJAOCRcMqRzjNo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WobBNEGHV1IOr+g4gwaul/8IBQdZJoylYCvkIZy4IohsgZzUZTRRpHKfmU76nmKj4IG9bfEwwdV8B8dq5dPkePQ0XrfipblAGJEo0syNbVmgJFyhreId6JUFf4m+Q/SrbCou6H81+7k80h1zef8XWwPKW6c0KNXmZUs5SpfbZsE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GoKDwMYn; 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="GoKDwMYn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8E4BC433C7; Sun, 28 Jan 2024 16:06:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706457980; bh=3Y2fe3v8fv82hwf99UNXqMFEmGi13fJAOCRcMqRzjNo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GoKDwMYnAXOfasnL3LeIKIDEOWP6iyLwq8T9d/vWS6mJbW9e0+clKEKjA5ABmYH69 77eaTotsqCzTnCeYZi+Xw1prbYTMHefffIafgAldZebhIP+UJKhIS8/4OY+Ujc5bzS dy304O/kjet2Jo7yGKkV4bR74zCHfIw/shk/fsoJefmcY6NJwpNw0oz3JhwFOEDdwr 956TCOy7YdIWLpVWYMx3x3rrXsy7PNfo0pSuOCcyikmh0K6N5GAtzo66JNsF+IS1h7 5n0ms4sVAqt34SGwjHuDlm1brtUYDrAhRCob1k87BkSLnI+SfWVYX0ocKhMmvjJ+ua JtCt8FTdUGfVA== From: Jonathan Cameron To: linux-iio@vger.kernel.org, Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org Cc: Julia Lawall , Nicolas Palix , Sumera Priyadarsini , "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , =?utf-8?q?Nuno_S=C3=A1?= , Jonathan Cameron Subject: [RFC PATCH 4/5] iio: adc: fsl-imx25-gcq: Use for_each_child_node_scoped() Date: Sun, 28 Jan 2024 16:05:41 +0000 Message-ID: <20240128160542.178315-5-jic23@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240128160542.178315-1-jic23@kernel.org> References: <20240128160542.178315-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Using automated cleanup reduces chance of an reference count leak and simplfies the code. Signed-off-by: Jonathan Cameron --- Chances since v1: Use new for_each_child_node_scoped() --- drivers/iio/adc/fsl-imx25-gcq.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/drivers/iio/adc/fsl-imx25-gcq.c b/drivers/iio/adc/fsl-imx25-gcq.c index 68c813de0605..a32b5f68768e 100644 --- a/drivers/iio/adc/fsl-imx25-gcq.c +++ b/drivers/iio/adc/fsl-imx25-gcq.c @@ -199,7 +199,6 @@ static int mx25_gcq_setup_cfgs(struct platform_device *pdev, struct mx25_gcq_priv *priv) { struct device_node *np = pdev->dev.of_node; - struct device_node *child; struct device *dev = &pdev->dev; int ret, i; @@ -216,7 +215,7 @@ static int mx25_gcq_setup_cfgs(struct platform_device *pdev, MX25_ADCQ_CFG_IN(i) | MX25_ADCQ_CFG_REFN_NGND2); - for_each_child_of_node(np, child) { + for_each_child_of_node_scoped(np, child) { u32 reg; u32 refp = MX25_ADCQ_CFG_REFP_INT; u32 refn = MX25_ADCQ_CFG_REFN_NGND2; @@ -224,14 +223,12 @@ static int mx25_gcq_setup_cfgs(struct platform_device *pdev, ret = of_property_read_u32(child, "reg", ®); if (ret) { dev_err(dev, "Failed to get reg property\n"); - of_node_put(child); return ret; } if (reg >= MX25_NUM_CFGS) { dev_err(dev, "reg value is greater than the number of available configuration registers\n"); - of_node_put(child); return -EINVAL; } @@ -243,10 +240,9 @@ static int mx25_gcq_setup_cfgs(struct platform_device *pdev, case MX25_ADC_REFP_XP: case MX25_ADC_REFP_YP: ret = mx25_gcq_ext_regulator_setup(&pdev->dev, priv, refp); - if (ret) { - of_node_put(child); + if (ret) return ret; - } + priv->channel_vref_mv[reg] = regulator_get_voltage(priv->vref[refp]); /* Conversion from uV to mV */ @@ -257,7 +253,6 @@ static int mx25_gcq_setup_cfgs(struct platform_device *pdev, break; default: dev_err(dev, "Invalid positive reference %d\n", refp); - of_node_put(child); return -EINVAL; } @@ -270,12 +265,10 @@ static int mx25_gcq_setup_cfgs(struct platform_device *pdev, if ((refp & MX25_ADCQ_CFG_REFP_MASK) != refp) { dev_err(dev, "Invalid fsl,adc-refp property value\n"); - of_node_put(child); return -EINVAL; } if ((refn & MX25_ADCQ_CFG_REFN_MASK) != refn) { dev_err(dev, "Invalid fsl,adc-refn property value\n"); - of_node_put(child); return -EINVAL; } From patchwork Sun Jan 28 16:05:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 767248 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 45D5F28E34; Sun, 28 Jan 2024 16:06:24 +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=1706457985; cv=none; b=Jp7J8iq4fXtsJJhZHZPTf1JFLEqpcx5Cqdb2gYOlzTdyLHu8F03ZdfjiwnyxNz5GpA25BbaDWk7/niOl8jHqfsntFDLNYWAoEbgJ/boxdC7gNV8f3KV223ackPiOrrchzpQAYulkn1tVIGpeV6tsaZ4bCgJxhLAm/wSYbpSnbDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706457985; c=relaxed/simple; bh=1d3N3oj+o7FIeyj++LcsGEScXmNohMCbxRK9XhQWY9c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q/2TyL49gUc7WxTXoPEVepToNaIdOrsDisWtonggTBB5CCRo0dbkz2Pfm6CySkMYY3vLrZ9rGM4s7vhtDARqP/WM0JgJg0J6abqaWRNOMrtlz+Vgbw2DRJ7/1eWjMmYK++WEEdGbriPMqW+95qRDSL3EZ76W7265BGKSJ6MnTZ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Mb8xytLv; 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="Mb8xytLv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99EACC43394; Sun, 28 Jan 2024 16:06:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706457984; bh=1d3N3oj+o7FIeyj++LcsGEScXmNohMCbxRK9XhQWY9c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mb8xytLv7+VHXwdF1NOZ1m7ib7wmEvQMUJKkae2rJI0C/BmkBtJKEPsiWq87Xcred vIt6Tx4p6rq1CqeAbyDTWD7qBZjWZrk+dAL1TIYNUMKo/YBOgqfCZX6Vl1BRRUcrOR +ZWsRSr3Lj/Fj9u16OqVZ6uH7gEsaMXcI4Fh2zMawk6wMity95YKMG+7w2NLgu442i 0rTYcvxEE16hraQ2qK4ytJdCes6u94HmZwBabiVd8AdasC5sY2hfnbJOK4gPc/Wp2U sthtsxonLrE4kKfjEVQiull8qt4anmvf/l4s6+mzU9L03T8WhCgX113WExAco1flKA D/ZY/dCHrFwpg== From: Jonathan Cameron To: linux-iio@vger.kernel.org, Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org Cc: Julia Lawall , Nicolas Palix , Sumera Priyadarsini , "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , =?utf-8?q?Nuno_S=C3=A1?= , Jonathan Cameron Subject: [RFC PATCH 5/5] iio: adc: rcar-gyroadc: use for_each_child_node_scoped() Date: Sun, 28 Jan 2024 16:05:42 +0000 Message-ID: <20240128160542.178315-6-jic23@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240128160542.178315-1-jic23@kernel.org> References: <20240128160542.178315-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@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. 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..6d9d286cb5df 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_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)