Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8433218imu; Thu, 15 Nov 2018 11:27:44 -0800 (PST) X-Google-Smtp-Source: AJdET5e5WVZl/bp+66fQZQrnKz0RHUmL0MGPk0Ayazi98U52ZQN4STxVjoA6moHvFm5i9v/vi4N2 X-Received: by 2002:aa7:8497:: with SMTP id u23mr3404418pfn.220.1542310064766; Thu, 15 Nov 2018 11:27:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542310064; cv=none; d=google.com; s=arc-20160816; b=bM1LHfSmdpQ5gL3dtJzK27TIVmyULLklr1vmB0cHJ6ywFGFKaoQvjLb9AuaBRn+9Ny 8bNO+vTbF8PTXE4k8EDiPhmiO6vdxjwfNfzryzka1RUmWdP5IvbKi7PTKhm8UuQ9hcLJ DKIADt2QKpZRCDmEuK06d3A9jrtu83/B//HxOANjImvOqXTEtmRTAs/587tFhBeHnzaz D8ida2oXvqTAmKBkKGENLq7VEUXkqPk+qXOBYEt8iqyC7euP5lDXbYBYYe8FdBq7HMVY mfKqQ+m20iMgck4CAmFSIVjEZ3FYVdvTG11AVbVsiDTBvuPqfntfSKSFh2p0GMy6C3L/ A/7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=fYVyUhfwAvSCGiwyhFI8E5SN7ul3gBAy0gxnhlSqdh0=; b=B24pGWqxRQ3kXNBctMNMxGMaFx/s4f8G8zWV5kc64IVsZcDJwMqPQ/hPvObB1rW1RU GqmNApOgRcite1GSNGIZdb2Ex0+jlM14wnZlUx2QgalfbHhieI14qdryZRROOeSnlsHQ bvp4iJUmwkliMMelT4sZ6ikcYpMCqdUgNdjfTOhkxt/NsaO0IW7TXfN5GuHlvJ2ynEY5 mzH63ymiWxiPM5PhDirkG+juSTRnJFH70Ym07ka0/KShzkU3y9WZGRM+J/B213wanWBf IA/cM4G7EgegMyOaVKpuvWfzb8OLMVKvLzk12TCLXFuALHxWi38Tot8oPypwosbddey4 /BRA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h8si9039743plr.343.2018.11.15.11.27.30; Thu, 15 Nov 2018 11:27:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729137AbeKPFeR (ORCPT + 99 others); Fri, 16 Nov 2018 00:34:17 -0500 Received: from smtprelay0179.hostedemail.com ([216.40.44.179]:38812 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725869AbeKPFeQ (ORCPT ); Fri, 16 Nov 2018 00:34:16 -0500 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay06.hostedemail.com (Postfix) with ESMTP id CD391180790B5; Thu, 15 Nov 2018 19:25:10 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::,RULES_HIT:41:355:379:599:800:960:966:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:1801:2196:2199:2393:2553:2559:2562:2828:2897:3138:3139:3140:3141:3142:3353:3622:3865:3867:3872:3873:4321:4385:4605:5007:6119:7514:8603:10004:10400:10848:11026:11232:11473:11657:11658:11914:12043:12048:12296:12438:12555:12679:12740:12760:12895:12986:13439:14181:14659:14721:21060:21080:21451:21627:30054:30090:30091,0,RBL:47.151.153.53:@perches.com:.lbl8.mailshell.net-62.8.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:33,LUA_SUMMARY:none X-HE-Tag: train79_844655162681d X-Filterd-Recvd-Size: 3595 Received: from XPS-9350.home (unknown [47.151.153.53]) (Authenticated sender: joe@perches.com) by omf14.hostedemail.com (Postfix) with ESMTPA; Thu, 15 Nov 2018 19:25:08 +0000 (UTC) Message-ID: <7a3922bc5089dfe0978e07a809606360c74c940c.camel@perches.com> Subject: Re: [PATCH] arch/powerpc: Use dma_zalloc_coherent From: Joe Perches To: Sabyasachi Gupta , benh@kernel.crashing.org, paulus@samba.org, mpe@ellerman.id.au, darren@stevens-zone.net, christophe.leroy@c-s.fr, geoff@infradead.org Cc: Souptick Joarder , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Date: Thu, 15 Nov 2018 11:25:07 -0800 In-Reply-To: References: <5bdfb8db.1c69fb81.c8f62.9586@mx.google.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.30.1-1build1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2018-11-15 at 23:29 +0530, Sabyasachi Gupta wrote: > On Mon, Nov 5, 2018 at 8:58 AM Sabyasachi Gupta > wrote: > > Replaced dma_alloc_coherent + memset with dma_zalloc_coherent > > > > Signed-off-by: Sabyasachi Gupta > > Any comment on this patch? It's obviously correct. You might realign the arguments on the next lines to the open parenthesis. Perhaps there should be new function calls added for symmetry to the other alloc functions for multiplication overflow protection. Perhaps: void *dma_alloc_array_coherent() void *dma_calloc_coherent() Something like --- include/linux/dma-mapping.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 15bd41447025..95bebf8883b1 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -565,6 +565,25 @@ static inline void *dma_alloc_coherent(struct device *dev, size_t size, (gfp & __GFP_NOWARN) ? DMA_ATTR_NO_WARN : 0); } +static inline void *dma_alloc_array_coherent(struct device *dev, + size_t n, size_t size, + dma_addr_t *dma_handle, gfp_t gfp) +{ + size_t bytes; + + if (unlikely(check_mul_overflow(n, size, &bytes))) + return NULL; + return dma_alloc_coherent(dev, bytes, dma_handle, gfp); +} + +static inline void *dma_calloc_coherent(struct device *dev, + size_t n, size_t size, + dma_addr_t *dma_handle, gfp_t gfp) +{ + return dma_alloc_array_coherent(dev, n, size, dma_handle, + gfp | __GFP_ZERO); +} + static inline void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, dma_addr_t dma_handle) { --- > > diff --git a/arch/powerpc/platforms/pasemi/dma_lib.c b/arch/powerpc/platforms/pasemi/dma_lib.c [] > > @@ -255,15 +255,13 @@ int pasemi_dma_alloc_ring(struct pasemi_dmachan *chan, int ring_size) > > > > chan->ring_size = ring_size; > > > > - chan->ring_virt = dma_alloc_coherent(&dma_pdev->dev, > > + chan->ring_virt = dma_zalloc_coherent(&dma_pdev->dev, > > ring_size * sizeof(u64), > > &chan->ring_dma, GFP_KERNEL); > > en > > if (!chan->ring_virt) > > return -ENOMEM; > > > > - memset(chan->ring_virt, 0, ring_size * sizeof(u64)); > > - > > return 0; > > } > > EXPORT_SYMBOL(pasemi_dma_alloc_ring);