From patchwork Sun Feb 11 17:42:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 772072 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 2DD102837D; Sun, 11 Feb 2024 17:43: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=1707673393; cv=none; b=SjVrsHH/2FMap/JwV/aWOrxMuWsq5Xrpaib4kRpudmCFnZ2JD+ooM3Obnf21JfWI3zCHyI2FP7rPxonTjSh6lZSB9jZtHdKsAXS5TmTiLbm4sSyakl5QTlwbD68sMpJUNfrg9xFnVjfGd838I1plck1BKFkoVgaQ3isjVPUQSak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707673393; c=relaxed/simple; bh=FL7OGytfdxTg1+Il2BlWOFoikr/LWTCTYjPks2DpfGI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H1LDiu8ygANN3U2cDpShQbIlPZAAsL5UydtHChrN8icqC6NdIR1kxB6CRAvCjJMsmah734MhzPY+g56APKZt9fwMV7Y1hr3qgXGwW/ekuyk7G5eZC+teGlhh9ktJek0k4oXDVyb2w1BgtuDgIIubacltHKinz2O87Ad4Br1ECGs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qUqMQoWk; 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="qUqMQoWk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7586BC43390; Sun, 11 Feb 2024 17:43:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707673392; bh=FL7OGytfdxTg1+Il2BlWOFoikr/LWTCTYjPks2DpfGI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qUqMQoWk1tXkagwZnH8JtWCfo+skthBMefbkiM+Vfu4g8PAYIoVqT7XFHAHWFPWuf OXFcvLIbfoxckJ3Bowqs/sx/kC5iM9Sds9nYopT+bQ4o6ueB3YpwsH4oV5aHi5S76h rA/cChOxg6BuRiDe/W0FE+PEcV9k2DpFtMXiRUwliV3jVuYu7g9QVoO07h/HrMDb8C mwPGc1bPXyG3sXjdpqEo3CjzH+15pwe2VDwHtPKOW7Xkqn0G7o2b7RhQCQiKFYRmgp H5F/XrokeFMMrDTzdBorgj280D9v+zZuyBFX0IY1gPMc/PE9r3cgf8DUXSoeMGsoaL 66JjV23yVCS+A== From: Jonathan Cameron To: linux-iio@vger.kernel.org, Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org, Julia Lawall Cc: Peter Zijlstra , 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: [PATCH 1/8] of: Add cleanup.h based auto release via __free(device_node) markings. Date: Sun, 11 Feb 2024 17:42:29 +0000 Message-ID: <20240211174237.182947-2-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211174237.182947-1-jic23@kernel.org> References: <20240211174237.182947-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 Feb 11 17:42:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 771853 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 C79E85CDF6; Sun, 11 Feb 2024 17:43: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=1707673396; cv=none; b=cBZYPVcdwsKN1cWj/c1hwXzZ5ttWWZDUB5jKYaAi+OP8Nca++JkgXRfWRP19rWhLAmmBMcLTqQd0uOrXqMt33YRQEGdE8ggPmFbGDTEXVtXWHidjBu+hdsMktXoJw8D5yVwpPce+fJ2Y7rWmAPMQPbB3AKQArvHYkBMzE8C2bfg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707673396; c=relaxed/simple; bh=VgEK2vscmpylabGiM7nvGoX57oIPPeaNwTit8d+h46A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PBTU9x9L97uaExtanH5teun+7Lk2o1M6fzsoL1kR2TT0DMCBkTZY7FFClZUFsqH8kRmvsPhL5CRjY3Du6t/tXu/zM0u+JrnEOPO6Mi7/shBC/nBaqa2G5Y67XKd3MuQ6mUSAmzkWPVt1zCJljKTD/088B8JGoVz2CVT/V+JHH9w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OCrmHKDP; 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="OCrmHKDP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4724CC433C7; Sun, 11 Feb 2024 17:43:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707673396; bh=VgEK2vscmpylabGiM7nvGoX57oIPPeaNwTit8d+h46A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OCrmHKDPCdySn0pPYItTL2t7zwZYjXsrjzzICJ5bIPlVfBxcXz3I4mQx9Rm8+05IG 4zhQ5X9GNutZxC1biiXulib7hYq7Nf9Pkc+p8yBs7GT2qSG+CWT06pgc4K15BVQ/Pt xJIvH/rpk2l+k8WlsV5XbVworWbScq2wnTXn6sh9G4n1qq322KDmhvEqFftqyOQTsF jO52rL3gkVRzJMXltO1tCzCRdeY33DAJeUZXabutSKhgmJRten5clFb7JlKG02UOgL 1DrJWdfMVK3jobfLMxbYhWwFvjIGhSWiXkuryeMBJYkELTHBHier4/Bq62iK/5yJp7 mbpWd75FVNViQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org, Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org, Julia Lawall Cc: Peter Zijlstra , 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: [PATCH 2/8] of: Introduce for_each_*_child_of_node_scoped() to automate of_node_put() handling Date: Sun, 11 Feb 2024 17:42:30 +0000 Message-ID: <20240211174237.182947-3-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211174237.182947-1-jic23@kernel.org> References: <20240211174237.182947-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. 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 11 17:42:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 772071 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 B39EB5D758; Sun, 11 Feb 2024 17:43: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=1707673400; cv=none; b=hurKDcSI22D0231wS5HSK+5kDAjoZ40TRigMr8+KtsODHP+dDaSTpprQuhGA/jpCC1+jk9cVHaovW48BEZrbBTTuA4ooCWh+ih1HOZwWW0GsziZzwDs1RjpcbxsYAt4ThTBLxuDH5dcRslGgDdBNsjRP2bKhZTHBf50BORH7wdI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707673400; c=relaxed/simple; bh=ipeQZ+LZe5XilwqeMPmR4IQ68fkOcifsuM6YVshivis=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c2cRYyCxZsyZmfqXCOWPoJdBk78cIFaZ5jxnqELW+s94utl2j2RmacSYzqS5mVRvmZ2fziNOTzfYvLS6gAVp2uuNRUKbyfb5ExJ5rDIQa/VarkENwcH0CGR18Vz5kek0J2ggfR6ZzgDzZv0//VTQK4qKJtXEc6LuVO1bTt11Rdc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FD5NkYJL; 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="FD5NkYJL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8237C43390; Sun, 11 Feb 2024 17:43:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707673400; bh=ipeQZ+LZe5XilwqeMPmR4IQ68fkOcifsuM6YVshivis=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FD5NkYJLGeomQEeIp1Xv63ealhPiBYhblKKG2irQbuUnY5MqOtb+XQ6EDfMV+QoCq +5gMoE+NXCpbH3s4hJZIS05gGzXh4KNxFjbEKvNzU/dk1RAvTzB4bNipOSwarkKuxx 1qrTBV2mtkcwzPKWjp/6TwLzWQbYYlreZ9905gHqcwvAPkDZj/+RDzDHOrvG42MS2Y qrzSrIuBCuKFpjiVl7r9PJWHRo/+fnDGjXih+y18F0cBu1MIqAlUwgqKpwwrqRgs5O DajTQzngXbAS4u8OT93WT67f7bx0IVK7ki8ixn3md3KFKsaxmwgR9FToBZce1bj+7d aiRH7jjfLlPPw== From: Jonathan Cameron To: linux-iio@vger.kernel.org, Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org, Julia Lawall Cc: Peter Zijlstra , 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: [PATCH 3/8] of: unittest: Use for_each_child_of_node_scoped() Date: Sun, 11 Feb 2024 17:42:31 +0000 Message-ID: <20240211174237.182947-4-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211174237.182947-1-jic23@kernel.org> References: <20240211174237.182947-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(). 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 11 17:42:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 771852 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 7242F5D46A; Sun, 11 Feb 2024 17:43:25 +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=1707673405; cv=none; b=KDg2Z//QDY9/TO/8MfFjPSNCG53TkVw2wQbmk9SSyp+sR0MoA5+NlZ49gRPl+9zziHjDhbZEJCyYkbZHIM8oWgYpVlQI+NQSVUTQQs+C52r1/SgHZyq3RXjYYloEyHYVBO6zjt1ODzWLR9OKRj0QakuEg0b8d4G1lgHJy49u6Ls= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707673405; c=relaxed/simple; bh=pMJBOa3z0fl/XMAEMYjuMhiH5HgtDAMqKqBYE15+9TQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Pr7xTiG4sskfa2pVOdr5vshDbUlGNstzw3AT4WQVk1YAlnoGbyiR8PTR6TDpNW3WiGfcaKI1Vy/WLmQ/zxKD8oIQg5DVkRWEfhRmA2Y1gfnK90E1bTPhejdj3aHsFZWVdf4HoCD2yFEjQXimsEbek0pLfRI9LK0bCSZMno2NJ6s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dVMFXNzn; 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="dVMFXNzn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE471C43394; Sun, 11 Feb 2024 17:43:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707673404; bh=pMJBOa3z0fl/XMAEMYjuMhiH5HgtDAMqKqBYE15+9TQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dVMFXNznnTMFwhRkqT2qf1PAHTM0xymZuhBNMzxG50a6LSNU/8qZMwh0uKttmsAej ulkNw5NStu0yHp6UD8qfDxR0TF2pDiMeeq150NRPiCebFtoZFsvwf8y3SDVbmp8OFE sxvV/Ey5nkJWgDwyUq5h+gAtCUQPt18CNQwCLNKFYeE2Pxku8IF3XHYW50Catv3wId W0DeF8+yQ4eC6/a02Pi9HZGSe4eVZKrpmTjr5/P7tAwTe5YemVUm6xbYreb8JHWAUK xmbclT2ZETYfk5vFKZ8cC9hzofKN6FI1BrR0ghAW9nG3Ig8aYxsIilKrA9AqvBT6nW lnmvi8Cw5QsAg== From: Jonathan Cameron To: linux-iio@vger.kernel.org, Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org, Julia Lawall Cc: Peter Zijlstra , 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: [PATCH 4/8] iio: adc: fsl-imx25-gcq: Use for_each_available_child_node_scoped() Date: Sun, 11 Feb 2024 17:42:32 +0000 Message-ID: <20240211174237.182947-5-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211174237.182947-1-jic23@kernel.org> References: <20240211174237.182947-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. Child nodes should only ever have been considered if they were available (either status is okay, or it is not defined). Signed-off-by: Jonathan Cameron --- 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..1b0003230306 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_available_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 Feb 11 17:42:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 772070 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 AADBA5E3AF; Sun, 11 Feb 2024 17:43:29 +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=1707673409; cv=none; b=D3nnasuC+7pHxiFfZmf+koHs8tUYVQACQ8mGQ5GIhigd3NZd4aXe/DpKoino/RM8xVoFkrkRzqGtBao5W74Xy8d7yJWrvOZH2p/tvwrWIIlhiovxf04wODIxDTYowt/OToWwiJr6NlN8gK5Xd5Sjw3hDnd3ZxYqabunZ8RYylbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707673409; c=relaxed/simple; bh=wN0leKygyGGEcV5J2AcNqnFx2iI5WbKZIEWRuroojKA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CA2uF1PEWCWU1F0HTju6smASHYyLz5DUpjGywLefCeHLFkVmtUVqyCtKw8dH1/0GsdzIducJeLnhfgB7yfpHaRHZdnVwujQ9aMFZF/RWNtLpTc4L9u/tniEo1vNCweKw+oh6TkbGk81xIFmFESL2FoJT5WLwAsd2sr9/PIj2Fb0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=N6JB8Lsa; 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="N6JB8Lsa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 837F5C433C7; Sun, 11 Feb 2024 17:43:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707673409; bh=wN0leKygyGGEcV5J2AcNqnFx2iI5WbKZIEWRuroojKA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N6JB8LsaAUSXkJFJHZG1xyAfSxLIAYPo3qlV+tAxOQ1UZqKIHDPIIuHqGNzTvvmnH OgCYG5YsIZA8Lfw/5Zr64SQ8BEKEpstcrDKq3UnVw7HcS277MVjWb4zlLz+rxzyZE8 +aZM73JONaqjIh4l0RJLdgxbXVDwAncyLnB0SuDzK0bBTT3ID3Lo8zd99XKSetxhA7 IMRN7QWZIPLfnvnSLuAKyAo3Aw6+GH02HgWtlvGlp1tAUzOg1gX8j8jt3Ml0LkAAri 9wARM5lHXoDB3YEfeiOktQL4Lw/YAKfGep8jo4EP4HP+Nc6i6m1zvgs5OgZMRsN5J/ B/ezXcEPZrstQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org, Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org, Julia Lawall Cc: Peter Zijlstra , 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: [PATCH 5/8] iio: adc: rcar-gyroadc: use for_each_available_child_node_scoped() Date: Sun, 11 Feb 2024 17:42:33 +0000 Message-ID: <20240211174237.182947-6-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211174237.182947-1-jic23@kernel.org> References: <20240211174237.182947-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. 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) From patchwork Sun Feb 11 17:42:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 771851 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 8CB745D488; Sun, 11 Feb 2024 17:43:34 +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=1707673414; cv=none; b=SIj5UzeUr7bkHNpmAaDTQGzA+tUdislDUjslGTlUo8y/nrNS40tFFLI7F+oXviWthNLGhpOFY1VlH9wy0af9YiTU5TroNGWv4F/44nyuuz+SUBZh1ynjN3YSIHe1Fb9tWC/bNcZM8y6+1fIKDDcZuFNWm/Af4uwT9wEbQHNOo70= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707673414; c=relaxed/simple; bh=7bhniuqSD2L2Qes7Q2zW21qyQGYtas6Yezol52kECBU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S9VNiNKu6zG+XmalyDu5ryBwx/ex6WzdAeKC9q0U6I/G6h20IiKTF2Z+Vj5NxOueX2RsFG8yImOeUfv6hU3QpWvxNHUDSM5ZviGfw/KIBEgnml2rIM/ueCn7U1srejEtEXk6ROxPgST9lZIrQ8ZXI+EoZQbIZ+RyvkVwBHcJds8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ej3YfNCT; 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="Ej3YfNCT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EFA7FC433C7; Sun, 11 Feb 2024 17:43:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707673414; bh=7bhniuqSD2L2Qes7Q2zW21qyQGYtas6Yezol52kECBU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ej3YfNCTsrNyhgyrJSjWQfqpVOb/sXA8AliwEeRJTObFTGZIAdWK9nKPRZQmXOJa3 DcxZAKQY9ko4IgGCn2UFYDhXFGFvtobi05jy1z6QkrNV9bnQxphA/ZGJIraBQiq2wH 1AwHxdFnY21L3kJe2z5KTRf/zRlUfqLt8kdOqV6W5E+WuQCTfmBfxgIJrZ1jKRK63f c+mrIOjOYxrUM54NqkSBgLil+IbqaVKKXlggGGLzYx9UVP8iEW0mfz5euTGRk9Ld/l moxJVf1KPZ2k4GQCsuxgTt56fvfiJahSpwsu3BSvQn+FNMCMLbKGQqi+W0Y4NO+78u Cst08PfMKSOHQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org, Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org, Julia Lawall Cc: Peter Zijlstra , 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: [PATCH 6/8] iio: adc: ad7124: Use for_each_available_child_of_node_scoped() Date: Sun, 11 Feb 2024 17:42:34 +0000 Message-ID: <20240211174237.182947-7-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211174237.182947-1-jic23@kernel.org> References: <20240211174237.182947-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 Avoids the need for manual cleanup of_node_put() in early exits from the loop. Signed-off-by: Jonathan Cameron --- drivers/iio/adc/ad7124.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c index b9b206fcd748..67ccdad752c5 100644 --- a/drivers/iio/adc/ad7124.c +++ b/drivers/iio/adc/ad7124.c @@ -813,7 +813,6 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev, struct ad7124_state *st = iio_priv(indio_dev); struct ad7124_channel_config *cfg; struct ad7124_channel *channels; - struct device_node *child; struct iio_chan_spec *chan; unsigned int ain[2], channel = 0, tmp; int ret; @@ -838,24 +837,21 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev, indio_dev->num_channels = st->num_channels; st->channels = channels; - for_each_available_child_of_node(np, child) { + for_each_available_child_of_node_scoped(np, child) { cfg = &st->channels[channel].cfg; ret = of_property_read_u32(child, "reg", &channel); if (ret) - goto err; + return ret; - if (channel >= indio_dev->num_channels) { - dev_err(indio_dev->dev.parent, - "Channel index >= number of channels\n"); - ret = -EINVAL; - goto err; - } + if (channel >= indio_dev->num_channels) + return dev_err_probe(indio_dev->dev.parent, -EINVAL, + "Channel index >= number of channels\n"); ret = of_property_read_u32_array(child, "diff-channels", ain, 2); if (ret) - goto err; + return ret; st->channels[channel].nr = channel; st->channels[channel].ain = AD7124_CHANNEL_AINP(ain[0]) | @@ -880,10 +876,6 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev, } return 0; -err: - of_node_put(child); - - return ret; } static int ad7124_setup(struct ad7124_state *st) From patchwork Sun Feb 11 17:42:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 772069 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 99AD45F484; Sun, 11 Feb 2024 17:43:38 +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=1707673418; cv=none; b=dXeS5u/Lb738PKQRNwWBa3Gdo0+V0ywfLf65XikKWcSFGpvMukgNIaUtJdRnibFLx/d632QKX8Nq9l3z0lcs4RGmAg+ml6C1ssLT7ZrPK+L36JjqqhvYw23xdVsXF7Nb0bMzKxfOyWKhjzZ31NO6Ft7kh7dWmsEk3jh0zKfA/kg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707673418; c=relaxed/simple; bh=+y95bK88fWChXwFe8dJiZk61N/FAhsRBrO4KSZJeTWs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nZxDug7nyiKIvoYUqPROAyd7GVB8LMI76PgAcP9HkLu9nP+IKDt1ZburtclPMtU4ITIMxi8Ht1VLsNjbmg97y+cUQ1kmiV6KpPH7/tnJZvQAKemk09qAigdn4lMLl+oQY05kPmmS+eUXoYXTw96HwnHdX6+bmeVsE9OI8B9DvPE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=r0aMipmi; 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="r0aMipmi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCDEDC43399; Sun, 11 Feb 2024 17:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707673418; bh=+y95bK88fWChXwFe8dJiZk61N/FAhsRBrO4KSZJeTWs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r0aMipmisV6duMkJCRpkqpdiPLxLixTLkM5cdohBgSPZ/vPLi8d6FZf3X6qPvMpAA fouKTUqKFfVdvPxi+r9AIQuHW1o3LgPtJvxK6/fbMqMe4SrEmy+IFrL5mYKSCUvAMs jm9iT2GreDxVejZblrC07OV+QihDMEFH3qz56ukAkFcgCyz29e/yKtVnXlx4nmsMEJ 3/uwd5hTaV5JCI/pt92fIzGjJeIv4otRNES5Gevdr5g2lyKfdmn2iHOjZmKpAhIZSw qIwsBzz6I4G7c2uOowuCkhv3fDNYK2nTWVkewZPEhu/GmnAoPfkTj0DJFLFhNNNQF+ lQU34WT1KbA+w== From: Jonathan Cameron To: linux-iio@vger.kernel.org, Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org, Julia Lawall Cc: Peter Zijlstra , 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: [PATCH 7/8] iio: adc: ad7292: Use for_each_available_child_of_node_scoped() Date: Sun, 11 Feb 2024 17:42:35 +0000 Message-ID: <20240211174237.182947-8-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211174237.182947-1-jic23@kernel.org> References: <20240211174237.182947-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 Avoids the need for manual cleanup of_node_put() in early exits from the loop. Signed-off-by: Jonathan Cameron --- drivers/iio/adc/ad7292.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/iio/adc/ad7292.c b/drivers/iio/adc/ad7292.c index cccacec5db6d..a9354bd1ce54 100644 --- a/drivers/iio/adc/ad7292.c +++ b/drivers/iio/adc/ad7292.c @@ -260,7 +260,6 @@ static int ad7292_probe(struct spi_device *spi) { struct ad7292_state *st; struct iio_dev *indio_dev; - struct device_node *child; bool diff_channels = false; int ret; @@ -305,12 +304,10 @@ static int ad7292_probe(struct spi_device *spi) indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &ad7292_info; - for_each_available_child_of_node(spi->dev.of_node, child) { + for_each_available_child_of_node_scoped(spi->dev.of_node, child) { diff_channels = of_property_read_bool(child, "diff-channels"); - if (diff_channels) { - of_node_put(child); + if (diff_channels) break; - } } if (diff_channels) { From patchwork Sun Feb 11 17:42:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 771850 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 7B2AA5D73E; Sun, 11 Feb 2024 17:43:43 +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=1707673423; cv=none; b=RZCvmYWZFc8yHqyosMcCO8uw5R0XjJZxk/STw+VW0yGYIfWSmcBdib8WhhYS9bQF+TBMdePDkxqUVu7Nd/8K+wpXaBxccdAxUU4cz1TgorpXz/L9BQsGvdSvYwB8epk5C6j7SBndnxBxM+HHKLpTVhiZkztg2CDnbQKnYS72HC0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707673423; c=relaxed/simple; bh=oP7Cqkm/5T3pGBvjae33JMVHKBsSoCzjAMOiZeqVCQo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Uk+d2XyLnwDl29lpVzxbtv82pgbY/6iwHBpYjVO3SKVsIiFTGosXOgQHtzZF5BEs1JXhT+dN+wD7va49uPrcPRAcktj4Yz1zMU+HEIRLSH/hvdPUmwpnFdzmwkH/09ysny8v27eZscf8LvAC5SqptVnHAFOHZACZsgGDhsoFAKY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nc3tKS7C; 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="nc3tKS7C" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D96E8C433F1; Sun, 11 Feb 2024 17:43:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707673423; bh=oP7Cqkm/5T3pGBvjae33JMVHKBsSoCzjAMOiZeqVCQo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nc3tKS7Cfm2B/aaEnOZz/NuKLMPYUqycHKpE821Nh54RAULRAh8B9c2A24fgokQCN mSouTJKqU7l8Xy35as8W/rK1xvuro0pmX+9zAsMlxBMnGRU+Q0rY6oVbgYe/rZuZjg hAMKM5XFu8F6EyP25nlWb81GKSZPuE/tDLhuCWx4y9fOzJV5gPx0+2a3puYGwHE/vK 3D2DDBybvc3hf7bz/eJP8ul93rejo+UpKblluzFuw303o1Yfc6b2PpOP7u5s1WhzL6 MpU6A0FVRYRefT7sIJsOuRZkWFOXQDv2UIqmBCvMzKlF/Ic/PBTC+CSWFXjg2onKJr OSB2XFbLyNwog== From: Jonathan Cameron To: linux-iio@vger.kernel.org, Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org, Julia Lawall Cc: Peter Zijlstra , 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: [PATCH 8/8] iio: adc: adi-axi-adc: Use __free(device_node) and guard(mutex) Date: Sun, 11 Feb 2024 17:42:36 +0000 Message-ID: <20240211174237.182947-9-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211174237.182947-1-jic23@kernel.org> References: <20240211174237.182947-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 Avoid need to manually handle of_node_put() or the unlocking of the mutex. Signed-off-by: Jonathan Cameron --- drivers/iio/adc/adi-axi-adc.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c index c247ff1541d2..3c85e8a6467b 100644 --- a/drivers/iio/adc/adi-axi-adc.c +++ b/drivers/iio/adc/adi-axi-adc.c @@ -248,19 +248,19 @@ static struct adi_axi_adc_client *adi_axi_adc_attach_client(struct device *dev) { const struct adi_axi_adc_core_info *info; struct adi_axi_adc_client *cl; - struct device_node *cln; info = of_device_get_match_data(dev); if (!info) return ERR_PTR(-ENODEV); - cln = of_parse_phandle(dev->of_node, "adi,adc-dev", 0); + struct device_node *cln __free(device_node) = + of_parse_phandle(dev->of_node, "adi,adc-dev", 0); if (!cln) { dev_err(dev, "No 'adi,adc-dev' node defined\n"); return ERR_PTR(-ENODEV); } - mutex_lock(®istered_clients_lock); + guard(mutex)(®istered_clients_lock); list_for_each_entry(cl, ®istered_clients, entry) { if (!cl->dev) @@ -269,22 +269,14 @@ static struct adi_axi_adc_client *adi_axi_adc_attach_client(struct device *dev) if (cl->dev->of_node != cln) continue; - if (!try_module_get(cl->dev->driver->owner)) { - mutex_unlock(®istered_clients_lock); - of_node_put(cln); + if (!try_module_get(cl->dev->driver->owner)) return ERR_PTR(-ENODEV); - } get_device(cl->dev); cl->info = info; - mutex_unlock(®istered_clients_lock); - of_node_put(cln); return cl; } - mutex_unlock(®istered_clients_lock); - of_node_put(cln); - return ERR_PTR(-EPROBE_DEFER); }