Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2037345rdb; Sun, 4 Feb 2024 11:56:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFXcCKJDnBGhyz7eSyJiDAw1ihygs9vt7++SE2EVIOh2CB4hTSgg4Lxp3XUUGT3cRrA2qqk X-Received: by 2002:a17:903:22c9:b0:1d9:b877:e7a0 with SMTP id y9-20020a17090322c900b001d9b877e7a0mr991674plg.43.1707076615502; Sun, 04 Feb 2024 11:56:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707076615; cv=pass; d=google.com; s=arc-20160816; b=KkgZiAYop9fIWttoZ2avWDvPNas1nsTAxiINXSJynERJLtvuj+INsd/AXi0TqV2ERy L8fZrP+HfpXH0/41XAfSRH2rYo0KBOQk05KcnZkgVZF4kHn0ZK5khj6Q9T5dyu9c7H6J Kl0HagSvHgaheLEHzXSEDoSSoMM/pZj9OqXaf9GdGhX0umk5VrqncvzuVccDunTeX/Ut 5gIZ5uAPrdCpy2IQ0AK9QoynLlHPc9s1ynivsvSblLu0xl7iEi3cMcayMXU85NWP6kbH axAkrNXS3hUwnJSccwjtO2gK+jyW9aTJpv3HjWo2Oq8enGj1/QX3tS0CV2Z5QMy/2G2p 8csQ== 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 :subject:cc:to:from:date:dkim-signature; bh=qFlTPvuBvk+YqVuiqP85Da3wmXHuOp+PFAakosVNEU8=; fh=jrBDz5H415S3+xajkNHk3J0d/b0snakblxEO6nDGVRY=; b=CrHTHkAW/aiQY1jvfYVcJ/bLPObpGyiCxnsBoZ4tNuQtCCOrQTKFORhcMGydEP2hT5 Qzmu4/yZ31uiaClT3C2xM5y+SbNiodVY3zlkWO1NMYonhn9NfPgreQbHJo+Mpbp5W3kL ryfeANNiQhPzM5CYteSFTSoBcyP3wCUDv5zyzm43zQXIdENus8mGg8thVSWi32t7Ow+g aGRhCYjBkncQcOBcP9Aa9ZILNcYtTP4cS2lulJzhJ3hAfg86brGqy2GTmyCiX92Aa4Z1 xxNNmBfRgu6Ig6awdv8KxXq9/1Trm8ykNZLaFcREgfJ0N+t2luGrKxb7j9y2HTK9SIGo BrPw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=T3Oyl7kd; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-51863-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51863-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCVHH+PsQMyvMMa5ltK073+aEdw1NCBzkH2zLcl4lkWClg79td6guQ4Rsdo/pEqexCNW3jLgMEJpacZRcMmkf/BYzP4pbGXDfvQRf25d2Q== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id r20-20020a170902c61400b001d940b83792si4987665plr.574.2024.02.04.11.56.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 11:56:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51863-linux.lists.archive=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=T3Oyl7kd; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-51863-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51863-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id CFB33B2243D for ; Sun, 4 Feb 2024 19:56:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 15B8828DB7; Sun, 4 Feb 2024 19:56:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="T3Oyl7kd" 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 21CCE288D9; Sun, 4 Feb 2024 19:56:26 +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=1707076587; cv=none; b=C0hwGmIUyCkv1kAZ/9kdL8hukqzKeIrABmWY9Ua9IGW8xnJpE4CyuCvvlucXM3EUtnZwYIp2zS0lzxRJNDX3bEq7YG+ws/Fv6pMiVnfutePmDpc9rxzvlM6d3lC4zGD//5tBWc3BCUFBmdiCpxrJEBsVftlQcfCJjHfEisdtFM8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707076587; c=relaxed/simple; bh=G3+CP77UbJCipyCA87pI2FMze2ZRBhHlill3yS+hHpI=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UY7Pz5eU2JoLhgYIlykAwsktzkNtfDvHWYBNKP98JWuxOmJW33Buql4Hn81+oIObQrwpaNOIgOH0Ybzvkzlj/NrmqpGtjbGz5uqN4ASxk9E+9kyuAg3RZsfL4qnolVK+mfkyHKa1CoD1CufAqjObRy3EOtdNfHhmP5Cc5KZ+8aI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=T3Oyl7kd; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3335C43390; Sun, 4 Feb 2024 19:56:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707076586; bh=G3+CP77UbJCipyCA87pI2FMze2ZRBhHlill3yS+hHpI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=T3Oyl7kd0uyQgK+BwaZgUuA/ztfCkYYNnFHtCzEXhfQazojUnDCZNnaxE+HSD61b3 Qumhr29+SuoHio+Jx9YdTU6Ck/KGn4ve3u6o0T4Mi5/wGypryOVdF6rIwkHi0fQSJ6 se5JHhGJ1v1WsRtRpixiCy9q4j+rWIZhuVCNgX5kPKuATBCstjBbfneE8fYwv8xGsg bJ+qcmiFiEnhA5dGST7m4Lhc3GKddjHwZWcW1VtG8kuagf+0HhGsByLK+T9TZkUBQw x+3IM2W8y8cL+oBDLbBJnvxOEUJUoINfjBwR+33TqBAtKJyvD9bZrAk2mEEcQXkrgH GC7uxwJM2FkjQ== Date: Sun, 4 Feb 2024 19:56:11 +0000 From: Jonathan Cameron To: David Lechner Cc: linux-iio@vger.kernel.org, Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org, Julia Lawall , Nicolas Palix , Sumera Priyadarsini , "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , Nuno =?UTF-8?B?U8Oh?= , Jonathan Cameron Subject: Re: [RFC PATCH 2/5] of: Introduce for_each_child_of_node_scoped() to automate of_node_put() handling Message-ID: <20240204195611.2bb6ff58@jic23-huawei> In-Reply-To: References: <20240128160542.178315-1-jic23@kernel.org> <20240128160542.178315-3-jic23@kernel.org> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Sun, 28 Jan 2024 15:11:01 -0600 David Lechner wrote: > On Sun, Jan 28, 2024 at 10:06=E2=80=AFAM Jonathan Cameron wrote: > > > > 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 defini= tion. > > > > 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 str= uct device_node *np, > > for (child =3D of_get_next_available_child(parent, NULL); child= !=3D NULL; \ > > child =3D of_get_next_available_child(parent, child)) > > > > +#define for_each_child_of_node_scoped(parent, child) \ > > + for (struct device_node *child __free(device_node) =3D = \ > > + of_get_next_child(parent, NULL); = \ > > + child !=3D NULL; = \ > > + child =3D of_get_next_available_child(parent, child)) =20 >=20 > Doesn't this need to match the initializer (of_get_next_child)? > Otherwise it seems like the first node could be a disabled node but no > other disabled nodes would be included in the iteration. FwIW that was was entirely unintentional. Not sure how it happened :( Anyhow, now will be for_each_available_child_of_node_scoped() with the right first call. >=20 > It seems like we would want two macros, one for each variation, > analogous to for_each_child_of_node() and > for_each_available_child_of_node(). >=20 >=20 > > + > > #define for_each_of_cpu_node(cpu) \ > > for (cpu =3D of_get_next_cpu_node(NULL); cpu !=3D NULL; \ > > cpu =3D of_get_next_cpu_node(cpu)) > > -- > > 2.43.0 > > > > =20