Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1617033ybv; Fri, 21 Feb 2020 00:22:02 -0800 (PST) X-Google-Smtp-Source: APXvYqxieVsncEPN+//fQyJByuF2svecTLMG2gd45BnQoAz+Nv8+yivCfjNbTqFSEAV21mLddo72 X-Received: by 2002:a05:6830:607:: with SMTP id w7mr28594459oti.155.1582273321789; Fri, 21 Feb 2020 00:22:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582273321; cv=none; d=google.com; s=arc-20160816; b=jANbprbbgP3pK2qHJcX/dkUqKjgu/bQW3RRm/ATogAWwuyqqYKcVKD8LwXyx1GAHhj IfYn1gdgouNxvttpUNoXY0cFNgwGbSWR2dxK6OHCXoWuBmI216DTaaKOXXYnWF/iRPQN NRUztAiElsE5wPKRKXDIhBJelHe3VrQ7yOCkBMQqqCakPpqAPphDtdNMB0lWpqmtv9Vd Eh6MEZWgC+T+UwiZxHv7g3VB8hxh77YSuSenkCcvSw380POy6glqK6m9TzuooWriMMJv l4TVts5ts0gwPi0Q2VnvUOiH7piXPT/LLW91Djx/gICfi8EHj92kXBAkgscwK+ygT6LZ VUFA== 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=mk8CoyJcsq5YtzNh3tpYg5cWpF5ocUXCyqcr8a4ESlQ=; b=Qh811foW0L5gzk4nHsrPbgM6vB1ZsWE1X5R2vVkRreVo5ocKDhqgHtP83xqpWzvdCV EoWBcUTLInVkp+QaCv13kV7St91z8n7ZLEWEtE3eSI6XZ5Np9swXTPfkj/BSTtwJWrQe MC9OqkAK+iKUXejkHr8cUv/1/jz8fLAmvwfaExTeFKTk0MkAG+OzLR/oKeRYs6pdM/iA K3OQlVFlOaRiThjejgXGaE9H27sVQ/fpqmFgRN84Y0FFZJQSWLdzCImaa5zxFK1hfSvT akZYNlnZqrq9pjxFHcTmU/XUlJHhG4RS0rQNdHXkqNe1uM/3aN7KYaP1G8P1jcLfod8k WMWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kRpEf1FP; 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 p22si1139311ota.43.2020.02.21.00.21.50; Fri, 21 Feb 2020 00:22:01 -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=kRpEf1FP; 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 S2388226AbgBUIVH (ORCPT + 99 others); Fri, 21 Feb 2020 03:21:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:60282 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388208AbgBUIU7 (ORCPT ); Fri, 21 Feb 2020 03:20:59 -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 C624E206ED; Fri, 21 Feb 2020 08:20:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582273259; bh=GRvpBHdwaRmGyhqFV9SutAkddtjGkMHJbBSngALE17A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kRpEf1FPcZLkTXzMhwqOA0Cs3clMncHDg4x/okiEyDIt1Uoa300LZNVpxy19ojq94 Zd8NwXlqz7iB9Lw4SOkLgsKfj/1I0X7/243xNX/EqCVM7+ind7m6y33Frkl6lO0Ndu jgqTigRD+x8gkV6yLdZ/GyztA10jPitoxBY2rIvQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sascha Hauer , Robin Gong , Vinod Koul , Sasha Levin Subject: [PATCH 4.19 087/191] dmaengine: imx-sdma: Fix memory leak Date: Fri, 21 Feb 2020 08:41:00 +0100 Message-Id: <20200221072301.597359445@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072250.732482588@linuxfoundation.org> References: <20200221072250.732482588@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: Sascha Hauer [ Upstream commit 02939cd167095f16328a1bd5cab5a90b550606df ] The current descriptor is not on any list of the virtual DMA channel. Once sdma_terminate_all() is called when a descriptor is currently in flight then this one is forgotten to be freed. We have to call vchan_terminate_vdesc() on this descriptor to re-add it to the lists. Now that we also free the currently running descriptor we can (and actually have to) remove the current descriptor from its list also for the cyclic case. Signed-off-by: Sascha Hauer Reviewed-by: Robin Gong Tested-by: Robin Gong Link: https://lore.kernel.org/r/20191216105328.15198-10-s.hauer@pengutronix.de Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/dma/imx-sdma.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index ceb82e74f5b4e..d66a7fdff898e 100644 --- a/drivers/dma/imx-sdma.c +++ b/drivers/dma/imx-sdma.c @@ -738,12 +738,8 @@ static void sdma_start_desc(struct sdma_channel *sdmac) return; } sdmac->desc = desc = to_sdma_desc(&vd->tx); - /* - * Do not delete the node in desc_issued list in cyclic mode, otherwise - * the desc allocated will never be freed in vchan_dma_desc_free_list - */ - if (!(sdmac->flags & IMX_DMA_SG_LOOP)) - list_del(&vd->node); + + list_del(&vd->node); sdma->channel_control[channel].base_bd_ptr = desc->bd_phys; sdma->channel_control[channel].current_bd_ptr = desc->bd_phys; @@ -1044,7 +1040,6 @@ static void sdma_channel_terminate_work(struct work_struct *work) spin_lock_irqsave(&sdmac->vc.lock, flags); vchan_get_all_descriptors(&sdmac->vc, &head); - sdmac->desc = NULL; spin_unlock_irqrestore(&sdmac->vc.lock, flags); vchan_dma_desc_free_list(&sdmac->vc, &head); } @@ -1052,11 +1047,19 @@ static void sdma_channel_terminate_work(struct work_struct *work) static int sdma_disable_channel_async(struct dma_chan *chan) { struct sdma_channel *sdmac = to_sdma_chan(chan); + unsigned long flags; + + spin_lock_irqsave(&sdmac->vc.lock, flags); sdma_disable_channel(chan); - if (sdmac->desc) + if (sdmac->desc) { + vchan_terminate_vdesc(&sdmac->desc->vd); + sdmac->desc = NULL; schedule_work(&sdmac->terminate_worker); + } + + spin_unlock_irqrestore(&sdmac->vc.lock, flags); return 0; } -- 2.20.1