From patchwork Mon Nov 11 18:27:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 179114 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp7046546ilf; Mon, 11 Nov 2019 10:52:45 -0800 (PST) X-Google-Smtp-Source: APXvYqyug4ZvvWyw2G4bDjpW0UQc0jy5masitVzuebIi6jrhSclcPAnVBwS9R7JOUw50rulojNym X-Received: by 2002:a17:906:4e99:: with SMTP id v25mr12851531eju.106.1573498365768; Mon, 11 Nov 2019 10:52:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573498365; cv=none; d=google.com; s=arc-20160816; b=KeGf6m2OkNTxfxidL1wfPZ1jRohF9rnlG2s7XbooX/SOigQ0teZP4NXCn/TbpTIN1I 9n541dk3DyPL8ZLGZTmgx+QywppGx3GbCuso3Kq1JEnqUZ58mHgGvp6Ho25QDUQpMcIR SIi60PQGi2w5P8a9lIPhxg0CJoW+4wBG/ri5om0fnLVIf8YHY5CTjG8keLLvspK4Cd5O lnh0SoQNLLW1sA9HagW+Bjmi8EK3VN+DTmO1gmC+gKec2W/Z2qDwCPuHxpkTLM/BLbym z6cbmcrg+Zoxny+X0SgN8q9GnLwAu98H/Had7yqsHJ4wjbmDkRNqhbVWs/1/0mNSd3bi D8Pg== 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=5PJFRPbsdzWQvL5c/uej9NU8sG+9wv1SxrMDAjhhAYY=; b=dDZrEcZJJ6QlRevjAB+pq/Ow5I3XRk+lyTzXWGIQQ0oocoam87OGHBQlI9SqEC3gdy NuwRBas+vvGHZcEJ0l7MHJU5tUAbWJDRnPRKIcsVAxYdfmH6Vva2tGynEhl1q4jS8FSm 5qLbU0gAY1NZVCytroadHgiNOXrSS7sbjg4hvKVX4nhfKXmF9KvIAwzlGGeuMTQoE9hj 0qyaUzPctYpLgFAJQ3xREjNiH+19jCnSmuUOxF+gcqhiLes7SmigCxwBrsJSkC3Zi6po Y1crCu6wsBwF7TpZaq/h75fiXvnsyiHmOK7flRiuZjZziVRacQG7oGPVvDygtIgfoLsM prUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IDzXOJNz; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 m12si5729435ejr.306.2019.11.11.10.52.45; Mon, 11 Nov 2019 10:52:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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=IDzXOJNz; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727341AbfKKSwn (ORCPT + 14 others); Mon, 11 Nov 2019 13:52:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:47060 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729650AbfKKSwm (ORCPT ); Mon, 11 Nov 2019 13:52:42 -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 A0829214E0; Mon, 11 Nov 2019 18:52:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573498360; bh=tY0oOqPs5y4Z3QzaxhFPBAKTG3CHb+oGU/zS+s/xIZc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IDzXOJNz9DfJIXQzHNOeAmvu3f3xKM4BnjPDCwY2+KzOvoq58UBxDhStzKwt3JpNk w2WYM9whr433IMApbL5QVcE4j4n2aWN6V0RCrUtwNQSIIQ9mVDjDbU4SGxTbUgiAhA eCPUES4JZPkyi79syrubUJgVKBDlXbOE7DWS2jlE= 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 5.3 096/193] dmaengine: sprd: Fix the possible memory leak issue Date: Mon, 11 Nov 2019 19:27:58 +0100 Message-Id: <20191111181508.229679609@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181459.850623879@linuxfoundation.org> References: <20191111181459.850623879@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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(+) -- 2.20.1 diff --git a/drivers/dma/sprd-dma.c b/drivers/dma/sprd-dma.c index a4a91f233121a..8546ad0347208 100644 --- a/drivers/dma/sprd-dma.c +++ b/drivers/dma/sprd-dma.c @@ -212,6 +212,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, @@ -613,12 +614,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); } @@ -1031,15 +1039,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; }