From patchwork Wed Sep 3 09:28:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 4831721 Return-Path: X-Original-To: patchwork-dmaengine@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 A7085C0338 for ; Wed, 3 Sep 2014 09:38:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C6BB1201CE for ; Wed, 3 Sep 2014 09:38:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F371520154 for ; Wed, 3 Sep 2014 09:38:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755286AbaICJip (ORCPT ); Wed, 3 Sep 2014 05:38:45 -0400 Received: from forward-corp1e.mail.yandex.net ([77.88.60.199]:40659 "EHLO forward-corp1e.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754707AbaICJio (ORCPT ); Wed, 3 Sep 2014 05:38:44 -0400 X-Greylist: delayed 572 seconds by postgrey-1.27 at vger.kernel.org; Wed, 03 Sep 2014 05:38:44 EDT Received: from smtpcorp4.mail.yandex.net (smtpcorp4.mail.yandex.net [95.108.252.2]) by forward-corp1e.mail.yandex.net (Yandex) with ESMTP id 182AE6405D7; Wed, 3 Sep 2014 13:29:05 +0400 (MSK) Received: from smtpcorp4.mail.yandex.net (localhost [127.0.0.1]) by smtpcorp4.mail.yandex.net (Yandex) with ESMTP id C12B22C0727; Wed, 3 Sep 2014 13:29:04 +0400 (MSK) Received: from unknown (unknown [2a02:6b8:0:408:56ee:75ff:fe06:6fd6]) by smtpcorp4.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id hABo4hU0Ve-T4uOao4A; Wed, 3 Sep 2014 13:29:04 +0400 (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Uniq: 59a7be5e-26f4-437b-a92e-2a7d7a2cf44a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1409736544; bh=78pxH9+zC5LuZoqsX+xzGnyxdyDY7jqCiKdN/kywhpU=; h=Date:Message-ID:From:To:Subject:User-Agent:MIME-Version: Content-Type; b=m+7q/gKE+gb9Ka2bNPKskkG7qK05wPdX3mfAXLSvCZ5yRsR5Dkt/cGfJZILbeH3PT pJNPEKcbTT6H3H7CvTmJlQ/Bv/GA9bEVqSiFBpCgjC4UaeouwUEwCSTPul5v9rypSF PcTupHDm4WTpdI6cmxhxAjlEUnzYtx1a1VT/445A= Authentication-Results: smtpcorp4.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Date: Wed, 03 Sep 2014 13:28:59 +0400 Message-ID: <87d2bdcask.wl%klamm@yandex-team.ru> From: Roman Gushchin To: dan.j.williams@intel.com, vinod.koul@intel.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] net_dma: fix memory leak in dma_pin_iocvec_pages User-Agent: Wanderlust/2.15.9 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham 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 dma_pin_iovec_pages() calls get_user_pages() for each iovec. If get_user_pages() returns a number smaller than the requested number, dma_pin_iovec_pages() calls dma_unpin_iovec_pages(). It releases previously allocated iovecs, but pages pinned by last get_user_pages() call remain unreleased. Fix this by calling put_page() for each such page. Signed-off-by: Roman Gushchin --- drivers/dma/iovlock.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/dma/iovlock.c b/drivers/dma/iovlock.c index bb48a57..c393cf9 100644 --- a/drivers/dma/iovlock.c +++ b/drivers/dma/iovlock.c @@ -107,8 +107,11 @@ struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len) NULL); up_read(¤t->mm->mmap_sem); - if (ret != page_list->nr_pages) + if (ret != page_list->nr_pages) { + for (i = 0; i < ret; i++) + put_page(page_list->pages[i]); goto unpin; + } local_list->nr_iovecs = i + 1; }