Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp638909pxj; Fri, 14 May 2021 11:49:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzt8yagvhZ/pN+/RGiGugRQn2338IMoauvjGjo4vzlPipDbB4xpszJ5/m+37GyHA97bH/HZ X-Received: by 2002:a17:906:fccc:: with SMTP id qx12mr6387537ejb.21.1621018140607; Fri, 14 May 2021 11:49:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621018140; cv=none; d=google.com; s=arc-20160816; b=mGGtNFO5ag4qKKr2BBDA1UtxQl2dqlOPpcCIokC5DwVZfFhS09iKQI7ZzW2SlWaDN1 rTjnvN+8SwoPvnao+LRTZMKpyHcm1mtyUNj9haqHAMsN7cloH8rUJRo4wsTSVxkHhRT/ ZV905N58HUyX9MY2EZfkscfnWvrF6J+JT8ZNvaXzhZxMGb3QBdIKDVOlN3RI9WSBz7Me 1xQkOjI2E2qsNf2R4/9kkmg0SL8p7ZKRwKKn0EoGe4XhnmOFREzXeAng5q5X0VFsrO2J AXZIdYfMm0UIYvsLLnHi9lUKnwHzjz9niMIaP+mcCrEe06eui9KwducelBW/0TnViZ1t DLCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=ycf+Ridpmezb3hp6yCOC46HUc2t/NrvYXBs20Gz2ILA=; b=CgMRHnzMZWhaKPnjMriAQGM74SimuWTGW2ZsWjcn4ti8W13qfjGypriNMR66iL+cg+ j4/ZaVtDLI3HhBgoIyXxIuCh7jtrY3cttQBMfrNJ5EGivUHT25CywDRoh4A+n3VzcevK dqjG3scM1/6jslNKB0v3/smCJuSKrFIgjfFiC4hL04yhWYcZkkABotH1/+7kWOGEjk7O fLbmnHvmFVIRPf3R68TYkWJPrsWp5jdp3uRs8ILWxbFuZYotCpCokZGXuloSuew03xZP L/Kg4W1GLseQ8x9/ASW5ostED2YHLTkddLMH3933gABJDMjPXPkrPisIHK2bu/QZu+zc QP3Q== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i8si8454889ejj.74.2021.05.14.11.48.35; Fri, 14 May 2021 11:49:00 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232002AbhENN63 (ORCPT + 99 others); Fri, 14 May 2021 09:58:29 -0400 Received: from verein.lst.de ([213.95.11.211]:50629 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229889AbhENN62 (ORCPT ); Fri, 14 May 2021 09:58:28 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id 176846736F; Fri, 14 May 2021 15:57:13 +0200 (CEST) Date: Fri, 14 May 2021 15:57:12 +0200 From: Christoph Hellwig To: Logan Gunthorpe Cc: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, linux-pci@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org, Stephen Bates , Christoph Hellwig , Dan Williams , Jason Gunthorpe , Christian =?iso-8859-1?Q?K=F6nig?= , John Hubbard , Don Dutile , Matthew Wilcox , Daniel Vetter , Jakowski Andrzej , Minturn Dave B , Jason Ekstrand , Dave Hansen , Xiong Jianxin , Bjorn Helgaas , Ira Weiny , Robin Murphy Subject: Re: [PATCH v2 15/22] dma-direct: Support PCI P2PDMA pages in dma-direct map_sg Message-ID: <20210514135712.GD4715@lst.de> References: <20210513223203.5542-1-logang@deltatee.com> <20210513223203.5542-16-logang@deltatee.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210513223203.5542-16-logang@deltatee.com> User-Agent: Mutt/1.5.17 (2007-11-01) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > + for_each_sg(sgl, sg, nents, i) { > + if (sg_is_dma_pci_p2pdma(sg)) { > + sg_dma_unmark_pci_p2pdma(sg); > + } else { Double space here. We also don't really need the curly braces to start with. > + struct pci_p2pdma_map_state p2pdma_state = {}; > + enum pci_p2pdma_map_type map; > struct scatterlist *sg; > + int i, ret; > > for_each_sg(sgl, sg, nents, i) { > + if (is_pci_p2pdma_page(sg_page(sg))) { > + map = pci_p2pdma_map_segment(&p2pdma_state, dev, sg); > + switch (map) { Why not just: switch (pci_p2pdma_map_segment(&p2pdma_state, dev, sg)) { (even better with a shorter name for p2pdma_state so that it all fits on a single line)? > + case PCI_P2PDMA_MAP_BUS_ADDR: > + continue; > + case PCI_P2PDMA_MAP_THRU_HOST_BRIDGE: > + /* > + * Mapping through host bridge should be > + * mapped normally, thus we do nothing > + * and continue below. > + */ I have a bit of a hard time parsing this comment. > + if (sg->dma_address == DMA_MAPPING_ERROR) { > + ret = -EINVAL; > goto out_unmap; > + } > sg_dma_len(sg) = sg->length; > } > > @@ -411,7 +443,7 @@ int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents, > > out_unmap: > dma_direct_unmap_sg(dev, sgl, i, dir, attrs | DMA_ATTR_SKIP_CPU_SYNC); > - return -EINVAL; > + return ret; Maybe just initialize ret to -EINVAL at declaration time to simplify this a bit?