From nobody Tue Oct 7 15:11:16 2025 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.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 B679E221710 for ; Wed, 9 Jul 2025 16:48:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752079729; cv=none; b=DOs8tbj1HZD0kTCivy2dKwRDwpfA8n9AUjC94DaUtQE8CEF/5KNEz0W732wWVnhnjRtSYrAhozn1feBh+GK+rI6zJYExYX2bTqjF7PNGWo54IoF4OmxTP/YjbYGPnEc7RXeymwHH/fY4K8Bw1SOTeSgyO5LgE/nlMdCEN61VVeg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752079729; c=relaxed/simple; bh=K+9FS2HHVmjkdc1hzhayoRBZfMnOI3uK97+JhhGSHPE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YF7epX2M4bVCDMuXNk4rVpnwYqMWshzl7WrNtrE1RWKiukoDC9VdQe/JIZOnfZq7XwCfPW9A0VWYFSHhZNRxXLWA5KdWlQp/foCWcnf9K0KL516Hk2Mpi9QLdNUWY7LumAANLwfwYRbPWeN+SDMB/bqKTWejtVgwu6Ti5GuVNSo= 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=nHbcYCzw; arc=none smtp.client-ip=217.70.183.201 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="nHbcYCzw" Received: by mail.gandi.net (Postfix) with ESMTPSA id 68189433D0; Wed, 9 Jul 2025 16:48:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1752079724; 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=sWfeXEz8KDLHWjQYxooMx54UR6soGrocC4j3PLR2M1Q=; b=nHbcYCzwnJhX7BuiBkiCk6mAwckkqlIc2aKGzaeZOTjKePKivXO+qX3ImmvSm/+9dn3kMJ CnFmHOWLjW6zDpHNyNENro1voOALWm7mG3hFPG9Z36mOzlj+pwmuh9bDzvZ/LnBqrbcKqL RbPG0Bp75v9tJTt0F2Q/Jcx89xILN7kESQGhFnqyiH7d0zuJn0OBXGD0OZoxU9wfFiEvuQ +MWWcnjLn+797jcxoxpU4kEbdacunxPLtnKBbuq10xRLbrhy80A/Ep0WC6qAHdak5jQWGr 3BVnD/q6tXfsBzs+aypp6NwBHsSOwlzdCFYjiv0UqPEYhOJ6WS+H6RxR+PlqMg== From: Luca Ceresoli Date: Wed, 09 Jul 2025 18:48:00 +0200 Subject: [PATCH 1/9] list: add list_last_entry_or_null() 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 Message-Id: <20250709-drm-bridge-alloc-getput-drm_bridge_get_next_bridge-v1-1-48920b9cf369@bootlin.com> References: <20250709-drm-bridge-alloc-getput-drm_bridge_get_next_bridge-v1-0-48920b9cf369@bootlin.com> In-Reply-To: <20250709-drm-bridge-alloc-getput-drm_bridge_get_next_bridge-v1-0-48920b9cf369@bootlin.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Liu Ying , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Tomi Valkeinen , Philipp Zabel Cc: Hui Pu , Thomas Petazzoni , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Luca Ceresoli , Andy Shevchenko , Andrew Morton , Zijun Hu , Greg Kroah-Hartman X-Mailer: b4 0.14.2 X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdefkedtkecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpefnuhgtrgcuvegvrhgvshholhhiuceolhhutggrrdgtvghrvghsohhlihessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnhepieeiuedvffetgfeuudelheeutefggfejieettdetteekueeuueeukeevvedvueevnecukfhppeekjedruddvtddrvddukedrvddtjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeekjedruddvtddrvddukedrvddtjedphhgvlhhopegludelvddrudeikedruddrudefngdpmhgrihhlfhhrohhmpehluhgtrgdrtggvrhgvshholhhisegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopedvledprhgtphhtthhopehtiihimhhmvghrmhgrnhhnsehsuhhsvgdruggvpdhrtghpthhtohepihhmgieslhhishhtshdrlhhinhhugidruggvvhdprhgtphhtthhopefjuhhirdfruhesghgvhhgvrghlthhhtggrrhgvrdgtohhmpdhrtghpthhtohepthhomhhirdhvrghlkhgvihhnvghnsehiuggvrghsohhnsghorghrugdrtghomhdprhgtphhtthhopehvihgtthhorhdrlhhiuhesn higphdrtghomhdprhgtphhtthhopehshhgrfihnghhuoheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepthhhohhmrghsrdhpvghtrgiiiihonhhisegsohhothhlihhnrdgtohhmpdhrtghpthhtohepphdriigrsggvlhesphgvnhhguhhtrhhonhhigidruggv X-GND-Sasl: luca.ceresoli@bootlin.com Add an equivalent of list_first_entry_or_null() to obtain the last element of a list. Signed-off-by: Luca Ceresoli --- Cc: Andy Shevchenko Cc: Andrew Morton Cc: Zijun Hu Cc: Greg Kroah-Hartman --- include/linux/list.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/list.h b/include/linux/list.h index e7e28afd28f8eef94ab6baec77e69ea104ba0391..7f7657e416209a2941b3f292b13= 34e9e0f2a3ca5 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -636,6 +636,20 @@ static inline void list_splice_tail_init(struct list_h= ead *list, pos__ !=3D head__ ? list_entry(pos__, type, member) : NULL; \ }) =20 +/** + * list_last_entry_or_null - get the last element from a list + * @ptr: the list head to take the element from. + * @type: the type of the struct this is embedded in. + * @member: the name of the list_head within the struct. + * + * Note that if the list is empty, it returns NULL. + */ +#define list_last_entry_or_null(ptr, type, member) ({ \ + struct list_head *head__ =3D (ptr); \ + struct list_head *pos__ =3D READ_ONCE(head__->prev); \ + pos__ !=3D head__ ? list_entry(pos__, type, member) : NULL; \ +}) + /** * list_next_entry - get the next element in list * @pos: the type * to cursor --=20 2.50.0