Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp287150imu; Fri, 16 Nov 2018 23:08:55 -0800 (PST) X-Google-Smtp-Source: AJdET5f7x1ujbej29CEuzIbVvZsNcwmHWjJ3sadJ5/xUeH9l3gEBPYcyE9dKdxhfHtDJTCUyUxpW X-Received: by 2002:a17:902:7d89:: with SMTP id a9mr14041679plm.242.1542438535897; Fri, 16 Nov 2018 23:08:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542438535; cv=none; d=google.com; s=arc-20160816; b=xs79JLE8MIS8tMjDVQCPNVBEhpXrMg12jMLxctNjjPfQ3Nqb71VxTIx8Sa9iI9IY00 8Eu7b4YHnNsrVh3F9OfN2e0pHsXT9kUCEBYrghEgf/h/IjD24bhbvgZ7z3vyuvzKm8d5 Zz5/gTJ5xb5HvyPc2SFIABLa0B7FnJjMvgEw/fCVTdFsDhox912NbOznXGja3Huu8c65 9ctmpdASM1v7TM24obuFYPaR3PBLLsc9X9ZB4V54jcRG46H+ks8WrcLrEE6/9dVxVspr mJL7rLsbOygjM2T7nvvLhzGFLfIPxj8cdEq10AtQFN+7n2he416P3+f7gzJVeIW+dlDD 4xgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=fIKcjyDRicTrvbuurk8pmEnO8fySvmZKHCB2aFwXKyo=; b=sWYx/ZNQfYP+7SVHwaZeA1UpRwRJQ0y5H5nYxz/epcOmB/p/9F6ffdWDzyU4nkoljK E39WDSXFz/elh8+nJsERX9gAuKH4zYXfZNwL1Iio8VDrQuKtrhIvSH+8RSXqCcJGmjyy IKj5zqiKfGKz+xEHieNkYinDTq7myFRoCZX+0KV9SMcWgEwGdXSAGwGeFhLiNLvAFTBc 4jV498DF1k/x703T54qZZLA20lQk1yc4DQFcPDvnjJfV05kQYmXcVR5xbBk9320ASbcK CkANX1rx2e4zKzOwe3xSAXOkDiKrmPOXOe4bDIVeX4oSJ38O4QZFFi9/4tioiUVehTzy HaDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=d1vIDkbe; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g62-v6si215059pfe.186.2018.11.16.23.08.40; Fri, 16 Nov 2018 23:08:55 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=d1vIDkbe; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725879AbeKQRWc (ORCPT + 99 others); Sat, 17 Nov 2018 12:22:32 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:34908 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725810AbeKQRWc (ORCPT ); Sat, 17 Nov 2018 12:22:32 -0500 Received: by mail-lj1-f193.google.com with SMTP id x85-v6so22242720ljb.2 for ; Fri, 16 Nov 2018 23:06:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fIKcjyDRicTrvbuurk8pmEnO8fySvmZKHCB2aFwXKyo=; b=d1vIDkbeZUZUCYskR8G7+3qH2MMSz6P51FBjnG/CkqJ7iWaUY9dyicU2YmH6olA42D Sp5JkcRb397m5fl5zZFVJY+eNi77Lps6tbR4yk7IXiUOT+CvsbSmn0C1eNXACcYw4zR1 fMC3t03xr4Cnqf0749ChMGV88OFtE8sqiFGN5VedJl4L5e0SEscrTTPRjJpXVABBM/Nc DykZpAZ/xLephvYBoA7UGbBJMX7baxyhg7y6GPb1JyIxSKN+uRsH6271lLw/3TrF/k5d IiSXtuQY6TZAMsMAqvGrLMiaXdTywSthefBge9GBj5WY5CGxqscf/FcMcih0KPMYwf/O xdyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fIKcjyDRicTrvbuurk8pmEnO8fySvmZKHCB2aFwXKyo=; b=mC4j1sglfQklPTkLfLrxTGkw10jgLtLxmTmrRb/yf1E6BOG3p/QLGIQz+OjY+1GQ4B ofKSmFw7uiMpmuvdXnNRHeD1cIMacGq8kDfVyXtahD8gK4ZMX5GCfVgs7x8cqffvD+yD vYcTLK1zEdh1xiVV4JOPUV1Vt6UDNHVfXQMDhfgyxBjwZYilGqaZYSn/rxCBsf9x2mQt 3idTtxyGcXMzu1oAkBNZ9VGOi/uejdmBMk/uDoKJQf3K5aaZW9y22ZodVm30YqhwLJtl WiWNUkQn2dy5eOdZpBQopBCuIiiy2eOnshNRQKNkhkYf8JYNqHW3xY1kqdQl2ujvuHQi OKsg== X-Gm-Message-State: AGRZ1gJkcM0gTHcEd1qu5nVIRZivwJFnegY+89sBjw8/shufu/pdlw37 n91AE9RsYJalhOclGY0uqa+xneV0q4rAV7AM24Q= X-Received: by 2002:a2e:9b84:: with SMTP id z4-v6mr7425061lji.93.1542438407249; Fri, 16 Nov 2018 23:06:47 -0800 (PST) MIME-Version: 1.0 References: <5bdfb8db.1c69fb81.c8f62.9586@mx.google.com> <7a3922bc5089dfe0978e07a809606360c74c940c.camel@perches.com> In-Reply-To: <7a3922bc5089dfe0978e07a809606360c74c940c.camel@perches.com> From: Souptick Joarder Date: Sat, 17 Nov 2018 12:40:14 +0530 Message-ID: Subject: Re: [PATCH] arch/powerpc: Use dma_zalloc_coherent To: Joe Perches 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Joe, 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 ? > 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); > >