Received: by 2002:a05:7412:9c07:b0:fa:6e18:a558 with SMTP id lr7csp768172rdb; Sun, 28 Jan 2024 08:06:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IGj3NKmK72KOQBFrwdIFYd+jx7ReCZ8i9PyDMQQQOaOfZeqfNqMbFQretpyhfYwEhKc1dUk X-Received: by 2002:a0c:f051:0:b0:68c:3d02:2fd3 with SMTP id b17-20020a0cf051000000b0068c3d022fd3mr2498272qvl.91.1706458011933; Sun, 28 Jan 2024 08:06:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706458011; cv=pass; d=google.com; s=arc-20160816; b=Heid36z2dKGkfgc+LPI2cAJ5zjpiPiQebDDCsKoeYbDWyaUOCW6RRLvn5J+IAV9a/R mbz0coa+Ui/AHmybOw485RpLGE6PUraEpzxNybjcc5Qn2dOueNOGj+Pj76HdmU9g9SvV f9bO9PD/im2goN+bssNHCbt5xc/EyQnOnXXEnIO2VxI+TmJaF0oSAd3vfo+OeTPrQMne EWHFCHKhdApwJJjxtDCOW7rSb2rwpP8BhzYs1NXm6+w1MDhpCb2ByQvmgyDU4qi+6LvA RWKoiDrEqh8KINxvasicSXERv0PhZCkTfqvXHHyJjGswh5dK1ZWue0f3/BjWsv78CqgJ QtXA== 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=YqgNZ+skOW1X/1tb0MZDeUqm0xdW+CN0YoSfRFfhG5g=; fh=QZniyVMMS+qc7OJnE11H0+VIi5BgZHbLL5e39gUA1jg=; b=a1B7vpw43TNJ/zv7VTd2OOSkkZcWPUYVXVNOG+uwCUGz+iq6uG7C/k46IcKsVFEJtW my7FvnbyJ6eew682e2wLSrPO4EY/yH1iY5IrSwdjw0nbMxkh1ZAITbTKqjjv/sV86aM8 91BvoeWLtJyH/Wqv2bkPXITEktE9QC0yQ8y9qJ8P6jEbVPTlB8xrHGPnmPyc16tKW8D8 aLbPbcabvB0tN8VHZip+HNjkVZ3WybLjxGaz3DtwPn3c5uoYUQBHyf/64I0hMaytcq8F OTUu9MTVBjksV82bblSWXurA1eqee/qqYb2EYtopGhwv33Zp4Bm9ZIAzhh0xjUN3ywBa M9EQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qfMWcqXQ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-41678-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41678-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id hu11-20020a056214234b00b0067f0540d19asi5647013qvb.444.2024.01.28.08.06.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 08:06:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-41678-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qfMWcqXQ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-41678-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41678-linux.lists.archive=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 AE1F21C217E7 for ; Sun, 28 Jan 2024 16:06:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 926AE2C6BA; Sun, 28 Jan 2024 16:06:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qfMWcqXQ" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B37B32E644; Sun, 28 Jan 2024 16:06:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706457972; cv=none; b=mDe7Fm+MLDygoinMqoVydFBKYTa6dheuWwcmjK1vTmPM9UGgATITtsI1WXReLppsRNDloZALV+Eaep2NFBokCIeGWZZdkN19iTPOlRUGwCkLvHDqgxnJDzhSw18MxpUX4qdPKsYJq3NzFMUb+2AJ24qdjmsHcO1L2/pwzCQUkXo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706457972; c=relaxed/simple; bh=1UnqaSq6US/sXw4AotStqr/RUKhvvYzhNHwicWeq4pM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M3N3Bz+2ouBQ++XLHf2K7A0Sx7SLmii5qKHjPOC19xRIGB4wHf47vTnzKkWU8ZrUrHQKKayRLGLYFsbCxd/fpxXINihazidr3/J10Ui+a6uFDyMBwO55O85Bl3N5C7ozb7SdcW3/aelpDDn1AKKUh/KLlXZ7m4L8+8yeeWf26i0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qfMWcqXQ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BA3CC43394; Sun, 28 Jan 2024 16:06:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706457972; bh=1UnqaSq6US/sXw4AotStqr/RUKhvvYzhNHwicWeq4pM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qfMWcqXQJuyNNX7HTwLclM8TLDtUP6uRfAE1TNMORFXG8gztAiXwty3tUBRAD6G2w 1UEZwjtVgOM+bZFNxdcukilsqEA6dzQ+Qq70YCR/Ze57qbGW10O/CkLpgbP65ElTaC dDwM85Z+swUBxO5/RquDc23ErRWPiFKm3njXeRm8YNbQcN4Foi7Bg275xOCzOE+/me MX3NURYzHj/GYCcWB5bRqzifBc80oe7k84cb5kX8pdLuXgaR+KdC8Yq9yX2WIY1QvA lzaJUBfoTwrHZKwVCAOVVELKTozQl8zKw2kV4rKZWvgZ9NS9zM1Cnda79ZcqPjLOLZ V3O5iVUHsBbBQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org, Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org Cc: Julia Lawall , Nicolas Palix , Sumera Priyadarsini , "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , =?UTF-8?q?Nuno=20S=C3=A1?= , Jonathan Cameron Subject: [RFC PATCH 2/5] of: Introduce for_each_child_of_node_scoped() to automate of_node_put() handling Date: Sun, 28 Jan 2024 16:05:39 +0000 Message-ID: <20240128160542.178315-3-jic23@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240128160542.178315-1-jic23@kernel.org> References: <20240128160542.178315-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Jonathan Cameron To avoid issues with out of order cleanup, or ambiguity about when the auto freed data is first instantiated, do it within the for loop definition. The disadvantage is that the struct device_node *child variable creation is not immediately obvious where this is used. However, in many cases, if there is another definition of struct device_node *child; the compiler / static analysers will notify us that it is unused, or uninitialized. Signed-off-by: Jonathan Cameron --- include/linux/of.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/linux/of.h b/include/linux/of.h index 50e882ee91da..f822226eac6d 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1434,6 +1434,12 @@ static inline int of_property_read_s32(const struct device_node *np, for (child = of_get_next_available_child(parent, NULL); child != NULL; \ child = of_get_next_available_child(parent, child)) +#define for_each_child_of_node_scoped(parent, child) \ + for (struct device_node *child __free(device_node) = \ + of_get_next_child(parent, NULL); \ + child != NULL; \ + child = of_get_next_available_child(parent, child)) + #define for_each_of_cpu_node(cpu) \ for (cpu = of_get_next_cpu_node(NULL); cpu != NULL; \ cpu = of_get_next_cpu_node(cpu)) -- 2.43.0