From nobody Wed Sep 17 03:40:56 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 62FB9C4332F for ; Fri, 23 Dec 2022 07:24:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230177AbiLWHYc (ORCPT ); Fri, 23 Dec 2022 02:24:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229603AbiLWHY2 (ORCPT ); Fri, 23 Dec 2022 02:24:28 -0500 Received: from mail.nfschina.com (mail.nfschina.com [124.16.136.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CBB92658A; Thu, 22 Dec 2022 23:24:27 -0800 (PST) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id 785B51E80DA0; Fri, 23 Dec 2022 15:19:16 +0800 (CST) X-Virus-Scanned: amavisd-new at test.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (mail.nfschina.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FMh5p-cEkS2V; Fri, 23 Dec 2022 15:19:13 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: kunyu@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id 419D41E80D96; Fri, 23 Dec 2022 15:19:13 +0800 (CST) From: Li kunyu To: alex.williamson@redhat.com, cohuck@redhat.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Li kunyu Subject: [PATCH] vfio_iommu_type1: increase the validity check of function parameters Date: Fri, 23 Dec 2022 15:24:18 +0800 Message-Id: <20221223072418.3728-1-kunyu@nfschina.com> X-Mailer: git-send-email 2.18.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Added validity check for count variable, return if count variable does=20 not meet the execution condition (do not execute mutex_lock and=20 mutex_unlock function). Signed-off-by: Li kunyu --- drivers/vfio/vfio_iommu_type1.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type= 1.c index 23c24fe98c00..9bdf96d932e4 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -3137,6 +3137,9 @@ static int vfio_iommu_type1_dma_rw(void *iommu_data, = dma_addr_t user_iova, int ret =3D 0; size_t done; =20 + if (count <=3D 0) + return ret; + mutex_lock(&iommu->lock); while (count > 0) { ret =3D vfio_iommu_type1_dma_rw_chunk(iommu, user_iova, data, --=20 2.18.2