From nobody Thu Dec 18 08:55:10 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA1BEC77B7E for ; Wed, 26 Apr 2023 20:03:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236205AbjDZUDL (ORCPT ); Wed, 26 Apr 2023 16:03:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233321AbjDZUDI (ORCPT ); Wed, 26 Apr 2023 16:03:08 -0400 Received: from smtp.smtpout.orange.fr (smtp-25.smtpout.orange.fr [80.12.242.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5ED5F138 for ; Wed, 26 Apr 2023 13:03:07 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id rlLzpN8gYFuuVrlLzpchLA; Wed, 26 Apr 2023 22:03:05 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1682539385; bh=fL3qIG/GDz0C+Fjp2zZoc/yr7ihwk/lufVhQHBEWF/w=; h=From:To:Cc:Subject:Date; b=S1ordQppoBepkwZ6IrQWXizCESx+DZQYHJ5zfnEcuY1RAug/mq3IyXyMlS7zN0ybj mZUGklz8nU6NGeus1nAPpRzBAjM/J91uGGwrudzKRqTLn2/egj2MEDqBz2nDroQUqy 4M95H14y2HZ3xgHaYoMf08B5MDLcYz20SxFfbgqZrrHxI0Ntpy64XKcDtfYIY/kbjE as8orXJtIxarUoI36RW7BAacOgxuHuXG0FCy9V+nFZslWtY4CA9cpxDZ2dEVPzRMdB GmElCeQfHWK2pLpjB3TAepQa1QpnVzA7koM+VzhH9w8yfRMxzJ4VVGGTvb8TepEcRd mBrkIXTmbXUew== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Wed, 26 Apr 2023 22:03:05 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Joerg Roedel , Will Deacon , Robin Murphy Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , iommu@lists.linux.dev Subject: [PATCH] iommu: Use list_count_nodes() Date: Wed, 26 Apr 2023 22:03:02 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" iommu_group_device_count() really looks the same as list_count_nodes(), so use the latter instead of hand writing it. One uses list_for_each_entry() and the other list_for_each(), but they both count the number of nodes in the list. Signed-off-by: Christophe JAILLET --- Un-tested --- drivers/iommu/iommu.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 91573efd9488..47f0a709380e 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1126,17 +1126,6 @@ void iommu_group_remove_device(struct device *dev) } EXPORT_SYMBOL_GPL(iommu_group_remove_device); =20 -static int iommu_group_device_count(struct iommu_group *group) -{ - struct group_device *entry; - int ret =3D 0; - - list_for_each_entry(entry, &group->devices, list) - ret++; - - return ret; -} - static int __iommu_group_for_each_dev(struct iommu_group *group, void *dat= a, int (*fn)(struct device *, void *)) { @@ -2083,7 +2072,7 @@ int iommu_attach_device(struct iommu_domain *domain, = struct device *dev) */ mutex_lock(&group->mutex); ret =3D -EINVAL; - if (iommu_group_device_count(group) !=3D 1) + if (list_count_nodes(&group->devices) !=3D 1) goto out_unlock; =20 ret =3D __iommu_attach_group(domain, group); @@ -2114,7 +2103,7 @@ void iommu_detach_device(struct iommu_domain *domain,= struct device *dev) =20 mutex_lock(&group->mutex); if (WARN_ON(domain !=3D group->domain) || - WARN_ON(iommu_group_device_count(group) !=3D 1)) + WARN_ON(list_count_nodes(&group->devices) !=3D 1)) goto out_unlock; __iommu_group_set_core_domain(group); =20 --=20 2.34.1