From patchwork Wed Apr 26 20:03:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 87975 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp482256vqo; Wed, 26 Apr 2023 13:13:32 -0700 (PDT) X-Google-Smtp-Source: AKy350avBOfMS3z0PmaWnOz/B9wmTZP9GduEdQOQYXec9rQcvh8nOlJ+AIf6vNMLxanNnJ98f2oV X-Received: by 2002:a17:903:1d1:b0:1a6:3c64:513c with SMTP id e17-20020a17090301d100b001a63c64513cmr30174577plh.37.1682540011776; Wed, 26 Apr 2023 13:13:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682540011; cv=none; d=google.com; s=arc-20160816; b=nFzrhoQ3xnQFR8fVaqg6jW+6XdwdoLiLzOKorIlM8/SiigPK78U73KK04gmGd+zU6q qpSVadA0RmjPtc280jywMlAqEEJG+qIXNx+ofHHp0dRfmgoySY/cqPRdcE2kTaaSX2+A MTxVEhwDY0Eg1n1AfoewT3ME+Eu3ob1fovYKXdpm4Obs2igXf++RcrFmjizFs+F1zpu9 pxXatRTj5ryYQyK5wJ1r10L+WwcpgzQ+Kxv2gjAV0yMBvgD2PMnncKo/OPUhedhZ567f WAIOEQwSrSHncMnGMPmNq+V5jMdmqbeG153rgYnt0UH6BS9B76qRyTGDHsWygD6f3GPB alcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=fL3qIG/GDz0C+Fjp2zZoc/yr7ihwk/lufVhQHBEWF/w=; b=HWvWaarDklLwqSowFODiLlo/udG5c6wiv5zh3+4VDcYyYRbgR9DAhxK5XLoxIO5WJ3 iwQMD5uZ+7encMtBrHAcrEu7Y+Ez9VhwjMq8l+fOWeZNzAbQKUipS2OGide7zYKdBxFK JTCZUCAtUGWHIVrSQpX0rpX4vFaFvDHHInUp+iPxUyFx9wpzZXq2q2YJhmo0se71+ceB Plxi5ShoLVtuThH1XPqGc8lvuQFr/gf+HVVF/GJPeUKLtRDCm8HG2VamINcKgiqcIknG 9YujalwTalx7MuAIijUgf+QKgQ5mFYUHQEkbyXLdAR34tuJT85VaEO/Vh0s4hV2jHAjQ bdeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=S1ordQpp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z18-20020a170903019200b001a522569381si17262269plg.301.2023.04.26.13.13.12; Wed, 26 Apr 2023 13:13:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=S1ordQpp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234002AbjDZUDK (ORCPT + 99 others); Wed, 26 Apr 2023 16:03:10 -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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764271075287979997?= X-GMAIL-MSGID: =?utf-8?q?1764271075287979997?= 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); -static int iommu_group_device_count(struct iommu_group *group) -{ - struct group_device *entry; - int ret = 0; - - list_for_each_entry(entry, &group->devices, list) - ret++; - - return ret; -} - static int __iommu_group_for_each_dev(struct iommu_group *group, void *data, 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 = -EINVAL; - if (iommu_group_device_count(group) != 1) + if (list_count_nodes(&group->devices) != 1) goto out_unlock; ret = __iommu_attach_group(domain, group); @@ -2114,7 +2103,7 @@ void iommu_detach_device(struct iommu_domain *domain, struct device *dev) mutex_lock(&group->mutex); if (WARN_ON(domain != group->domain) || - WARN_ON(iommu_group_device_count(group) != 1)) + WARN_ON(list_count_nodes(&group->devices) != 1)) goto out_unlock; __iommu_group_set_core_domain(group);