Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp340443imu; Sat, 17 Nov 2018 00:27:33 -0800 (PST) X-Google-Smtp-Source: AJdET5fTCudKe4cFwOrdEMpixnt/QKMCuSKLxcLRkRJyx5r1Hl0rYoiOJCORqc6mMV4uZOvfiW1H X-Received: by 2002:a65:4142:: with SMTP id x2mr11354041pgp.356.1542443253589; Sat, 17 Nov 2018 00:27:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542443253; cv=none; d=google.com; s=arc-20160816; b=whez5kMDLohjDh1itAemtbhbibml6THQkKak3oULA0mG8a7OJ3TLaUBfvAWUkw5hm/ Jazyz0b/cd4rBoFqX6gZpCt65zQHPLpXFAztNIDdE1xbU5OJ4ivVCq4PkAfs/mwIbGWw cTaLSoSZ60OPjx9X8VSOGn5j26fAShNYwwtMdghRUpP9QXyjYJF0ah7D2djegnUqZIkY 9ddG9eAbO8DONbjvXniVWxMBWGqr+Hhr+R+UajBKVcMDqEEFgaKnzoKSMlrPM9sLaJM9 8hTGAO3wF/JVHtfHvSnCr5F8AkJM+01ymlw5V5qY8G6Oj173xJahbUamdgFTaEtl0eBU 0x+A== 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=6fyLNkyftvgDFzvEnGQ5BJekArTPwKYrw05ElDCtrm8=; b=odCXovQ5E7tZRqu6owjoZGeZh0WwdKMCyBUrsmnbtLTA/VPCDR1ehjlpf7VhtYjrrh 7dwD79T/V2FHdKnhhNSRckD9KJZtnzJ3Bw5ohTbOKHWxS7PZJzQkLe2223Gn9uev2j3O zQSLMAhRqMgG+LqdlaMCEccmmAM5iIPRdWQ3xw70Oz9YS7za4tH0h3nraEqlEgJDAp1O 9ItQltUZyUyy/0P90KeDOjuevZzIniDSB5F4RjHE9nrc+gPI1fD845rNe8R+F8LAnmr3 whcZ9a5ObPJeLdSL+wdXNXFJKN4G35Xto74SezVd7YaRGcJcIT7gG1nI6Lp9wdc0Gp5/ jFpA== 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 p16si14256923pff.272.2018.11.17.00.26.49; Sat, 17 Nov 2018 00:27:33 -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 S1726040AbeKQSki (ORCPT + 99 others); Sat, 17 Nov 2018 13:40:38 -0500 Received: from smtprelay0226.hostedemail.com ([216.40.44.226]:47603 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725981AbeKQSki (ORCPT ); Sat, 17 Nov 2018 13:40:38 -0500 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay06.hostedemail.com (Postfix) with ESMTP id 614441800B891; Sat, 17 Nov 2018 08:24:42 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::,RULES_HIT:41:355:379:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:1801:2393:2553:2559:2562:2692:2828:2897:3138:3139:3140:3141:3142:3354:3622:3865:3866:3867:3872:3873:3874:4321:4605:5007:6119:7514:7903:8603:8660:10004:10400:10848:11026:11232:11473:11658:11914:12043:12438:12555:12740:12760:12895:12986:13071:13148:13230:13439:14096:14097:14180:14181:14659:14721:21060:21080:21433:21451:21627:30054:30090:30091,0,RBL:47.151.153.53:@perches.com:.lbl8.mailshell.net-62.14.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:28,LUA_SUMMARY:none X-HE-Tag: songs71_bbd521b5d657 X-Filterd-Recvd-Size: 3762 Received: from XPS-9350.home (unknown [47.151.153.53]) (Authenticated sender: joe@perches.com) by omf17.hostedemail.com (Postfix) with ESMTPA; Sat, 17 Nov 2018 08:24:40 +0000 (UTC) Message-ID: Subject: Re: [PATCH] arch/powerpc: Use dma_zalloc_coherent From: Joe Perches To: Souptick Joarder Cc: 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, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Date: Sat, 17 Nov 2018 00:24:39 -0800 In-Reply-To: References: <5bdfb8db.1c69fb81.c8f62.9586@mx.google.com> <7a3922bc5089dfe0978e07a809606360c74c940c.camel@perches.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 Sat, 2018-11-17 at 12:40 +0530, Souptick Joarder wrote: > Hi Joe, Hi back. > On Fri, Nov 16, 2018 at 12:55 AM Joe Perches wrote: > > 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); > > +} > > + > > If I understood correctly, you are talking about adding these 2 new inline > functions. We can do that. > > Can you please help to understand the consumers of these 2 new inline ? Any call to dma_alloc_coherent with a multiply _might_overflow the multiplication. The check_mul_overflow simply avoids the overflow.