Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp239179pxf; Tue, 6 Apr 2021 20:52:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7XLxV3O7iveBnURQCx1fKbDoiWZ+QAuUl/tSP7zMVLkkd1WcCNvp7m3itJrzmKfzESAll X-Received: by 2002:a17:906:3e97:: with SMTP id a23mr1412109ejj.440.1617767561607; Tue, 06 Apr 2021 20:52:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617767561; cv=none; d=google.com; s=arc-20160816; b=Uv3z6po9evF2T/pi6ukitak2sV8t2HCTa81lbYsCb7O6BUsJqzbsdZEpYzsaM+0HxJ A2F8prlx+SYO9umIavPDLT8GdLN0BDtKjAfT+qfBwY5k5OIUA0c9N5HT5YSU48mG6dW1 5hAc9mbpUliqFePk0YkRMYA0rt8UN8RTeEC+q2fr848IXJ/59LPgt8wEIwFnfZSj0hKy +MviR4kh675w32Dqdl75g2SufI5ipTRwZ7bSCJ9+3uGL9A4df6Nb9vZv9mixr+P0x3Ht ruXdq51Joc70bq11531TiKYsM+FU4USMqUlab7qB4R7t+r6wTezfAWGoG5AJyITjn3uB Ging== 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; bh=ZX+kHvUEkeDmRNgJJMs1cd3LvI4aGgA+s/eRyL2kyZU=; b=fk0+ldhcV1/Zl5M6ujvdMk0DiPjySZ0ERLgEQxWzbZnK59r6T41li7FUl3LdRWiAH+ UvHQ0u5f4kvXmOifNqVObcVPG8CBMd1ZdIRDbY1+Tw9Mhk3lg8gnwB1See5MQ/S+GBFJ LnXpyAJdYGXR/KxS4Yz5EbdfoMIFOejuLY5VOWygmt6jIM0NLf/o0WSMnsTcnfCkoAb7 subpz5nkyVo0O8xhoQSue9/TtB8ZgWHETaq03fU8JD6paFCsFFNNhhZfBOp5dseZvtY6 kqCv1nq522QK+nKhx5t9JNDtjfrYxzB0bevK795Ta0pp8+IGVyKahPk6CtQyvxpsfxBX F6yw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a12si6776741ejk.28.2021.04.06.20.52.18; Tue, 06 Apr 2021 20:52:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244312AbhDFNuf (ORCPT + 99 others); Tue, 6 Apr 2021 09:50:35 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:16001 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244186AbhDFNue (ORCPT ); Tue, 6 Apr 2021 09:50:34 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FF83b4Yz0zPnX8; Tue, 6 Apr 2021 21:47:39 +0800 (CST) Received: from DESKTOP-7FEPK9S.china.huawei.com (10.174.184.135) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.498.0; Tue, 6 Apr 2021 21:50:18 +0800 From: Shenming Lu To: Alex Williamson , Cornelia Huck , , CC: , , Subject: [PATCH v1] vfio/type1: Remove the almost unused check in vfio_iommu_type1_unpin_pages Date: Tue, 6 Apr 2021 21:50:09 +0800 Message-ID: <20210406135009.1707-1-lushenming@huawei.com> X-Mailer: git-send-email 2.27.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.174.184.135] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The check i > npage at the end of vfio_iommu_type1_unpin_pages is unused unless npage < 0, but if npage < 0, this function will return npage, which should return -EINVAL instead. So let's just check the parameter npage at the start of the function. By the way, replace unpin_exit with break. Signed-off-by: Shenming Lu --- drivers/vfio/vfio_iommu_type1.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 45cbfd4879a5..fd4213c41743 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -960,7 +960,7 @@ static int vfio_iommu_type1_unpin_pages(void *iommu_data, bool do_accounting; int i; - if (!iommu || !user_pfn) + if (!iommu || !user_pfn || npage <= 0) return -EINVAL; /* Supported for v2 version only */ @@ -977,13 +977,13 @@ static int vfio_iommu_type1_unpin_pages(void *iommu_data, iova = user_pfn[i] << PAGE_SHIFT; dma = vfio_find_dma(iommu, iova, PAGE_SIZE); if (!dma) - goto unpin_exit; + break; + vfio_unpin_page_external(dma, iova, do_accounting); } -unpin_exit: mutex_unlock(&iommu->lock); - return i > npage ? npage : (i > 0 ? i : -EINVAL); + return i > 0 ? i : -EINVAL; } static long vfio_sync_unpin(struct vfio_dma *dma, struct vfio_domain *domain, -- 2.19.1