Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp6568196ybx; Mon, 11 Nov 2019 11:05:39 -0800 (PST) X-Google-Smtp-Source: APXvYqwhGHubGwcKVyeLNzjUJh9I0m77Xfg7yJEjfDFefvg3HYAE8T42Zgzj3Mlw5RkXwghRGnFP X-Received: by 2002:a17:906:3458:: with SMTP id d24mr24548443ejb.271.1573499139308; Mon, 11 Nov 2019 11:05:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573499139; cv=none; d=google.com; s=arc-20160816; b=Z17AJXmyFQYNA19X4+zYQJrIKeJRWR5n87WNwhv0E4wvJ+6qbbaohu7VVu/bbHYvev FrI+uVaqnTgQiV6q8YypQk16K7N6FG+AnxmKd/CUL3NaJJ64aTd5D8VafttWS8zemeyb cMi+d6mLe8XeMJolJs3mfty5UAwMR8dkaMhvJfjSTPDq1VeyMod7c86CIQ1bLCoDctJC +mR0PRDMlf2t7ru4rjS6H9cIW1dvzvl9sNorJAyFJQ9Pr85yBNM87OtHH5c/BLjl4mmy m4HuBWlKgw4H0AW08W2cNOaU9/+lzupVhFBDVQz/dGH/69UI1+KWOQzgtVaywNzuScKf HuDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+0+rLiFD4QvbVWJ3wNwc/OVy5xC0qWj6HSQ1CggMqFE=; b=pJEaH96+Z54D665N5PXeXRIdoGTzyKr/gwD7E0IYUso61LRDhA8EGx4bX53ov0/uCV ejxdRTfPKt0wD6E2m7mMNUstdAOkUxuIBpIpXok8/T9fuF3rCsLVY7TkLdR1z4bDkfBI ZkwJv8KTmb+QU9DhjzUxa3PoqvQR17PrlGt0TcU28P8BEurbpHcqqehiUOCnmgshb5Pv 43s7A7Ib0haxgkrQhF9iULsBaar4XY/CLrq2jZ9YFh1EBZYJ3LQN4QXX7+ng0gtMMjWv tHJGPa5X0NVgHTUVNRY84FiN5Twdv4ZfaGcqxiNdcMSQqTKG3apUEr6V7qOMhahSZVal g2Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sscScEYy; 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 k24si11374890edk.367.2019.11.11.11.05.14; Mon, 11 Nov 2019 11:05:39 -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; dkim=pass header.i=@kernel.org header.s=default header.b=sscScEYy; 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 S1729290AbfKKSoG (ORCPT + 99 others); Mon, 11 Nov 2019 13:44:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:35602 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728130AbfKKSoD (ORCPT ); Mon, 11 Nov 2019 13:44:03 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 55BD6204FD; Mon, 11 Nov 2019 18:44:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573497841; bh=dywrqtEgRpBStaOON3XI5ekgKLo9hIVBLPXy10+jWHw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sscScEYyhU1DXMlrhNckLb9Z9ehXvUR3UZ/FemxJHkID7jebj3rMTeApHbZVouaaE 4W+BEQb7Xw8bwslitM1q3huFJf+vJVJtc+II+62OuYYMzV+WT8DrMvUzN1AsS3nm7+ d3F3/9OfblZrBQQ2hhWdU0AmCXEPH9QH4zMhTafc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhenfang Wang , Baolin Wang , Vinod Koul , Sasha Levin Subject: [PATCH 4.19 072/125] dmaengine: sprd: Fix the possible memory leak issue Date: Mon, 11 Nov 2019 19:28:31 +0100 Message-Id: <20191111181449.739146488@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181438.945353076@linuxfoundation.org> References: <20191111181438.945353076@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Baolin Wang [ Upstream commit ec1ac309596a7bdf206743b092748205f6cd5720 ] If we terminate the channel to free all descriptors associated with this channel, we will leak the memory of current descriptor if the current descriptor is not completed, since it had been deteled from the desc_issued list and have not been added into the desc_completed list. Thus we should check if current descriptor is completed or not, when freeing the descriptors associated with one channel, if not, we should free it to avoid this issue. Fixes: 9b3b8171f7f4 ("dmaengine: sprd: Add Spreadtrum DMA driver") Reported-by: Zhenfang Wang Tested-by: Zhenfang Wang Signed-off-by: Baolin Wang Link: https://lore.kernel.org/r/170dbbc6d5366b6fa974ce2d366652e23a334251.1570609788.git.baolin.wang@linaro.org Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/dma/sprd-dma.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/dma/sprd-dma.c b/drivers/dma/sprd-dma.c index 1ed1c7efa2885..9e8ce56a83d8a 100644 --- a/drivers/dma/sprd-dma.c +++ b/drivers/dma/sprd-dma.c @@ -181,6 +181,7 @@ struct sprd_dma_dev { struct sprd_dma_chn channels[0]; }; +static void sprd_dma_free_desc(struct virt_dma_desc *vd); static bool sprd_dma_filter_fn(struct dma_chan *chan, void *param); static struct of_dma_filter_info sprd_dma_info = { .filter_fn = sprd_dma_filter_fn, @@ -493,12 +494,19 @@ static int sprd_dma_alloc_chan_resources(struct dma_chan *chan) static void sprd_dma_free_chan_resources(struct dma_chan *chan) { struct sprd_dma_chn *schan = to_sprd_dma_chan(chan); + struct virt_dma_desc *cur_vd = NULL; unsigned long flags; spin_lock_irqsave(&schan->vc.lock, flags); + if (schan->cur_desc) + cur_vd = &schan->cur_desc->vd; + sprd_dma_stop(schan); spin_unlock_irqrestore(&schan->vc.lock, flags); + if (cur_vd) + sprd_dma_free_desc(cur_vd); + vchan_free_chan_resources(&schan->vc); pm_runtime_put(chan->device->dev); } @@ -814,15 +822,22 @@ static int sprd_dma_resume(struct dma_chan *chan) static int sprd_dma_terminate_all(struct dma_chan *chan) { struct sprd_dma_chn *schan = to_sprd_dma_chan(chan); + struct virt_dma_desc *cur_vd = NULL; unsigned long flags; LIST_HEAD(head); spin_lock_irqsave(&schan->vc.lock, flags); + if (schan->cur_desc) + cur_vd = &schan->cur_desc->vd; + sprd_dma_stop(schan); vchan_get_all_descriptors(&schan->vc, &head); spin_unlock_irqrestore(&schan->vc.lock, flags); + if (cur_vd) + sprd_dma_free_desc(cur_vd); + vchan_dma_desc_free_list(&schan->vc, &head); return 0; } -- 2.20.1