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: 199489 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2032529dyd; Sun, 11 Feb 2024 09:43:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWkSxO3z29ZOuBodYM5KS7r2wgcqhsQbkPqoHDAsLP7gYMILgPoFy4LEZxnDasXJMq5tq/qrKK0yllIkPEcBUuRETECaA== X-Google-Smtp-Source: AGHT+IEMHe9jKxVvFz1gqvAe8mpNpbSE9ONl8XVDIdMD93FeoQ7CuAw6BZTK0QgaahM+uXBQh31N X-Received: by 2002:a17:906:f9d1:b0:a38:5658:54aa with SMTP id lj17-20020a170906f9d100b00a38565854aamr4331088ejb.12.1707673425525; Sun, 11 Feb 2024 09:43:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707673425; cv=pass; d=google.com; s=arc-20160816; b=j199EtdRQ5GktHCGFPJt7T8T5DScpvcSXW7xbhoAbD7CBPeLHrr+hhbs+y/NySjQRz U0LG4YFL3qPt+fNZs0OK17b60hH4NoPgf+fbkxfxwa43eVurlm3dnA0AMjxEpXpmmgvx SIuap8h0GbbYVZqB2mWIHu9zJZ7TG8nNY+KLBp2e4lOYaYzKvRUuta9HgwhRQvQcRcKf yVcykPFiO5chVVv130+uRHVbSDeS8iNr5Snra8wlbxW6ceHIKxVdg3wbvt7hx+Q56Xge YuxNM2cy4OVfFsIZShzHjd4EDt+mEM/d1C9huf+I8FpYRBmMqq71PqP/kXdmdz3lrLQD 0iSA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=nQsj22NPxmBMr5ip7C9eNpQVJYUc91r8FEatPtU1zrk=; fh=xfiTMzPv/Vii32NWQwZKUy4liNzEYqGxEhjuGAQAoJo=; b=iTVaekaN3oF5DGnpQ4yNCoikxhdU7Jh3drnf4/AQMKCj0aggExtuYZlT94pGGlnS/4 pR1odFyJlhTwTWtNRew4TlQZ+YPCBdP7gC7RENlWP5UYHBHPyYjGTxh//n6vQ8fG+BUO RVnZ2UoZ0K5/m4w06ojY9D4UQwq+/CGZsKhxMZHSino25SPcs4da1AbvrNVBQeQbbvTi Mg5FOo3Jkza681CwW9H10Jbn9UTgOb9CLaXb/AnQeKl4l9+MS8DPpeV4poa6ib5attHF wEHQq2WNvNedZ0n5XlGdYiu/V+mEnSvA+s2EedbwpTOTJXIDd2OOGBvxQxD4FIcW/n3D duxw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qUqMQoWk; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60886-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60886-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCWAQ6ULOqdwJHS45uOhdiG0ChgJ/d6ZU82fwY4pLoK9dpp0yiAwaFr+RTgkMX7LeJJbQELr4o8gaOzOeqQ4RR/DcnMIXw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id gt17-20020a170906f21100b00a384f537a74si3028208ejb.860.2024.02.11.09.43.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 09:43:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60886-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qUqMQoWk; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60886-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60886-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 255391F227A9 for ; Sun, 11 Feb 2024 17:43:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 272025D745; Sun, 11 Feb 2024 17:43:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qUqMQoWk" 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 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790625370235264406 X-GMAIL-MSGID: 1790625370235264406 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: 199490 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2032601dyd; Sun, 11 Feb 2024 09:44:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFlS0aABUET5Ti+oK+UTtRS30X0fSIT1aTqd5eMiC5M90RfRhECEkbgWmJHmOU6n1QwZiCA X-Received: by 2002:ac2:44ab:0:b0:510:ee2d:c185 with SMTP id c11-20020ac244ab000000b00510ee2dc185mr2946084lfm.13.1707673440997; Sun, 11 Feb 2024 09:44:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707673440; cv=pass; d=google.com; s=arc-20160816; b=bfE/pu5URSwr2uzX5m83zpt40VBx34yzWmWCUaCcadCKbPSn70PkeytMumHfoS9Bb9 zKZa1PzXWDPPioDyNOBgmHRaA+pa2Y9XHu6erPWQQ9auWtzD+nppi/ukaDEUcNfzULQj GXuZDdM+pwGkQkgoKopUzTv1YExHSuiHQeopgstoxaoy81LcQJsrxzMQAvFM7mqR9rJK OtNhVj1Vv8j+6Evwhd9usCL/gMoTchHN3MYRVrk4F+8cGOBzoN3+ORovJzgAZONpXxMl 0x7/oIb4njlXLynFFsi0Qbduh47AW1qNd2xlfUsF+V1P2OXa56y+nGkCH8Uu51D4UiYs pmfg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ELvTT+TwAMDXy1/buqnUbKuYi0cGHMudMPi+twztNOs=; fh=zA3Vk3bZOog6QEQVHRHuDlpFHnCKEYOP/w08OutB/OA=; b=XlzwvpZva7RXsaJeXJmhwcnGVa41PUTQ5avuGB0lYp+7LRYWecdx4omFkzwOGpi1Sf lMe5mSGaAOgngx+QQl5Phq34aBjX4jmE4X6EuwvRZWL7i0LX8Doz6KepEOMn+ZUwyFAQ 23wfkKnre3ZPjXSYqTbY7CFU/GHeR2ZrUlAXLJ3FAMPZmiGP6fw58FNZ6dQfsodWSjh8 zHxZ0S/NoXgDPUiaNePgm7uwahJ4DpMdQe8ayt+bWYGDS1mGKSGX7/PuyY8nHS4gOdJq 0FBpBXOAyOF8alHfa3W1TN2YJg+TecfK0pPBPhS8CuSJFpu9XPbJsalWjvDX691VtpHG NGTw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OCrmHKDP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60887-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60887-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCWKaAezKbbqrXLIsKgM2ZFB71cS+LmRk17ca1jKcVwxQN/3PN8FTVNyoA8GO9DdeGuuwcI7Q3dn1z6Yfb5VmXnCgLwnQQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id h25-20020aa7de19000000b0055ef7edb086si1917680edv.365.2024.02.11.09.44.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 09:44:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60887-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OCrmHKDP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60887-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60887-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9386C1F226EE for ; Sun, 11 Feb 2024 17:44:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A11F35D8E8; Sun, 11 Feb 2024 17:43:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OCrmHKDP" 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 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790625386072843064 X-GMAIL-MSGID: 1790625386072843064 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: 199491 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2032684dyd; Sun, 11 Feb 2024 09:44:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IFhGdebeW83OrN+R4/ZPFJlMhcO/20n+Yw9zkGaXJuNtgxCBG6I4xhCxgDCADMYfK7xluRI X-Received: by 2002:a05:6870:e2ce:b0:214:cd76:caf5 with SMTP id w14-20020a056870e2ce00b00214cd76caf5mr5870520oad.24.1707673455249; Sun, 11 Feb 2024 09:44:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707673455; cv=pass; d=google.com; s=arc-20160816; b=BXTdQwIuGuRFgCX2LuFS5B/EcUU6icS8Sf/KSpoXUgASQ4VBB8Ki/MLlzHXV9zP7C3 KHOXyT7bnv1GovrAfHDhk0gMogStlx2e/EFqnzoOIcg0COWWCtk1lR2FJ9S7k7cahTl/ ug9lzAxNhWZrEl98e0pekNS8BMd04NwPyk0R6Cgvqn2hkuAO8jUXXdSLKcnd0yz2+Yif Njd2dLfqSUyWzUHOT6Ns+A3GAq/rrok7R44+8L2zQ/lNV1/Ic+QuL8eWOEOs9npLHpr3 34nf0+7QmDcM25D7DhsT9fACSkPGOvMwLyKW1cP4n85EuXM9RpP9fJNfMNdr4bvYTdRJ Imaw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=sJPCWKBSX+6lnC9wnsLv1sD9T4P0iwOH5PegSMELXLc=; fh=OYPCDyGR10O0Y3erTx1GHe3dQ1qEkEkXtBeyURCyvws=; b=ghVRswaM/22Qnp7IKER+d40o3L4E1DRSjHU4LfhFGaNLOaxVq+/1OX4m6iwWiQ7F1e TAV+Kws0xLrqcl4x4d/aunXDf2bFv8Vg1HwO/WfJbQZJmu81nTb7kS/hTUos+aYC6e6J aiFofn+R1VMQBYrDgeEQL5+460mCzxAM5JvE6nB75aXeSVAQeXaCrxdTW0JcqzMUXcrf +TvedBF7g8QeuRhzF9XyYRn3P5qsL0zHFv/kHB3EYrOQ57ue9cB8L5Cq6t8f5Bs9nDfa I8ddyoneQgAPas+MDtMi59uROyXWjbp+ss4QzlunFF20fIL129lcwn0zUNNQqaphWhnb Lw3g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FD5NkYJL; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60888-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60888-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCUovoq99iMTFKViPaN1q7ahLlOJZkrvfkYmoNlf9avGeGKsmnD0z1wvLyYbnGyaIDGvS2JHFCBRaz4agpBE0/PCy5tu1g== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id fv7-20020a056214240700b0068cb501b052si7024906qvb.138.2024.02.11.09.44.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 09:44:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60888-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FD5NkYJL; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60888-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60888-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0A1761C20F18 for ; Sun, 11 Feb 2024 17:44:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7156D5D465; Sun, 11 Feb 2024 17:43:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FD5NkYJL" 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 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790625400937737537 X-GMAIL-MSGID: 1790625400937737537 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: 199492 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2032754dyd; Sun, 11 Feb 2024 09:44:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IENua3KkPRpEOWJTKr0CORar1lL63hNyJRhPtLg4DhghHbIF6rEV9GWDqVB+tszLLt0TUZk X-Received: by 2002:a05:6214:4a01:b0:68c:6891:d42a with SMTP id pg1-20020a0562144a0100b0068c6891d42amr7257339qvb.22.1707673471083; Sun, 11 Feb 2024 09:44:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707673471; cv=pass; d=google.com; s=arc-20160816; b=xLOSqjHrLgTSSGk2PGyuq2gYYSOL0Ai772O4eE3yYTdjOMweL2/BI9BPRu0hT1i5U9 RYvDjQ7X6QuVe3vgBKyzyyaYvJzv1tGZrZvggqT4jsKi9n4MPxciDgAedmlyurMKA9gc 1BhOXr771yCvsdOXf9NZHHgKZn0F1QyAWNvFFKaqQChA8ZS30CwhoNAOQAegpY4TDfby y4kDWq+OXEmRoFJ/24a5KLZ4Cm9ZM2BW+rbAFSn4OToRBRjKn+apddIGAJpwoSnUt3yH r5MbWa7JhIuuTmwFRci1Cflb8XgOeyD3lOgrXdz6os6GrTjLuJa/aOblLNMEpmyXyM+M 3Xug== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=fnJQE2QkMcRVzQA2BeqNJ/Uh0gWKXCfBgW79oWutut8=; fh=+usM+UNU/HLZBgKk5u0Q8I1i++VFCLxkkRE5bfxhJow=; b=fn5dRkL5Z9citINeLxHOdhTJQoz5BSj1tcRtZ9xRsIWs9GgBSHqKgiEHaqg0cFq62A 3q9LHiEDMNU290GRxqpgJZlzeT2NhsKNg/CXciYU4Ci8AjLv69SixlTAYKBNnTbczD3o +l+XkkOULqEvPwHMTteaW5tAbBGYEaTzkWTYWnQjPxFufKz51kYdn7mWjuqXuYsVYNfz nl30w7OIv0vHIu+g7lkotLPXmn0YLWQzefiGzrpinejDX/poTGr0xL2GKKRR6xUedIfc +ejGmwCpDNnkIAbWZJ40mXAwskWaJg6ucIQy37ZMFRkYhLrVgGrk7f4paMifGfD08uaq LZEA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dVMFXNzn; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60889-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60889-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCUza2RbQoVFAkA9PtoNtgvHO/Hg+cQWyuS+p35VXSmUtzLA+oW7if5tF9yg3hEqLViIcNVHyS6MG+ckBfB9OP0MKKjE9w== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 7-20020a05621420c700b0068c87e072f8si6993456qve.453.2024.02.11.09.44.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 09:44:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60889-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dVMFXNzn; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60889-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60889-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D62101C21001 for ; Sun, 11 Feb 2024 17:44:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1DC0E5D474; Sun, 11 Feb 2024 17:43:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dVMFXNzn" 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 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790625417898907141 X-GMAIL-MSGID: 1790625417898907141 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: 199495 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2033415dyd; Sun, 11 Feb 2024 09:46:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUc92FrUB0sd4OqGp1U/gk2qqLNoxIq5rAnrFAL7nnjFb/9TI8B7FJRXNzb2VWCQjBocuh5C0Ik7UruQoMWdIyntCS7pw== X-Google-Smtp-Source: AGHT+IGhGf24R5Eo07WX3JFHa+JRo1ztWxHtkc8HU7dz7WerRSn89H3MVqB6NyGHcyMqAbSnkEOX X-Received: by 2002:a17:902:b589:b0:1da:1daa:e2bd with SMTP id a9-20020a170902b58900b001da1daae2bdmr4942856pls.19.1707673584141; Sun, 11 Feb 2024 09:46:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707673584; cv=pass; d=google.com; s=arc-20160816; b=zgj0LDCnnxoqf1D/KO59uX++eNchT1WGMZAy9vutqW7ffas2BxFvgxFfW6Hy79HMNs lG0yycmSNbwSRLNiKviqxM3EAC50EushF4I7Ea3NPcKmEdTxzdR2vieeIDRP/LkkqqGf BCj8uJfvljkV33/w38odTiqSEhZXFB3UI2x3i3IRHUjbK1hfgXqhNgla70cQCDaBWcYa uN9jZ95BpDtCzshJLUgBv6hxFSeF8SmqYvvDT51ISDl8FErB8bChBm7a/7XYP/sAk31k vQuG599yYjTrIKk0wY8y++8ZpnbRCGtAW4pRssK2Ac1KsoPfKUCGwI8PBLMAcHWALqKG gXDA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=oZnbVRUfZe8hqk9BCac8OmWV6jnzfnVNPXTHm7C304I=; fh=ATIzgBMCAVrcGwBXArv9v3/8NvNJkiZuRVh3k1HPhHk=; b=yB50WHKj9mpdt8UxisAkQsU1bi4PhPlwKAeHTMoKJF0c9YYyVqD5nLI1RV0YQUKt+w JJrZyQmGxqusIS0CXtM0t70c3EKpvyvgAG5ZzDy0VukoYehrIeaIiBurql737MyQ2rEK lUrVt7lj/3myWzNB7fIeJTfgnO8OERR5PctW62cFWSXGv6cbTGwyapgOn8+HMLZ4yXV6 zLSYSOvEqN+CN2TL/bOj0BFInn8/4orXbnjfkXd6zt+/gFPSmW0zyY7qt4zLP89qMTO1 F79/nv2/jaXHEcsKMYgYrLg1OyJFa8Y0Zi4394CJbgCD1jN6kbTkPnXdnZYnXGwjYqbI gNwg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=N6JB8Lsa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60890-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60890-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCWGY7I4gdrwMjZKvwCKRl/m5jEzAnp11CbQFCqiqZ3WJ6P3fPu6jU6a9cVzhtzsl46hXL6zGb/mBOBi/F3htvJjytAxNg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id mb3-20020a170903098300b001da2c896119si908964plb.432.2024.02.11.09.46.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 09:46:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60890-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=N6JB8Lsa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60890-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60890-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 6A22EB222D7 for ; Sun, 11 Feb 2024 17:44:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7079A5EE6D; Sun, 11 Feb 2024 17:43:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="N6JB8Lsa" 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 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790625536617329864 X-GMAIL-MSGID: 1790625536617329864 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: 199493 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2032928dyd; Sun, 11 Feb 2024 09:45:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXgqzu55n5Xk2+C13Rd44cHgmtWrUZ93dW8an5F2kBzSfvAIt+fTcQ1TtA3n2OGRnAj7a6 X-Received: by 2002:a05:6a21:3489:b0:19e:b6c6:8f15 with SMTP id yo9-20020a056a21348900b0019eb6c68f15mr7220025pzb.25.1707673501984; Sun, 11 Feb 2024 09:45:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707673501; cv=pass; d=google.com; s=arc-20160816; b=aRU0sz0WYkT8mnSM2rYsj/ngDWlMECobrrT62nYaJupBoHlvSPgXl7elB8+Wf8Ofah DMasqr6U34lkoPonxf8qnUbnSOY5BVCHrIQ53Ue3IhM4YTFq9aaz6yWyeBiWWZHw1aT8 +y4vgxye9uqjdb1L1UkyVMMCXFQ2CLgV2sLCxvblv0IOBlWl/3Sev0VLMcw/MCOCIB4d uSHYU7BKkv+hjnCU+WuuFm/06lcesl3ZeivooK+3X8cUVu6iBFwyx3/6G/3mRkmbIUV/ DlnALeiNQGFNQOBYF3ou7E40YHUYuvCdgAaAMCviH1BhKsEuiwSFSrQgtERsrAz5sbRy owsQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=t9/DrgjTOa891oxA8pdeZr5UKfA4224wTmrSkwOcfj4=; fh=zfcXrm7l5pzvUMT1ioHMh+MilsiUhACIFHa1fvMMho4=; b=k7+45cfp1YfyjfiabcebRVdcYgkphitOcS3SH531Yze+JkCL944/88H2Sxb83Xoxbk r3KPbceSNurJJG3lDSmnBljg9kfl3AObEMzhJ+PrzarOF9xZIFSatZT6Q2WvJxcrOId0 BOhDFafX+DFdNiY2pv10HkP1YceASLbrGn+sqQn3e8Sk9R+f2NMsfvB46hnrqllq/nTa bh0fD7+IKfTTdwRXt+tze5zlcgHKe5nvlZCv+FbnYFh+ZlpfI1Bc0cfTu1l6pSdaZmU2 yQJ5VkdD6EW9KjG347HXGrbKklj37tc2Ip1Keb8wNlIUbGUN+SKDBhzb271KsT1IlHGx EVnQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ej3YfNCT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60891-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60891-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCXTU23XWYlDCW4+wXGgKSWI/MWZVMfXd+G4QZc9HYsbLo7OCyPCC6BpOwPb+LTVqPt7u5TJO0Xko5Y6DkwaL+P+rUDjRw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id cj12-20020a056a00298c00b006e0a46b72a2si3040280pfb.148.2024.02.11.09.45.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 09:45:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60891-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ej3YfNCT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60891-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60891-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id BE2D428102B for ; Sun, 11 Feb 2024 17:45:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 551D55F460; Sun, 11 Feb 2024 17:43:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ej3YfNCT" 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 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790625449919492455 X-GMAIL-MSGID: 1790625449919492455 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: 199494 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2032996dyd; Sun, 11 Feb 2024 09:45:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IGxxJXh2d2fja4ZOZtlzjVwJ7m5cT4tVcTIzO7+QHIGX+8u8mycbxdfRauP37pry9CSr/ZX X-Received: by 2002:a05:6a00:450f:b0:6e0:548c:97e5 with SMTP id cw15-20020a056a00450f00b006e0548c97e5mr5967080pfb.2.1707673517421; Sun, 11 Feb 2024 09:45:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707673517; cv=pass; d=google.com; s=arc-20160816; b=u9NNsfczjJxGRFD8a6bB4XqwSgI2EyFuggmvdu/jMr6KpgPpGMdzu+R4e4OlrL5j1w gaY/ga6jS4A59MBUYUvB0fsX2vPNuEiFeGhYPHDcQaW4IolDDttkWXb6pICK+T3XTwZB 6wkOZj/NhjFSBfHzlGsk6tyeUm27l6fRH6TtzhFSPQGmC8Cs+rFCvxvueuelc+/NWyUU ve2ssqQW9gdF8vmiNX0XVZY4mHn7n/jprMYi1MHZoMIWOZTMbejOxYvgTfWe+xNC3DK4 Mi9RVkrO/YODisuR0mLheLmuxbwmv1n5U/sFPGPaVnIZxRkmDlWY3Mwc0gOJxuWozOEM 2YOA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=PG5RTZkgI90P7Ay2I5/CrgUMTQxy+sFcIpFu69YFgvw=; fh=0YIId2Tm981pPetfXHTaab/v1QEWCK/J0ACXYXQ5O6M=; b=Chz7AAYrBtzR8exsyRFUkRN85DwCEvQ59Dd6ip8z8QUdRiCgCUXrQts6g6twnnMute 5YYkrbcG8oujXIEu78e9fbwtT6fP2IMy8kI4HM14GwRPU8eXWqaWvX5ysTNOQ2kDOIqX 09nAA5HBvMm/S58M8yg3fLXVg41sC4DaxzNwgTbKnK6ykDyYMs6YvW6sbVh4aLr/YA/Z YEkc1JegXokzjANtGd62TN2pcKuQfTsFbAXI+a+GG5Q6/A8Fa9izdNN0dGnD6WXcb0QA jqJo29eKxlhsNEOFi8jSTrqMTLwgsVJI8/TyfPlxxClObfnKvxjQt60W4pS9ptKxTkX1 2HDg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r0aMipmi; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60892-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60892-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCUqNIw/qovA7pSMBIy4Hx6aQcheGE/YM2rav7H4kPKnwFONh1yI1QlunlsYicmNGgqKjkrlbMaujWrwUAVB1W+604lCLA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i134-20020a636d8c000000b005dc498de158si5094556pgc.49.2024.02.11.09.45.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 09:45:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60892-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r0aMipmi; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60892-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60892-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 31FE1283AD0 for ; Sun, 11 Feb 2024 17:45:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 506F15F552; Sun, 11 Feb 2024 17:43:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="r0aMipmi" 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 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790625466072504074 X-GMAIL-MSGID: 1790625466072504074 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: 199496 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2033657dyd; Sun, 11 Feb 2024 09:47:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IFRztJ5CcEcodapq056Wv4CcxjpFxrfAn+u+SLjj2wvXZ/iBIxhOn9W872G2D287ttztxKy X-Received: by 2002:a05:6358:8421:b0:178:799f:bcea with SMTP id b33-20020a056358842100b00178799fbceamr7473314rwk.7.1707673633778; Sun, 11 Feb 2024 09:47:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707673633; cv=pass; d=google.com; s=arc-20160816; b=jTsNM+KP6of10VH1x6/M7GieM0gLR7amRfKDHlDSu76w236ITHs6YWsvZZQdgzPFke FVWIgpx+OOcO1IHosmgeNlyNhJNX19G4kUtUpIgzt0Y2RnRvrZFYy0+faCIwHRJvlL7a krWkVWas34eHW/lzHkE9dEP4Xh12Rgfo7CJr5uN7CwNGWqZ7sNgEUG0Mz6yUs98xw/qg u5hJTFoVIuBtXclk69mFcap//rSXwdLQ4CEVKEypVndwO8ezvhEFvRXtfbrns0w2SWpa q67hJ8PcPqXkaUvW6Z7JiSuJh3mHl8aUZw1OgKHfUWruifmZsPm/YJ/Mr5JA0a6Nnqhp bQfg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=xp/CsoF57mWiI8+dBWoEFGm72AqFSgmGcJeP0F8ffxI=; fh=rjlmNYMyWMjSdSWfSmRjwTQvtdD3MbOHm5LPbhDMTx4=; b=DaSoJEP8AHm3ZUQnOcxTWpUoYppX2Q3SrqgUGbdeIOVdHbuTKh9tA4C8I1jRciEkIT lQKIGVGu/cQL09dawltor+yBuCamSFDflUNMR6I7vuHODBkDUSeZ8aV26wFeADMQBl6s QOD8jfNbmCksC55l32eqOAMhnlVdXmLfclzpnM182IqAO+8rNgudg0JVzTPbuaSj2Me+ Q22aBGtlD8MXDJyrN4at9J5IwaoUxPWHD7Nlxzh+UrdZo63PaKvPa9Yuqku8jsr+/ltk pKabMMghDVLADS1+BSwU8gwauQj111OMxZaf9o2Tw9akUxk34tIA5LG7v97dJITxriIE 4uTw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nc3tKS7C; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60893-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60893-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCUBcd8igRfvsQ9d0/D6DYOCEFIXOs3zYHCR8ngxKtDKnUiUB++VtFbd1moliAqwc46jsGXtF/WGjjSnrmYSAJuPfomsEw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id y9-20020aa79e09000000b006e061bdc0fbsi3698295pfq.27.2024.02.11.09.47.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 09:47:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60893-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nc3tKS7C; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60893-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60893-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 2D60FB2274B for ; Sun, 11 Feb 2024 17:45:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2603A5F57B; Sun, 11 Feb 2024 17:43:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nc3tKS7C" 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 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790625587707421662 X-GMAIL-MSGID: 1790625587707421662 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); }