Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp706466pxv; Thu, 15 Jul 2021 14:02:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuUq41V4Dajy++IiJ0ZIesLTmIPvEmafIy2TdC7N5n2m1IEpVqgHoEbqJSgwslWmxY3HkI X-Received: by 2002:a05:600c:4f96:: with SMTP id n22mr6552821wmq.137.1626382924457; Thu, 15 Jul 2021 14:02:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626382924; cv=none; d=google.com; s=arc-20160816; b=tsEizx/56GiMccr8fcFvGwoe9yJ8Mu0v39Z1meZClbm8ZwmWmxE27B9DhsKjxXSGf4 a70ra6XGoWkTn8NALyhU0hefTMHCgDL3Sk1fDCi9bJoQywZnodQLjA6eDfbNoJ+bj0ht ihIvoW11DxSBihsvGUocAJ1PYRqmpMZoEIvqN6siIfhtAyCYh+mSsHduf+oKB0NNBRu7 OH5BY6dxZvUAY3wgCjn29iZ+R8z5nxh9g8leDetCEGWuP3SitI4OyX3Q0f062VZm0Cpp rQEhNXfQ6izUOiivo6bMfVhpLk5CaR9EA2jIGRbR4ewvL98KM9NXGkonyoMkUFGtObaD RiaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=wWprxpQbGfLFSl5wy/zhotLOA6ZrkLS6haFDYZBjiv4=; b=zm+/NG7c3gl0mySKbuzIuCbgXFTuVbw8qiTkW7I0niwUO3nOiSY2N8Fq11NphWeB8o oTLSWD9ctBdH3i/gd8UO5ieO0XzMXgXsaJHV+QP1G6AdQfqGKow9w9+mQ1DqehGgmPFN /Y8wY5Z/YlE/NVYaa+2uOxILIBIFoaut945eXSW62l9k+Y5NfUNW6HKoOQgfn2+jj0qN 8JQ/qb0YQkVRcHel5Tl/l0exyW2xG/cX1so1KAYMyXi53H9zobB0s4aM96sMQXagmpHT Y2FHFu7w3JU7ppQ4VQ/u/F/g21c9H2lVJZxjG2UhiqQzAfyJSZgUXNVLZXqRrfHIdZQz csaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=Spw0vcPu; 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=pass (p=NONE sp=NONE dis=NONE) header.from=deltatee.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u18si8392869ejk.196.2021.07.15.14.01.40; Thu, 15 Jul 2021 14:02:04 -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; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=Spw0vcPu; 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=pass (p=NONE sp=NONE dis=NONE) header.from=deltatee.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234792AbhGOQtM (ORCPT + 99 others); Thu, 15 Jul 2021 12:49:12 -0400 Received: from ale.deltatee.com ([204.191.154.188]:49988 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233883AbhGOQtE (ORCPT ); Thu, 15 Jul 2021 12:49:04 -0400 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==; 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 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: 8bit 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) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, struct scatterlist *sg, else ents = ops->map_sg(dev, sg, nents, dir, attrs); + WARN_ON_ONCE(ents == 0); + if (ents > 0) debug_dma_map_sg(dev, sg, nents, ents, dir); @@ -251,9 +253,7 @@ int dma_map_sgtable(struct device *dev, struct sg_table *sgt, int nents; nents = __dma_map_sg_attrs(dev, sgt->sgl, sgt->orig_nents, dir, attrs); - if (nents == 0) - return -EINVAL; - else if (nents < 0) + if (nents < 0) return nents; sgt->nents = nents; -- 2.20.1