From patchwork Thu Jan 23 21:23:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 3532141 Return-Path: X-Original-To: patchwork-davinci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 79C7DC02DC for ; Thu, 23 Jan 2014 21:24:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8FA4F20181 for ; Thu, 23 Jan 2014 21:24:37 +0000 (UTC) Received: from arroyo.ext.ti.com (arroyo.ext.ti.com [192.94.94.40]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5679E20161 for ; Thu, 23 Jan 2014 21:24:36 +0000 (UTC) Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id s0NLNYUn031050; Thu, 23 Jan 2014 15:23:35 -0600 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s0NLNXMM010047; Thu, 23 Jan 2014 15:23:33 -0600 Received: from dlep32.itg.ti.com (157.170.170.100) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.2.342.3; Thu, 23 Jan 2014 15:23:32 -0600 Received: from linux.omap.com (dlelxs01.itg.ti.com [157.170.227.31]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s0NLNVNW030759; Thu, 23 Jan 2014 15:23:31 -0600 Received: from linux.omap.com (localhost [127.0.0.1]) by linux.omap.com (Postfix) with ESMTP id 4E17880627; Thu, 23 Jan 2014 15:23:30 -0600 (CST) X-Original-To: davinci-linux-open-source@linux.davincidsp.com Delivered-To: davinci-linux-open-source@linux.davincidsp.com Received: from dflxv17.itg.ti.com (dflxv17.itg.ti.com [128.247.5.93]) by linux.omap.com (Postfix) with ESMTP id ECB1F80626 for ; Thu, 23 Jan 2014 15:23:28 -0600 (CST) Received: from red.ext.ti.com (red.ext.ti.com [192.94.93.37]) by dflxv17.itg.ti.com (8.14.3/8.13.8) with ESMTP id s0NLNSd0021112 for ; Thu, 23 Jan 2014 15:23:28 -0600 Received: from mail6.bemta12.messagelabs.com (mail6.bemta12.messagelabs.com [216.82.250.247]) by red.ext.ti.com (8.13.7/8.13.7) with ESMTP id s0NLNStf023451 for ; Thu, 23 Jan 2014 15:23:28 -0600 Received: from [216.82.250.83:33606] by server-4.bemta-12.messagelabs.com id E4/FD-08925-05881E25; Thu, 23 Jan 2014 21:23:28 +0000 X-Env-Sender: akpm@linux-foundation.org X-Msg-Ref: server-10.tower-120.messagelabs.com!1390512207!11587429!1 X-Originating-IP: [140.211.169.12] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.9.16; banners=-,-,- X-VirusChecked: Checked Received: (qmail 15550 invoked from network); 23 Jan 2014 21:23:27 -0000 Received: from mail.linuxfoundation.org (HELO mail.linuxfoundation.org) (140.211.169.12) by server-10.tower-120.messagelabs.com with SMTP; 23 Jan 2014 21:23:27 -0000 Received: from akpm3.mtv.corp.google.com (unknown [216.239.45.95]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 8457E8AF; Thu, 23 Jan 2014 21:23:26 +0000 (UTC) Date: Thu, 23 Jan 2014 13:23:25 -0800 From: Andrew Morton To: Prabhakar Lad Subject: Re: [PATCH] lib/genalloc.c: add check gen_pool_dma_alloc() if dma pointer is not NULL Message-ID: <20140123132325.cada6dca726c2cdd1173ad91@linux-foundation.org> In-Reply-To: References: <1390470990-16065-1-git-send-email-prabhakar.csengg@gmail.com> X-Mailer: Sylpheed 3.2.0beta5 (GTK+ 2.24.10; x86_64-pc-linux-gnu) MIME-Version: 1.0 CC: DLOS , Sachin Kamat , LKML , Philipp Zabel , Joe Perches X-BeenThere: davinci-linux-open-source@linux.davincidsp.com X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: Errors-To: davinci-linux-open-source-bounces@linux.davincidsp.com X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, 23 Jan 2014 15:51:31 +0530 Prabhakar Lad wrote: > Hi Sachin, > > On Thu, Jan 23, 2014 at 3:38 PM, Sachin Kamat wrote: > > Hi Prabhakar, > > > > On 23 January 2014 15:26, Prabhakar Lad wrote: > >> From: "Lad, Prabhakar" > >> > >> In the gen_pool_dma_alloc() the dma pointer can be NULL > >> and while assigning gen_pool_virt_to_phys(pool, vaddr) to > >> dma caused the following crash on da850 evm, > >> > > [snip] > >> > >> Signed-off-by: Lad, Prabhakar > >> --- > >> lib/genalloc.c | 3 ++- > >> 1 file changed, 2 insertions(+), 1 deletion(-) > >> > >> diff --git a/lib/genalloc.c b/lib/genalloc.c > >> index dda3116..f48163f 100644 > >> --- a/lib/genalloc.c > >> +++ b/lib/genalloc.c > >> @@ -334,7 +334,8 @@ void *gen_pool_dma_alloc(struct gen_pool *pool, size_t size, dma_addr_t *dma) > >> if (!vaddr) > >> return NULL; > >> > >> - *dma = gen_pool_virt_to_phys(pool, vaddr); > >> + if (dma) > >> + *dma = gen_pool_virt_to_phys(pool, vaddr); > > > > Wouldn't it be better to return (with error/message) if dma is NULL > > rather than silently ignore it? > > > I am not sure if returning here with error is OK, > may be just adding a warning message could be OK ? The patch look OK as-is to me. `dma' is a second return value from gen_pool_dma_alloc() and this patch extends the gen_pool_dma_alloc() interface by making that return value optional. That's good for callers who don't want the physical address, and they can call gen_pool_virt_to_phys() at a later time to get the physical address anyway. >From my reading, 3.13.x kernels will need this patch. I suppose we should document the API change: --- a/lib/genalloc.c~lib-genallocc-add-check-gen_pool_dma_alloc-if-dma-pointer-is-not-null-fix +++ a/lib/genalloc.c @@ -316,7 +316,7 @@ EXPORT_SYMBOL(gen_pool_alloc); * gen_pool_dma_alloc - allocate special memory from the pool for DMA usage * @pool: pool to allocate from * @size: number of bytes to allocate from the pool - * @dma: dma-view physical address + * @dma: dma-view physical address return value. Use NULL if unneeded. * * Allocate the requested number of bytes from the specified pool. * Uses the pool allocation function (with first-fit algorithm by default).