Received: by 10.223.185.116 with SMTP id b49csp1799744wrg; Thu, 22 Feb 2018 03:23:50 -0800 (PST) X-Google-Smtp-Source: AH8x225BUc1mP138b597jwSgvkFsV648LavWuvGy2A8P9nPw5Hb7Uwfjd6suFINkC0OQlcMVxK9X X-Received: by 10.98.214.218 with SMTP id a87mr6613960pfl.146.1519298630073; Thu, 22 Feb 2018 03:23:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519298630; cv=none; d=google.com; s=arc-20160816; b=IUTJnBNtYfSPtQmbLDsFOGxf9iiZhnIZb5j1gZQaVSCsNfcdKA8tR5+MNR6lepLqx9 eFav5IUoB3+QBUHx2eELOtybsksvcBBrNdzeGj2nzpkEyYn+To+XcqSdYXNG+aQ0b8DS L1GcPcdXrJXtvflQYSMAVbXhY3uo10fmHx6bKCK5uw4jas+5Lxfp3XFpJGkk/UGIrh1m ZN2agKGPE6RkNJm5/brWiaZf+rPqYNkrmxagD4h2xkvdc1FTBAlqZDAdZFSnIOqg5lgV xUKdkS3rRyjI9E/94ZN/tHllv7QiYXj+8OVq7mVU3OJZtmL6PljsO2PWfeXZYSdkrLpb n24Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=oY1OFnPnCLEpZRI/+bEsjILjSOR9+tZYyUCFv54boUU=; b=kPjLQegW9IodL53fcqHk2nTRYRa6pk1mi0TFQnIoezf6zG/k66uCik22xU3qQrRosu bGrsJMc7/jmpxsnWU5nJwEFPjNo0eMFVNc5e9Wa2H0782FsSBCXdbDWmCTzhqDXVachA taMT5E0kqeDRKip3DphMTMm+Ns7rkgWxBP6HMJDqALlhyl40zVh2OqRCjRIGrPHPnKtb gtHYNRhOGpxGqc+O1XA/ibVxfCau+C50hkdDQsZxLl7UYSVTsSNGD7MfN2tThQeqMtUW c6QerqYQ3zy6j61prxU7GhbN7oo7KhJjs+HXszbSLxGEy1jpjCkCU1MpeTrP60aHz3HY ScGQ== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l70si2748777pge.778.2018.02.22.03.23.35; Thu, 22 Feb 2018 03:23:50 -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 S1753673AbeBVLW0 (ORCPT + 99 others); Thu, 22 Feb 2018 06:22:26 -0500 Received: from mailgw01.mediatek.com ([210.61.82.183]:19600 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753512AbeBVLWZ (ORCPT ); Thu, 22 Feb 2018 06:22:25 -0500 X-UUID: 4d9a3e23ca4645a99fd962b21a432692-20180222 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 464300832; Thu, 22 Feb 2018 19:22:22 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs08n1.mediatek.inc (172.21.101.55) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Thu, 22 Feb 2018 19:22:21 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Thu, 22 Feb 2018 19:22:21 +0800 From: To: Christoph Hellwig , Marek Szyprowski , Robin Murphy CC: , , , , Miles Chen Subject: [PATCH] lib/dma-debug.c: fix memory leakage Date: Thu, 22 Feb 2018 19:22:20 +0800 Message-ID: <1519298540-3071-1-git-send-email-miles.chen@mediatek.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miles Chen Marty reported a memory leakage introduced by commit 3aaabbf1c39e ("lib/dma-debug.c: fix incorrect pfn calculation"). Fix it by checking the virtual address before allocating the entry. This patch also use virt_addr_valid() instead of virt_to_page() to check if a virtual address is linear. Reported-by: Marty Faltesek Signed-off-by: Miles Chen --- lib/dma-debug.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/dma-debug.c b/lib/dma-debug.c index 1b34d210452c..7f5cdc1e6b29 100644 --- a/lib/dma-debug.c +++ b/lib/dma-debug.c @@ -1491,12 +1491,12 @@ void debug_dma_alloc_coherent(struct device *dev, size_t size, if (unlikely(virt == NULL)) return; - entry = dma_entry_alloc(); - if (!entry) + /* handle vmalloc and linear addresses */ + if (!is_vmalloc_addr(virt) && !virt_addr_valid(virt)) return; - /* handle vmalloc and linear addresses */ - if (!is_vmalloc_addr(virt) && !virt_to_page(virt)) + entry = dma_entry_alloc(); + if (!entry) 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)) -- 2.12.5