From patchwork Wed Nov 22 03:17:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miles Chen X-Patchwork-Id: 10069477 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 C15086022E for ; Wed, 22 Nov 2017 03:18:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4ACC295F8 for ; Wed, 22 Nov 2017 03:18:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A8A7C29AA1; Wed, 22 Nov 2017 03:18:40 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham 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 44BE4295F8 for ; Wed, 22 Nov 2017 03:18:40 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=Hh9cIJxaMJhN81jusH01boTS0K+zMy2hTj10SYX6VUw=; b=BjxGe6hu/+c5YM 3zY+dRK9LB7Ge/jG3cdcdxMAFvjZ5fKMusVtjtxraZDZcalWJ6LaLQylssig0+UFu1QZKiMDbPMtJ hFzlECDLnxumilbjAShfmZJDFGEJtfHXhU3teZW10Fq6aKBdB8RGe+roX3d8NcafRA1JAVRYIN83N aE9AGKf/hSwr6i+8wRAcP2PxFiQerusMTMYSilkq0r5HiPynV2SWJ4YP3kzTpYdPSWzxTUStGPEN1 sT0trb+iaOZDlLEPif796W725STzfcnGTzVt2gnWVrcukwk/dCIRjalo9xzWRGDw3tO+qIQqazBFp qFn80qoYt+u2rWS172yQ==; 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 1eHLYd-00064y-0V; Wed, 22 Nov 2017 03:18:39 +0000 Received: from [210.61.82.183] (helo=mailgw01.mediatek.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eHLYZ-00061Q-Ke for linux-mediatek@lists.infradead.org; Wed, 22 Nov 2017 03:18:37 +0000 X-UUID: a22e983644be4f5da5397e0a11f8439f-20171122 Received: from mtkcas08.mediatek.inc [(172.21.101.126)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1004105861; Wed, 22 Nov 2017 11:17:48 +0800 Received: from mtkcas09.mediatek.inc (172.21.101.178) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Wed, 22 Nov 2017 11:17:42 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Wed, 22 Nov 2017 11:17:35 +0800 From: To: Christoph Hellwig , Marek Szyprowski , Robin Murphy Subject: [PATCH] dma-debug: use virt_addr_valid() to check linear addresses Date: Wed, 22 Nov 2017 11:17:35 +0800 Message-ID: <1511320655-22752-1-git-send-email-miles.chen@mediatek.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171121_191835_855551_BCBD67DD X-CRM114-Status: UNSURE ( 8.82 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Miles Chen , iommu@lists.linux-foundation.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, wsd_upstream@mediatek.com Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Miles Chen Coverity found that the commit 3aaabbf1c39e ("lib/dma-debug.c: fix incorrect pfn calculation") uses incorrect API to check if a given address is a linear address. The condition should be: (as discussed in Christoph's review) if (!is_vmalloc_addr(virt) && !virt_addr_valid(virt)) not if (!is_vmalloc_addr(virt) && !virt_to_page(virt)) Fix it by using virt_addr_valid() instead of virt_to_page(). Signed-off-by: Miles Chen --- lib/dma-debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/dma-debug.c b/lib/dma-debug.c index 1b34d21..4c08eb6 100644 --- a/lib/dma-debug.c +++ b/lib/dma-debug.c @@ -1496,7 +1496,7 @@ void debug_dma_alloc_coherent(struct device *dev, size_t size, return; /* handle vmalloc and linear addresses */ - if (!is_vmalloc_addr(virt) && !virt_to_page(virt)) + if (!is_vmalloc_addr(virt) && !virt_addr_valid(virt)) return; entry->type = dma_debug_coherent; @@ -1528,7 +1528,7 @@ void debug_dma_free_coherent(struct device *dev, size_t size, }; /* handle vmalloc and linear addresses */ - if (!is_vmalloc_addr(virt) && !virt_to_page(virt)) + if (!is_vmalloc_addr(virt) && !virt_addr_valid(virt)) return; if (is_vmalloc_addr(virt))