From patchwork Wed Oct 9 09:11:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 175612 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp481955ill; Wed, 9 Oct 2019 02:11:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqxYDTKFkFkT6tAjsMyBruGeorRFfput/+qev+WHoCu9ACo8IXtSW+bHg6j3ktGKocc7GKSy X-Received: by 2002:a05:6402:134e:: with SMTP id y14mr2023215edw.55.1570612311558; Wed, 09 Oct 2019 02:11:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570612311; cv=none; d=google.com; s=arc-20160816; b=BuBNcEaikBtkS6oQhvtCq8WWoCw/A1ZwzEkCVTaNhxqLLH/Jd1np1DnnV5/uOHZ93i hYYakUBP0yPF67345FacjxxPZUlT0rWnrqwXn7Ij9cdH0A4AKOtiXAerV3as5fKkLne4 jSu2UdWHhJRsEKi5FIav7JvOqtB/hybJbr4tbGSXhnd0xvEkqWDOlT8TkOCmlCdnWruN IUFKA1CTYf8P2mFqi1u4Emu2/23aQIWHjNNhPGiuWhKfq8IwYLPrMsvbqyXQWo0uEppT tOnA7P7mRwTkx7YXudR4MSYdZ7s942SrBcGfybbdhvyxsL7whAL6xEaYxmWXwkJMplan 1DZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=O5t0e/gQse8Qw5vCIuQfPPdmME+fzFWGPG6GN+mUsd8=; b=XxeBIHdjHqUJekIMoRvU4kQ7GEmrBCZxDb2qjkh345TnhS20WPuiuSRSuiXUCoFChL LExrpfYztxmH9D06+EK74Y8RCxTHR+1nmZaBu/QV9oC1+gTqMXXKajTOC3Lu5RbbjHxD 2Mmh+bT9ZDVJCWYe36PXXbBm+gxYBK/7XgodiVszed4eutZtLrN/rLPo2LPTSu01fwmO YOxI1zpvtHsxTkAkflhw+k2bGOTx7hXyUwFdi44UZ7aCT0PyMx8h45i3CDtQhynA9ZA/ 0IKq/PHLnz0tQuEmhYq/gukX/SC3O3QMw71Sm7WLzxpfkzNU2llT5onCAmRNc6UxDqoH 38BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LoukXlwG; spf=pass (google.com: best guess record for domain of dmaengine-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=dmaengine-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g3si952838edj.220.2019.10.09.02.11.51; Wed, 09 Oct 2019 02:11:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dmaengine-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=@linaro.org header.s=google header.b=LoukXlwG; spf=pass (google.com: best guess record for domain of dmaengine-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=dmaengine-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726579AbfJIJLs (ORCPT + 3 others); Wed, 9 Oct 2019 05:11:48 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:37609 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725942AbfJIJLr (ORCPT ); Wed, 9 Oct 2019 05:11:47 -0400 Received: by mail-pg1-f193.google.com with SMTP id p1so1007226pgi.4 for ; Wed, 09 Oct 2019 02:11:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=O5t0e/gQse8Qw5vCIuQfPPdmME+fzFWGPG6GN+mUsd8=; b=LoukXlwGXcDpo42+DF7QA/ampXViZ8/qogRylR7ilMVvqTBR5C9prHUwp/JSDEPfHL wsxGbIsyAs24d6jeOL6KuV/JtF+Bv0Ynez+O/OD1IreIVHoI6xvNB3GNlyzXYHlwOlSN qs6kclNoibg5qb4HjCbyCz4nrnD4jp51YnY7Vtez7bL2fs8xoHY/Lu483aW2/OhTtrFU RkGQp/OlYBo8hzcukAFIAdhIkaiWkCN+pyCR4jwmvA13SyWGlgYSF83Vzk9BBLK64K9D ZxKnipZJPSwWSUr0wT+CLOGLFFiTLomqkczZR2ZISQd2W5jqsOVJZ+zRORQdSr6zul80 Ozew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=O5t0e/gQse8Qw5vCIuQfPPdmME+fzFWGPG6GN+mUsd8=; b=pxy7FvpUz8YcWWyUlZgfgvaLN8dnJ1WTWu20nvUSMj0M0p693PHjzmvx4Mb7xs9ryQ 8eL6Lm4ssuCsY4NklbU+wnfZrvxGgtRkwQBRUhfdvqzNTFlB795T40ebWt2ETcrF0tJu CVkJ5JatGvQGML0H5N9kZQDpNZ/M8O795lo0+olwkSjGRltQblxAIy4AZHKFRgueSg7L lPISYLS+RiiR9mM9A9KOo0Svi9YMcss35KY1FMXIDfrUbGcOhnPPszx4lj9eAO1jzGw6 Za3QcH3sVu2VcHuD8b/etv5Fp+HgDL6rjunHF+wwDQ52OyHwe8YyVbtV6pJPchjp3QeU zFQg== X-Gm-Message-State: APjAAAW5SLs5fFnUSkE5wqiG24t2KmaugovGB/OsglMjNAAS4BhnvWGq +sWsrG1wngkb6okSW3lKqaz7o7daJWrKow== X-Received: by 2002:a63:1c06:: with SMTP id c6mr3153861pgc.417.1570612306950; Wed, 09 Oct 2019 02:11:46 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id m68sm1642818pfb.122.2019.10.09.02.11.43 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Oct 2019 02:11:46 -0700 (PDT) From: Baolin Wang To: vkoul@kernel.org Cc: orsonzhai@gmail.com, zhang.lyra@gmail.com, dan.j.williams@intel.com, linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org, eric.long@unisoc.com, zhenfang.wang@unisoc.com, baolin.wang@linaro.org Subject: [PATCH] dmaengine: sprd: Fix the possible memory leak issue Date: Wed, 9 Oct 2019 17:11:30 +0800 Message-Id: <170dbbc6d5366b6fa974ce2d366652e23a334251.1570609788.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org 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 --- drivers/dma/sprd-dma.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) -- 1.7.9.5 diff --git a/drivers/dma/sprd-dma.c b/drivers/dma/sprd-dma.c index 60d2c6b..32402c2 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; }