From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 29858C83F0A for ; Wed, 9 Jul 2025 21:58:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=sWfeXEz8KDLHWjQYxooMx54UR6soGrocC4j3PLR2M1Q=; b=ZgkrW5DlY0D5g9tjgVIi0gTi5+ CKKo8UD46j/MDP9HoNe59Pt9jMVJCaCig4pUD5EqIpIRGkcnVK4WpzEzDXYoXcHqq409+zsOYB9G0 QJGauRR4TOHOuTTSLzI6I60ipDHUlE3915vSFsJ7EGQ7wEDTjzK93wxTFuRMIEWqvGQdpcvmJ0dqA FSOBPAFp51gfVelgrUm3CXFMP46AOZ41HBRLANOppVB0phxj6IRJk7l1f5zF0SZli8Pw1RIJDSMGi 6SntFcWWnLFo3Z53yLAjJ+90C0gfc0UpRlEpyT99HgB4s/prjS9a0OcZ5K4k9J7aI97D6FcmWLysa aWSR6FuA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uZcoA-00000009xNK-1VOm; Wed, 09 Jul 2025 21:58:31 +0000 Received: from relay8-d.mail.gandi.net ([2001:4b98:dc4:8::228]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uZXyR-00000009LmH-2cX3 for linux-arm-kernel@lists.infradead.org; Wed, 09 Jul 2025 16:48:49 +0000 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() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250709_094847_820301_8E5023AD X-CRM114-Status: GOOD ( 12.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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..7f7657e416209a2941b3f292b1334e9e0f2a3ca5 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -636,6 +636,20 @@ static inline void list_splice_tail_init(struct list_head *list, pos__ != head__ ? list_entry(pos__, type, member) : NULL; \ }) +/** + * 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__ = (ptr); \ + struct list_head *pos__ = READ_ONCE(head__->prev); \ + pos__ != head__ ? list_entry(pos__, type, member) : NULL; \ +}) + /** * list_next_entry - get the next element in list * @pos: the type * to cursor -- 2.50.0