From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 E9B5223F291 for ; Tue, 19 Aug 2025 16:01:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755619313; cv=none; b=QaVA6TPAFXJhKdR0bvsfI2nkzuM0biYrcAZYkef8gXg/koGCz7D3HnwZp+KT/bvoxudLr8tiHqBaz1Tx8aq8kzjDzKoeR1Kpjg9lQpjbTuSD/b5yXDHXjDCSqcjVywtZI1cf3JBJ7V4HqrqSlArOkr6qFPmtPCxKzKUWf2752xU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755619313; c=relaxed/simple; bh=fZ6+GjKEmyeibVijbqOoSe4XZ2Q+y84drPEeFaIZNNA=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DTf7aDypQM+ak2j1d7VTV3EEpe3GVO8zxRJxFMmuoYIkuYcON5fS4+8FTz9dgmLCZtjO8/TnvVNwxCkY8nm2+7ohxlEG4aWh03IHVStguBRcp5JJ+eyrA0D6FMsUlYJ6CW9iUEuBvtAtqkhk72yuO1AB31bR3m14BABsaKRiff0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=b5FCqyVA; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="b5FCqyVA" Received: by mail.gandi.net (Postfix) with ESMTPSA id 27D8B4432F; Tue, 19 Aug 2025 16:01:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1755619302; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ltpNMif16os2+Ik15uMFCGv0wNTw+E/lpUi+uydO/XY=; b=b5FCqyVAX8LmMpQZDLg2qoroHaf7LnQSIkv96cIxOlz7XoGvYEjX3b9L+xkYLPrC6aqSx2 QU4Rzd73UEjSwGcl7fllMe17Ke9Bn48ahV3HDzYBQCgvZZxUb75pGYy+MDjjCxAweKCJ2p sqNxJ1VX9FHQ5leEOnuqw/Huwm9OdpsyjbdoOf814+vNOES62kW/XK37tiuZh7BL8CBeEv EtKxVRK7b6v76qkrpvrY7bujRPu2jcBayT0GejagkjxenTZT8rEal905FuD6pK4UMaRfh3 SiXXyIKH/pr/Y9WQ3ikxHRZY1EfvQ1fc1AIlhE4Phz+vdZ8PDpMPGtaNJ5/7lA== Date: Tue, 19 Aug 2025 18:01:37 +0200 From: Luca Ceresoli To: Maxime Ripard Cc: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Thomas Zimmermann , David Airlie , Simona Vetter , Miguel Ojeda , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Tomi Valkeinen , Dmitry Baryshkov , Chaoyi Chen , Hui Pu , Thomas Petazzoni , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH v2 3/9] drm/bridge: add drm_for_each_bridge_in_chain_scoped() Message-ID: <20250819180137.28ca89c0@booty> In-Reply-To: <7gpqrxlxxuarbp5b7bycukbbjdcuonlhn4zm6xinnrlqzrbeu7@rrpcwxnxxrag> References: <20250808-drm-bridge-alloc-getput-for_each_bridge-v2-0-edb6ee81edf1@bootlin.com> <20250808-drm-bridge-alloc-getput-for_each_bridge-v2-3-edb6ee81edf1@bootlin.com> <7gpqrxlxxuarbp5b7bycukbbjdcuonlhn4zm6xinnrlqzrbeu7@rrpcwxnxxrag> Organization: Bootlin X-Mailer: Claws Mail 4.3.1 (GTK 3.24.49; x86_64-redhat-linux-gnu) Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdduheehledvucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfgjfhhoofggtgfgsehtjeertdertddvnecuhfhrohhmpefnuhgtrgcuvegvrhgvshholhhiuceolhhutggrrdgtvghrvghsohhlihessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnhepgeelffefgfehhfdtvdefueefieevkefggfelkeeiudetkeektedvhedukefgvddvnecuffhomhgrihhnpegsohhothhlihhnrdgtohhmnecukfhppedvrgdtvdemieejtdemvddtvddtmegvrgdtudemsggvgedumeelhegvjeemfeegfeemledufegvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdgrtddvmeeijedtmedvtddvtdemvggrtddumegsvgegudemleehvgejmeefgeefmeeludefvgdphhgvlhhopegsohhothihpdhmrghilhhfrhhomheplhhutggrrdgtvghrvghsohhlihessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvdegpdhrtghpthhtohepmhhrihhprghrugeskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprghnughriigvjhdrhhgrjhgurgesihhnthgvlhdrtghomhdprhgtphhtthhopehnvghilhdrrghrmhhsthhrohhngheslhhinhgrr hhordhorhhgpdhrtghpthhtoheprhhfohhssheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepnfgruhhrvghnthdrphhinhgthhgrrhhtsehiuggvrghsohhnsghorghrugdrtghomhdprhgtphhtthhopehjohhnrghssehkfihisghoohdrshgvpdhrtghpthhtohepjhgvrhhnvghjrdhskhhrrggsvggtsehgmhgrihhlrdgtohhmpdhrtghpthhtohepmhgrrghrthgvnhdrlhgrnhhkhhhorhhstheslhhinhhugidrihhnthgvlhdrtghomh X-GND-Sasl: luca.ceresoli@bootlin.com Hi Maxime, On Tue, 19 Aug 2025 15:47:06 +0200 Maxime Ripard wrote: > > +/** > > + * drm_for_each_bridge_in_chain_scoped - iterate over all bridges attached > > + * to an encoder > > + * @encoder: the encoder to iterate bridges on > > + * @bridge: a bridge pointer updated to point to the current bridge at each > > + * iteration > > + * > > + * Iterate over all bridges present in the bridge chain attached to @encoder. > > + * > > + * Automatically gets/puts the bridge reference while iterating, and puts > > + * the reference even if returning or breaking in the middle of the loop. > > + */ > > +#define drm_for_each_bridge_in_chain_scoped(encoder, bridge) \ > > + for (struct drm_bridge *bridge __free(drm_bridge_put) = \ > > + drm_bridge_chain_get_first_bridge(encoder); \ > > So my understanding is that the initial value of bridge would be cleaned > up with drm_bridge_put... > > > + bridge; \ > > + bridge = drm_bridge_get_next_bridge_and_put(bridge)) > > ... but also when iterating? > > So if we have more than 0 values, we put two references? No, this is not the case. The __free action is executed only when exiting the entire for loop, not a single iteration. This is consistent with the fact that the loop variable is persistent across iterations. I tested this macro in both cases: * looping over the entire chain the final value of @bridge will be NULL and the cleanup action won't call drm_bridge_put() * breaking before the last element, @bridge is non-NULL and the cleanup action does call drm_bridge_put() See examples such as for_each_child_of_node_scoped() and other OF iterators which work in the same way (which is no coincidence, I used them as starting point for writing this patch). Best regards, Luca -- Luca Ceresoli, Bootlin Embedded Linux and Kernel engineering https://bootlin.com