From patchwork Mon Dec 4 13:05:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sharat Masetty X-Patchwork-Id: 10090225 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 7497760580 for ; Mon, 4 Dec 2017 13:06:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 880BF28D30 for ; Mon, 4 Dec 2017 13:06:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7CB8C2916B; Mon, 4 Dec 2017 13:06:45 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1D7CC28E3E for ; Mon, 4 Dec 2017 13:06:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 53B4A6E29E; Mon, 4 Dec 2017 13:06:44 +0000 (UTC) X-Original-To: dri-devel@freedesktop.org Delivered-To: dri-devel@freedesktop.org Received: from smtp.codeaurora.org (smtp.codeaurora.org [198.145.29.96]) by gabe.freedesktop.org (Postfix) with ESMTPS id E12F06E338 for ; Mon, 4 Dec 2017 13:06:42 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1000) id CDC886025C; Mon, 4 Dec 2017 13:06:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1512392802; bh=fSq0wj1QRKOzn4H7aUo+yYRoFVqBzg6OMT3Y5qDm9EY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WktfpmVbzqaBRrlazxqZ3a8Ijt68qnimBwtvrnKtrdf3Rka5VklafhBKHhwllJv+R ZhlGGay7Lwug8kA/UscW0XcoeoqvqoWprnld57Yf+OJ8Hn8mbcD8K2TuQBXlDvks7z 0nhIyBtLQnvcQZ2jK7CwK1+obAOg5xRrjcVBYL/U= Received: from smasetty-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: smasetty@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 485146025C; Mon, 4 Dec 2017 13:06:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1512392802; bh=fSq0wj1QRKOzn4H7aUo+yYRoFVqBzg6OMT3Y5qDm9EY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WktfpmVbzqaBRrlazxqZ3a8Ijt68qnimBwtvrnKtrdf3Rka5VklafhBKHhwllJv+R ZhlGGay7Lwug8kA/UscW0XcoeoqvqoWprnld57Yf+OJ8Hn8mbcD8K2TuQBXlDvks7z 0nhIyBtLQnvcQZ2jK7CwK1+obAOg5xRrjcVBYL/U= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 485146025C 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=smasetty@codeaurora.org From: Sharat Masetty To: freedreno@lists.freedesktop.org Subject: [PATCH] drm/msm: fix leak in failed get_pages Date: Mon, 4 Dec 2017 18:35:58 +0530 Message-Id: <1512392758-12042-2-git-send-email-smasetty@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1512392758-12042-1-git-send-email-smasetty@codeaurora.org> References: <1512392758-12042-1-git-send-email-smasetty@codeaurora.org> Cc: Sharat Masetty , linux-arm-msm@vger.kernel.org, Prakash Kamliya , dri-devel@freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Prakash Kamliya get_pages doesn't keep a reference of the pages allocated when it fails later in the code path. This can lead to a memory leak. Keep reference of the allocated pages so that it can be freed when msm_gem_free_object gets called later during cleanup. Signed-off-by: Prakash Kamliya Signed-off-by: Sharat Masetty --- drivers/gpu/drm/msm/msm_gem.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c index 0776160..cb3d58d 100644 --- a/drivers/gpu/drm/msm/msm_gem.c +++ b/drivers/gpu/drm/msm/msm_gem.c @@ -93,14 +93,17 @@ static struct page **get_pages(struct drm_gem_object *obj) return p; } + msm_obj->pages = p; + msm_obj->sgt = drm_prime_pages_to_sg(p, npages); if (IS_ERR(msm_obj->sgt)) { + void *ptr = ERR_CAST(msm_obj->sgt); + dev_err(dev->dev, "failed to allocate sgt\n"); - return ERR_CAST(msm_obj->sgt); + msm_obj->sgt = NULL; + return ptr; } - msm_obj->pages = p; - /* For non-cached buffers, ensure the new pages are clean * because display controller, GPU, etc. are not coherent: */ @@ -135,7 +138,10 @@ static void put_pages(struct drm_gem_object *obj) if (msm_obj->flags & (MSM_BO_WC|MSM_BO_UNCACHED)) dma_unmap_sg(obj->dev->dev, msm_obj->sgt->sgl, msm_obj->sgt->nents, DMA_BIDIRECTIONAL); - sg_free_table(msm_obj->sgt); + + if (msm_obj->sgt) + sg_free_table(msm_obj->sgt); + kfree(msm_obj->sgt); if (use_pages(obj))