From patchwork Sat Jun 10 19:41:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olav Haugan X-Patchwork-Id: 9779951 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 12E38601EA for ; Sat, 10 Jun 2017 19:41:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0459128643 for ; Sat, 10 Jun 2017 19:41:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC6A42866B; Sat, 10 Jun 2017 19:41:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 046C428643 for ; Sat, 10 Jun 2017 19:41:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=lN9UQGCO9U/Y6+xD5mi7lvDobapLPv7RncCtwFCud0U=; b=svO ZiGo+iVVURv/XIOjZPVe94hDFmdUIcsU39tVfi5HUkDvTeFuhC/9KF8Y6vo3DQJQfThfo5kOY58m8 +jpgAxI0a3tVp6io8YUJzP9EcfDLNLI0DCdjYxpseewg5s+rEhHkGBOO8rOngqaMRBW+wE66XwM63 h8uus3SxMeNNA87dlrVG/HDoZeKZWMAnT+RLewJNcJ3nyyyBYm1JnEicECo3bhYwL0xD103d9KacM R8TB5wsd67GYnK2hPj+ZmkaA8OkBCthWhMi5Akvxl91ouDnkacJJlSiDvQ1h5ZDbP1ilBs620kdRN hF2hTOJvYWz3LqJ44DhR9OVV4eptxmg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dJmGc-0000yT-Ub; Sat, 10 Jun 2017 19:41:50 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dJmGZ-0000x8-5L for linux-arm-kernel@lists.infradead.org; Sat, 10 Jun 2017 19:41:48 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 48E2E60F5D; Sat, 10 Jun 2017 19:41:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1497123686; bh=fLc06Ndxrvg/tQCsdwLXvf64HgRydijDu4Jncy/w/HY=; h=From:To:Cc:Subject:Date:From; b=bpHCdGrd0EAM80qbKowZccqG1IOWOtNpE3s6cWsLu9S2YHAmENvFWeWKo0UvBnRPZ JdByDzQEw5HS3q/ZTutIOcG9K3IT8E54tl24L/GURKArsCNy5Pds+AiPv97LhJPg9P oYR5FXBOKSy401TXZwJhPAIxvmaBfqKiYCDjSLI0= Received: from ohaugan-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: ohaugan@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 7A4DE60EB7; Sat, 10 Jun 2017 19:41:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1497123685; bh=fLc06Ndxrvg/tQCsdwLXvf64HgRydijDu4Jncy/w/HY=; h=From:To:Cc:Subject:Date:From; b=dXvzF625NbobIZDoRfCz5f9V2Rq7JIV6EUYyLp2ZeXIvP9DPFBpJx0uDv+089vAwi jqR+7R/kFpcCWWxw0JbUrajWF/yqGciu1I0y4yfGYpCbduTlQm8kWirNBPcdozip3d sgBSltwXWjxVKPvRFE+2IK2wcnsibQHUJLFSEJ7E= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 7A4DE60EB7 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=ohaugan@codeaurora.org From: Olav Haugan To: ohaugan@codeaurora.org, catalin.marinas@arm.com, will.deacon@arm.com, robin.murphy@arm.com Subject: [PATCH] arm64/dma-mapping: Fix null-pointer check Date: Sat, 10 Jun 2017 12:41:10 -0700 Message-Id: <20170610194110.27712-1-ohaugan@codeaurora.org> X-Mailer: git-send-email 2.13.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170610_124147_292376_3303EF94 X-CRM114-Status: GOOD ( 11.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The current null-pointer check in __dma_alloc_coherent and __dma_free_coherent is pretty much useless since we are dereferencing the pointer before checking for null. Check for null-pointer before the actual dereferencing of the pointer. Signed-off-by: Olav Haugan --- arch/arm64/mm/dma-mapping.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index 3216e098c058..a4b65773711d 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -95,11 +95,6 @@ static void *__dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t flags, unsigned long attrs) { - if (dev == NULL) { - WARN_ONCE(1, "Use an actual device structure for DMA allocation\n"); - return NULL; - } - if (IS_ENABLED(CONFIG_ZONE_DMA) && dev->coherent_dma_mask <= DMA_BIT_MASK(32)) flags |= GFP_DMA; @@ -128,10 +123,6 @@ static void __dma_free_coherent(struct device *dev, size_t size, bool freed; phys_addr_t paddr = dma_to_phys(dev, dma_handle); - if (dev == NULL) { - WARN_ONCE(1, "Use an actual device structure for DMA allocation\n"); - return; - } freed = dma_release_from_contiguous(dev, phys_to_page(paddr), @@ -149,6 +140,11 @@ static void *__dma_alloc(struct device *dev, size_t size, bool coherent = is_device_dma_coherent(dev); pgprot_t prot = __get_dma_pgprot(attrs, PAGE_KERNEL, false); + if (!dev) { + WARN_ONCE(1, "Use an actual device structure for DMA allocation\n"); + return NULL; + } + size = PAGE_ALIGN(size); if (!coherent && !gfpflags_allow_blocking(flags)) { @@ -192,8 +188,13 @@ static void __dma_free(struct device *dev, size_t size, void *vaddr, dma_addr_t dma_handle, unsigned long attrs) { - void *swiotlb_addr = phys_to_virt(dma_to_phys(dev, dma_handle)); + void *swiotlb_addr; + if (!dev) { + WARN_ONCE(1, "Use an actual device structure for DMA free\n"); + return; + } + swiotlb_addr = phys_to_virt(dma_to_phys(dev, dma_handle)); size = PAGE_ALIGN(size); if (!is_device_dma_coherent(dev)) {