Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7077939rdb; Wed, 3 Jan 2024 04:04:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IG/ntBv4K+XsU2DjbBNMNwT9x+IiTzZqFF4OxiCvKIX0d271Gx3olVWyW3T7opIhBMkAXo2 X-Received: by 2002:a05:6214:23cc:b0:680:c792:56a with SMTP id hr12-20020a05621423cc00b00680c792056amr1355507qvb.55.1704283465350; Wed, 03 Jan 2024 04:04:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704283465; cv=none; d=google.com; s=arc-20160816; b=wzaj48WW+KSd+abZBOZmropW9NqivwbkVBpyGGhY4ubefDFeqbd6XOi88atNje2sqw lUdEdVggUWAxjV1vUi/N23G98EUF7F+2sUpvEty1prrcLc85Smge4R6/gezPzInS4J+0 CeDrZXvNRLI/o7EL+tL/z1ezwToR4HJEX4CxUEawpEvkMQ8NAq7bnTLvwkuJ++TKX8Ck FHJv6KtylS4d9/288VXfz+JuYrNB5esM/SlmP+JyM6Yugkg0a+HSA4AIcMRzoGysGelZ HeIv9n1BjMOFeHLKZ9XUc16dQL+gKIGasyVvje8IW8mUBmoehkt6gjupjCd4q4CCj+5F X5Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=KfpvlKMlDB3pUtkeFvtgAaW9bzbJSxUWJFY8KM2bOZI=; fh=8QETM/J1u4ByMIEsyepCRuALkBNmwvF8Gq/Lf5tX0nU=; b=wh3tpyT9uzXfFVkYWsJjqB3cD/W4uCVFgLyl0zVaozVTJKigJyEQXNIOMiH8sG3BR2 RD35znZh/uKJboIp+4GdicBzwYS9t61wavPvDUyUdyrf5RVWAW2ySfHzRVpDN4/7y3/w MSMl1EFR5B6yV9tydizjZoAWpnhGZwBgINmapRIsFiJXSrSd8BZshpGzfJmwXeG1GsnL aPKcZA6QS3ZGIimCNTG6F12/V+a4FsoVpm6gPQ0A64jVxYonyiv26vkCPt7sekAwa2p1 M8/odqcQX+TgqW/BhdyBs07iTQuDgEVdUYeWbk3PVBUMPPMK5XB+laMDpXkuuZq1Lnzb 4i/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-15487-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15487-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d14-20020a0cf0ce000000b0067aa5efad4fsi29400726qvl.192.2024.01.03.04.04.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 04:04:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15487-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-15487-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15487-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 1DDC81C20C3D for ; Wed, 3 Jan 2024 12:04:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 572CB18EB2; Wed, 3 Jan 2024 12:04:20 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DC45018EAA for ; Wed, 3 Jan 2024 12:04:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 3B176C15; Wed, 3 Jan 2024 04:05:03 -0800 (PST) Received: from [10.34.100.129] (e126645.nice.arm.com [10.34.100.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 49BD33F64C; Wed, 3 Jan 2024 04:04:16 -0800 (PST) Message-ID: <2f4a5ea1-daa2-4ede-bdc0-6692d7d52e8c@arm.com> Date: Wed, 3 Jan 2024 13:04:14 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] list: Add hlist_count_nodes() To: Marco Elver Cc: linux-kernel@vger.kernel.org, Kees Cook , Lucas De Marchi , Jani Nikula , Andy Shevchenko , Ingo Molnar References: <20240103090241.164817-1-pierre.gondois@arm.com> Content-Language: en-US From: Pierre Gondois In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hello Marco, On 1/3/24 12:25, Marco Elver wrote: > On Wed, 3 Jan 2024 at 10:02, Pierre Gondois wrote: >> >> Add a function to count nodes in a hlist. hlist_count_nodes() >> is similar to list_count_nodes(). >> >> Signed-off-by: Pierre Gondois > > Is this patch part of another patch series? As-is, this will be dead > code, and there's no guarantee someone will just go and delete it in > future. Although this function looks useful, we also should avoid > adding new dead code. The function is indeed not used in the project right now. I needed it for a private module. If it helps integrating the function and not make it dead code, maybe I could add usages at the following places: - drivers/gpu/drm/drm_hashtab.c::print_binder_node_nilocked() - drivers/md/bcache/sysfs.c::bch_cache_max_chain() Regards, Pierre > >> --- >> include/linux/list.h | 15 +++++++++++++++ >> 1 file changed, 15 insertions(+) >> >> diff --git a/include/linux/list.h b/include/linux/list.h >> index 1837caedf723..0f1b1d4a2e2e 100644 >> --- a/include/linux/list.h >> +++ b/include/linux/list.h >> @@ -1175,4 +1175,19 @@ static inline void hlist_move_list(struct hlist_head *old, >> pos && ({ n = pos->member.next; 1; }); \ >> pos = hlist_entry_safe(n, typeof(*pos), member)) >> >> +/** >> + * hlist_count_nodes - count nodes in the hlist >> + * @head: the head for your hlist. >> + */ >> +static inline size_t hlist_count_nodes(struct hlist_head *head) >> +{ >> + struct hlist_node *pos; >> + size_t count = 0; >> + >> + hlist_for_each(pos, head) >> + count++; >> + >> + return count; >> +} >> + >> #endif >> -- >> 2.25.1 >>