From patchwork Wed Mar 9 09:29:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 63710 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp2542590lbc; Wed, 9 Mar 2016 01:31:03 -0800 (PST) X-Received: by 10.66.255.39 with SMTP id an7mr48660766pad.2.1457515863611; Wed, 09 Mar 2016 01:31:03 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id hc1si11320224pac.16.2016.03.09.01.31.03; Wed, 09 Mar 2016 01:31:03 -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 S1752996AbcCIJa7 (ORCPT + 30 others); Wed, 9 Mar 2016 04:30:59 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:52546 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751742AbcCIJax (ORCPT ); Wed, 9 Mar 2016 04:30:53 -0500 Received: from 172.24.1.136 (EHLO szxeml434-hub.china.huawei.com) ([172.24.1.136]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DCZ87782; Wed, 09 Mar 2016 17:30:47 +0800 (CST) Received: from localhost (10.177.23.164) by szxeml434-hub.china.huawei.com (10.82.67.225) with Microsoft SMTP Server id 14.3.235.1; Wed, 9 Mar 2016 17:30:37 +0800 From: Zhen Lei To: Andrew Morton , Marek Szyprowski , Will Deacon , linux-kernel CC: Zefan Li , Xinwei Hu , "Tianhong Ding" , Hanjun Guo , Zhen Lei Subject: [PATCH v2 1/1] dma-mapping: to avoid oops when parameter cpu_addr is null Date: Wed, 9 Mar 2016 17:29:36 +0800 Message-ID: <1457515776-12352-2-git-send-email-thunder.leizhen@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1457515776-12352-1-git-send-email-thunder.leizhen@huawei.com> References: <1457515776-12352-1-git-send-email-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.23.164] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.56DFED49.00DA, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: a5d854d5f946e2f92388ad96a6cf7635 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To keep consistent with kfree, which tolerate ptr is NULL. We do this because sometimes we may use goto statement, so that success and failure case can share parts of the code. But unfortunately, dma_free_coherent called with parameter cpu_addr is null will cause oops, such as showed below: Unable to handle kernel paging request at virtual address ffffffc020d3b2b8 pgd = ffffffc083a61000 [ffffffc020d3b2b8] *pgd=0000000000000000, *pud=0000000000000000 CPU: 4 PID: 1489 Comm: malloc_dma_1 Tainted: G O 4.1.12 #1 Hardware name: ARM64 (DT) task: ffffffc00d7d26c0 ti: ffffffc0837fc000 task.ti: ffffffc0837fc000 PC is at __dma_free_coherent.isra.10+0x74/0xc8 LR is at __dma_free+0x9c/0xb0 pc : [] lr : [] pstate: 80000145 sp : ffffffc0837ff700 x29: ffffffc0837ff700 x28: 0000000000000000 x27: 0000000000000000 x26: ffffffffffffffff x25: ffffffc000d1b1d0 x24: ffffffffffffffff x23: 0000000000a00000 x22: ffffffbfff5fffff x21: 0000000000100000 x20: ffffffc2e21f7010 x19: ffffffffffffffff x18: 0000000000000000 x17: 0000007f9360a2b0 x16: ffffffc000541040 x15: ffffffffffffffff x14: ffffffffffffffff x13: ffffffffffffffff x12: 0000000000000001 x11: 0000000000000068 x10: 0000000000000040 x9 : ffffffc000214e00 x8 : ffffffc2e54586b0 x7 : 0000000000000000 x6 : 0000000000000004 x5 : ffffffc000214d64 x4 : 0000000000000000 x3 : 0000000003ffffff x2 : 00000003ffffffff x1 : 000fffffffffffff x0 : ffffffc000d3b2c0 Process malloc_dma_1 (pid: 1489, stack limit = 0xffffffc0837fc020) Stack: (0xffffffc0837ff700 to 0xffffffc083800000) f700: ffffffc0837ff730 ffffffc000214e00 0000000000100000 0000000000000000 f720: ffffffc2e21f7010 ffffffc0837ff7d0 ffffffc0837ff770 ffffffbffc1d6134 f740: ffffffc2e21f7010 00000000000001a0 0000000000000064 ffffffc0837ff7d0 f760: ffffffc000c9fa20 ffffffc0837ffaf0 ffffffc0837ffe10 ffffffc000239b0c f780: ffffffc00d54a280 ffffffc000d1ef58 ffffffc000957163 ffffffc2e21f7000 [...] Call trace: [] __dma_free_coherent.isra.10+0x74/0xc8 [] __dma_free+0x9c/0xb0 [] malloc_dma+0x104/0x158 [dma_alloc_coherent_mtmalloc] [] kthread+0xec/0xfc Signed-off-by: Zhen Lei --- include/linux/dma-mapping.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.5.0 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 75857cd..728ef07 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -386,7 +386,7 @@ static inline void dma_free_attrs(struct device *dev, size_t size, if (dma_release_from_coherent(dev, get_order(size), cpu_addr)) return; - if (!ops->free) + if (!ops->free || !cpu_addr) return; debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);