From nobody Fri Nov 29 22:50:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=deltatee.com ARC-Seal: i=1; a=rsa-sha256; t=1626367606; cv=none; d=zohomail.com; s=zohoarc; b=CeFvwhRQdZUsU/7rjA1EfMuhZj58Z1G/ElgH38CwAfRnwtxM1PQYfZ6KVvHyYNjRWTS5DgV0+y698vYn1qY4NHwWILV2mG4UBR/6G6BY/QURURvzt6EQtai0rBmcbXx+JdUh2HQxq1J0TduyAE3PQaK9aDQNyUVJ3y+vu24ZMgU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1626367606; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wWprxpQbGfLFSl5wy/zhotLOA6ZrkLS6haFDYZBjiv4=; b=d9kYmcS+9UOoiyJt8nHz+q3Ulc6DK6hQBIn0nCbnD0Nx2abmzwdjye3RRbj+B6jTuJaxt5bXbrkbQrSw+QWiCGHWOVwJeb4Iggx5A8jFqUkT7G3O+Z84sTiBs/9YhBUq6BhE6jeXpZE677gYqb+5bfTxiq8cvQ1aBHOCMtYvIsw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1626367606544300.6607174620823; Thu, 15 Jul 2021 09:46:46 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.156733.289298 (Exim 4.92) (envelope-from ) id 1m44VN-0002sx-Fr; Thu, 15 Jul 2021 16:46:33 +0000 Received: by outflank-mailman (output) from mailman id 156733.289298; Thu, 15 Jul 2021 16:46:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1m44VN-0002sY-AE; Thu, 15 Jul 2021 16:46:33 +0000 Received: by outflank-mailman (input) for mailman id 156733; Thu, 15 Jul 2021 16:46:32 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1m44VM-0008SR-DM for xen-devel@lists.xenproject.org; Thu, 15 Jul 2021 16:46:32 +0000 Received: from ale.deltatee.com (unknown [204.191.154.188]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id cb6d9360-c6db-4ff0-971f-a419cd0c309b; Thu, 15 Jul 2021 16:46:11 +0000 (UTC) Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m44Ut-0001yd-PE; Thu, 15 Jul 2021 10:46:04 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.92) (envelope-from ) id 1m44Up-0001nr-Se; Thu, 15 Jul 2021 10:45:59 -0600 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: cb6d9360-c6db-4ff0-971f-a419cd0c309b DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:MIME-Version:References:In-Reply-To: Message-Id:Date:Cc:To:From:content-disposition; bh=wWprxpQbGfLFSl5wy/zhotLOA6ZrkLS6haFDYZBjiv4=; b=Spw0vcPuNWrC1VB/N3ErsY9QsR SVOu2pyWJ/FuZ63VRhkHaNrYGNxmmYIXx9PikhM8TCMmdpKyjBuF9RLs0h5USncTLdFqA8ookOx0G Uh+6hSZ1LQ/AT/6fkMs7I/sWmgeij/QksGHD/wcgAvLgLFIYupGJcECBNvTIejINc9vzRhnt1gvMp d1qv/fQOX1iCowsgU//qvf9zBxNSzcO+QCg8whF/oXVJhQQoSMlgUYlJBgNgtfjNvKiSi4udAIPMg kZkbvAnNQf0F0JxQ/F67quZyGQhReNDhJW14fk20qFpoR28wptyOUDAN3gFjO1yJsvCMWx9e+oRs6 TMj7iEGw==; From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, iommu@lists.linux-foundation.org, linux-parisc@vger.kernel.org, xen-devel@lists.xenproject.org Cc: Christoph Hellwig , Marek Szyprowski , Robin Murphy , Stephen Bates , Martin Oliveira , Logan Gunthorpe Date: Thu, 15 Jul 2021 10:45:44 -0600 Message-Id: <20210715164544.6827-17-logang@deltatee.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210715164544.6827-1-logang@deltatee.com> References: <20210715164544.6827-1-logang@deltatee.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org, linux-ia64@vger.kernel.org, linux-mips@vger.kernel.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-parisc@vger.kernel.org, xen-devel@lists.xenproject.org, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, sbates@raithlin.com, martin.oliveira@eideticom.com, logang@deltatee.com X-SA-Exim-Mail-From: gunthorp@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on ale.deltatee.com X-Spam-Level: X-Spam-Status: No, score=-6.7 required=5.0 tests=ALL_TRUSTED,BAYES_00, MYRULES_NO_TEXT autolearn=no autolearn_force=no version=3.4.2 Subject: [PATCH v1 16/16] dma-mapping: Disallow .map_sg operations from returning zero on error X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) X-ZohoMail-DKIM: pass (identity @deltatee.com) X-ZM-MESSAGEID: 1626367608786100004 Content-Type: text/plain; charset="utf-8" Now that all the .map_sg operations have been converted to returning proper error codes, drop the code to handle a zero return value, add a warning if a zero is returned and update the comment for the map_sg operation. Signed-off-by: Logan Gunthorpe --- include/linux/dma-map-ops.h | 8 +++----- kernel/dma/mapping.c | 6 +++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h index eaa969be8284..f299bc1e317b 100644 --- a/include/linux/dma-map-ops.h +++ b/include/linux/dma-map-ops.h @@ -42,11 +42,9 @@ struct dma_map_ops { unsigned long attrs); /* * map_sg should return a negative error code on error. - * dma_map_sgtable() will return the error code returned and convert - * a zero return (for legacy implementations) into -EINVAL. - * - * dma_map_sg() will always return zero on any negative or zero - * return to satisfy its own calling convention. + * dma_map_sgtable() will return the error code returned by the + * operation and dma_map_sg() will always convert any error to zero + * to satisfy its own calling convention. */ int (*map_sg)(struct device *dev, struct scatterlist *sg, int nents, enum dma_data_direction dir, unsigned long attrs); diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index 30f89d244566..978a6a16aaf7 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -194,6 +194,8 @@ static int __dma_map_sg_attrs(struct device *dev, struc= t scatterlist *sg, else ents =3D ops->map_sg(dev, sg, nents, dir, attrs); =20 + WARN_ON_ONCE(ents =3D=3D 0); + if (ents > 0) debug_dma_map_sg(dev, sg, nents, ents, dir); =20 @@ -251,9 +253,7 @@ int dma_map_sgtable(struct device *dev, struct sg_table= *sgt, int nents; =20 nents =3D __dma_map_sg_attrs(dev, sgt->sgl, sgt->orig_nents, dir, attrs); - if (nents =3D=3D 0) - return -EINVAL; - else if (nents < 0) + if (nents < 0) return nents; =20 sgt->nents =3D nents; --=20 2.20.1