From patchwork Tue Jul 30 11:11:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 815300 Delivered-To: patch@linaro.org Received: by 2002:a5d:4acf:0:b0:367:895a:4699 with SMTP id y15csp242709wrs; Tue, 30 Jul 2024 04:12:00 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUSaEN1aMgeusfv0ohD8GkDyvfyd+dBUyvnOmA3t7jjEQinp9laNQ7PQk7lZBmnL7MRG8+4dhGQUDJIBge5umX4 X-Google-Smtp-Source: AGHT+IHKDxzl9OBxKt9DgMyqMrsYcTUdessSkJlKxnHPdNR5FeAF6r/UCnr80psvwEKKwHW2pNKO X-Received: by 2002:a50:8713:0:b0:5a1:b0b2:798d with SMTP id 4fb4d7f45d1cf-5b0224ceed5mr6559451a12.25.1722337920039; Tue, 30 Jul 2024 04:12:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1722337920; cv=none; d=google.com; s=arc-20160816; b=cQdTAmNgi2m5YHRsMBPz3kWbVj+/ioPsvQmMRDs22dNKJmXWObSNJJnDBmY1zd8g/e gWxahztWLR69uUNMt8zdS2XzTNl1GDB/CGwdZNodc9Rjdz6dF3rnfZt3+Em5gJkR57So JuTSVsG2f96Xzq2OIgK9wrYdN2Lt6y6kSjLJ2rALdTGooKKKPSNQNIWbJXVEM2VYdb4h /abWqADVGV9mAGOIhN6kJDd7qi0eXQp0mYlkfnEeMs6ovMLGhkSZzkzizHyT+dh94YXW 4C5daL1R1P1AMWF2GWuAxYDldvES+LEpYIsq3YPW9fclixUStqAoUN/cZJL0Zae2QLp7 5P+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=4E+/ky8Pu8U93oZVFfQhvZKQNmIq2Bk7nEvYQhwQRxw=; fh=c60fu1IChZaOc2lQYQAOoRysAfBqXosZh6e58mdWpwk=; b=ytY4k/imiSazf62FhnETDmu0wa7KZibTIWfb9xAQpOJfgEoo/hlmI98fEHcNtxj4g9 /xvM9CUt/x6aCDcVU7OOYImH1FAf48hJ5xnGtD43l0FsbxczHnOF3B1OAi97izPmsScS rURwXdGEhL9cMr3JFblojywsKS3DgXJRFjKs54VkYxjNX2cjwgw9cP7CI2FH5HTFj9bc 1+Ap5/r6S1ElLLA0rDszq/zKV6MdneVFpnPHF72mmT43F8M1WoTdVYjVk4EqcqKVpBB3 LWFEh+TJtECM+55dFYXbVhfnMGaKU9fzI48YSYs00CJWBSLJo5ONLg8IObuC1Du+O+2t 6vyQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5ac65f3c5cbsi7605615a12.561.2024.07.30.04.11.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jul 2024 04:12:00 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C9331887FF; Tue, 30 Jul 2024 13:11:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 98C26887E8; Tue, 30 Jul 2024 13:11:57 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 8F3468780A for ; Tue, 30 Jul 2024 13:11:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 96BCD1007; Tue, 30 Jul 2024 04:12:20 -0700 (PDT) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4CE663F5A1; Tue, 30 Jul 2024 04:11:53 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt , Simon Glass , Sughosh Ganu Subject: [PATCH 1/5] linux: list: add a function to count list nodes Date: Tue, 30 Jul 2024 16:41:28 +0530 Message-Id: <20240730111132.1097315-1-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add a function to count the nodes of a list. Taken from linux 6.11-rc1 tag commit 8400291e289e. Signed-off-by: Sughosh Ganu Reviewed-by: Simon Glass Reviewed-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas --- include/linux/list.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/linux/list.h b/include/linux/list.h index 6910721c00..0f9d939b05 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -547,6 +547,21 @@ static inline void list_splice_tail_init(struct list_head *list, &pos->member != (head); \ pos = n, n = list_entry(n->member.prev, typeof(*n), member)) +/** + * list_count_nodes - count nodes in the list + * @head: the head for your list. + */ +static inline size_t list_count_nodes(struct list_head *head) +{ + struct list_head *pos; + size_t count = 0; + + list_for_each(pos, head) + count++; + + return count; +} + /* * Double linked lists with a single pointer list head. * Mostly useful for hash tables where the two pointer list head is