Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp218038rdb; Sun, 28 Jan 2024 22:55:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKUyjSgGLltSyNKIeFO7JQRlwnPk0ZrAJSvjHtrz6IgjsHl/5aK6NmCvI0uyRxqsNqD9rn X-Received: by 2002:a17:906:48d1:b0:a35:a018:6bc9 with SMTP id d17-20020a17090648d100b00a35a0186bc9mr2067719ejt.63.1706511330966; Sun, 28 Jan 2024 22:55:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706511330; cv=pass; d=google.com; s=arc-20160816; b=eM0mL34F1JosL4qWLRZI+I6qRI5esM23Z/2JztnDtdfKphRyY54xdpp/M0cQshM2oO QhwqujCNWfsoAzkRG08difk0axBgcGCjJUJ5KsoGnJqMB6hjCsXtXpfkTyDk218UW7ef gNLTNIF14Y1DnKAASNwYYYb0r6hfUp6Wz4u+GK36wnbZ9Rr14j93Xe1qgmz4tfsSTEoP TrxKudlGCuY0miQpT4iVhUMAqpCc84cpluQk0qEG4pVoyEyTIu8wi9yTwAyRNkEEh++a vtWfY7YAuUF1sdopvzIz7lfDYmhF3U/q93jDAzlZyZiE4VgV6xR8y1NZy6Xg3Yy9L0nc 02mw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:references:message-id:in-reply-to:subject:cc:to:from :date:dkim-signature; bh=/vK4mdK7puxw3rS5CIKuzcUkW3pOhOeAoQxmK8/bCoo=; fh=X1VPYQ8F7hSv8IVFGwoDGAqLsn8QeuqNuLBGTFi3MBE=; b=uS22GWiRoEEGUtnrbwCquQv3JTV2TXWvgnQXFlGWWu+fxdOtEjD0uhebTsac8aEo2U 6a1pbLOxm/M5ygwuLbuclQRpH8jr9kIS21xgVC96zIxX+IvNwWJFTfSa8TBs9jOy5R+t x4p0oTZHUImF6HkxY/sLktKJMtbAbVefnlEm+1FVPCy2aOFFWhsWeUXTjF04HK+fU7R1 95G15eH1I7/O4EmhsLwSC4KNXkXvIxocEWiSmhGeANZTBQd/j2CSutAAdFRVqombRA57 7la7ubH5j1RJU9rfQ9v11/wiJPrDe5/M9ZpZfkwtm9SMK0imnUx+EvTDshcbK48af4OG 91rA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=QQF2gEPW; arc=pass (i=1 spf=pass spfdomain=inria.fr dkim=pass dkdomain=inria.fr dmarc=pass fromdomain=inria.fr); spf=pass (google.com: domain of linux-kernel+bounces-42266-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42266-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=inria.fr Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ca21-20020a170906a3d500b00a35e1563f75si167085ejb.253.2024.01.28.22.55.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:55:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42266-linux.lists.archive=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=@inria.fr header.s=dc header.b=QQF2gEPW; arc=pass (i=1 spf=pass spfdomain=inria.fr dkim=pass dkdomain=inria.fr dmarc=pass fromdomain=inria.fr); spf=pass (google.com: domain of linux-kernel+bounces-42266-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42266-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=inria.fr 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 B6CB01F237CB for ; Mon, 29 Jan 2024 06:55:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 43C694D583; Mon, 29 Jan 2024 06:55:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=inria.fr header.i=@inria.fr header.b="QQF2gEPW" Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) (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 7BEA54E1CF; Mon, 29 Jan 2024 06:55:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.134.164.83 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706511311; cv=none; b=CYhXelpA502bBJrTm4Lrs/cnLQISd8kHNfkq1pp4mCwET4OnDutDKjWrTghtmMzUcpmzCH7t9MuE3BagQho9kBgE3Wo1DHUWAKZGjVZDuRWI85MWnWGUoFWyFJh73NcStooEMW7clKeMWg3K9v36VWrMriAbJNVXbvCDvXvPBR4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706511311; c=relaxed/simple; bh=QxPFzwiC832gHBvsrc8uTvj7SV6ybIfVQEvlV8pe4K0=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=hHO/E1yCf14+o+epXfmh5/12jqe+TltuEFoDirbtsySFejSwANhz66blAd23dPzwqtFplWx8K9JFGICp4atQNALzjqenDJ7CfRk53emSQUdLhZEkbd2EfwSB8pWPfnKWzzMxcll+SQENU4jKaW0Kpda3mV9eKKnkfvkV67VaBPI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=inria.fr; spf=pass smtp.mailfrom=inria.fr; dkim=pass (1024-bit key) header.d=inria.fr header.i=@inria.fr header.b=QQF2gEPW; arc=none smtp.client-ip=192.134.164.83 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=inria.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=inria.fr DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=/vK4mdK7puxw3rS5CIKuzcUkW3pOhOeAoQxmK8/bCoo=; b=QQF2gEPWROMVJ3W0BFwbJvQi+G8tacNtEPzvU2ZDvfyD5BCEo5deJrHE Rxv6Z3pwCwzwPiOAY6zNAOHHvpqwbitiWYZb/q+adZDQ4aDY+0FdFadWf LlsZzAgbhBU9gQbKdDz6In89cW+RXFIhQPNW+Z/SmhbxHqeaBJ+UjWoYo A=; Authentication-Results: mail2-relais-roc.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=julia.lawall@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="6.05,226,1701126000"; d="scan'208";a="149064864" Received: from 231.85.89.92.rev.sfr.net (HELO hadrien) ([92.89.85.231]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2024 07:54:58 +0100 Date: Mon, 29 Jan 2024 07:54:57 +0100 (CET) From: Julia Lawall X-X-Sender: jll@hadrien To: David Lechner cc: Jonathan Cameron , 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 , =?ISO-8859-15?Q?Nuno_S=E1?= , Jonathan Cameron Subject: Re: [RFC PATCH 2/5] of: Introduce for_each_child_of_node_scoped() to automate of_node_put() handling In-Reply-To: Message-ID: References: <20240128160542.178315-1-jic23@kernel.org> <20240128160542.178315-3-jic23@kernel.org> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8323329-1061988734-1706511298=:3150" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-1061988734-1706511298=:3150 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT On Sun, 28 Jan 2024, David Lechner wrote: > On Sun, Jan 28, 2024 at 10:06 AM 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 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)) > > 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. > > 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(). There are a bunch of iterators, and I guess a scoped version is needed for each of them? julia > > > > + > > #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 > > > > > --8323329-1061988734-1706511298=:3150--