public inbox for alsa-devel@alsa-project.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Sasha Levin <sashal@kernel.org>, Xin Tan <tanxin.ctf@gmail.com>,
	Xiyu Yang <xiyuyang19@fudan.edu.cn>,
	alsa-devel@alsa-project.org,
	Peter Ujfalusi <peter.ujfalusi@ti.com>,
	Mark Brown <broonie@kernel.org>
Subject: [PATCH AUTOSEL 4.19 011/172] ASoC: davinci-mcasp: Fix dma_chan refcnt leak when getting dma type
Date: Wed, 17 Jun 2020 21:19:37 -0400	[thread overview]
Message-ID: <20200618012218.607130-11-sashal@kernel.org> (raw)
In-Reply-To: <20200618012218.607130-1-sashal@kernel.org>

From: Xiyu Yang <xiyuyang19@fudan.edu.cn>

[ Upstream commit a697ae6ea56e23397341b027098c1b11d9ab13da ]

davinci_mcasp_get_dma_type() invokes dma_request_chan(), which returns a
reference of the specified dma_chan object to "chan" with increased
refcnt.

When davinci_mcasp_get_dma_type() returns, local variable "chan" becomes
invalid, so the refcount should be decreased to keep refcount balanced.

The reference counting issue happens in one exception handling path of
davinci_mcasp_get_dma_type(). When chan device is NULL, the function
forgets to decrease the refcnt increased by dma_request_chan(), causing
a refcnt leak.

Fix this issue by calling dma_release_channel() when chan device is
NULL.

Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
Acked-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
Link: https://lore.kernel.org/r/1587818916-38730-1-git-send-email-xiyuyang19@fudan.edu.cn
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 sound/soc/davinci/davinci-mcasp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c
index 14ab16e1369f..1203de8aab99 100644
--- a/sound/soc/davinci/davinci-mcasp.c
+++ b/sound/soc/davinci/davinci-mcasp.c
@@ -1758,8 +1758,10 @@ static int davinci_mcasp_get_dma_type(struct davinci_mcasp *mcasp)
 				PTR_ERR(chan));
 		return PTR_ERR(chan);
 	}
-	if (WARN_ON(!chan->device || !chan->device->dev))
+	if (WARN_ON(!chan->device || !chan->device->dev)) {
+		dma_release_channel(chan);
 		return -EINVAL;
+	}
 
 	if (chan->device->dev->of_node)
 		ret = of_property_read_string(chan->device->dev->of_node,
-- 
2.25.1


  parent reply	other threads:[~2020-06-18  1:48 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200618012218.607130-1-sashal@kernel.org>
2020-06-18  1:19 ` [PATCH AUTOSEL 4.19 003/172] ASoC: tegra: tegra_wm8903: Support nvidia, headset property Sasha Levin
2020-06-18  1:19 ` Sasha Levin [this message]
2020-06-18  1:19 ` [PATCH AUTOSEL 4.19 014/172] ALSA: hda/realtek - Introduce polarity for micmute LED GPIO Sasha Levin
2020-06-18  1:19 ` [PATCH AUTOSEL 4.19 015/172] ALSA: isa/wavefront: prevent out of bounds write in ioctl Sasha Levin
2020-06-18  1:20 ` [PATCH AUTOSEL 4.19 047/172] ASoC: meson: add missing free_irq() in error path Sasha Levin
2020-06-19 13:28   ` Pavel Machek
2020-06-18  1:20 ` [PATCH AUTOSEL 4.19 064/172] ALSA: usb-audio: Improve frames size computation Sasha Levin
2020-06-18  1:20 ` [PATCH AUTOSEL 4.19 065/172] ALSA: usb-audio: Fix racy list management in output queue Sasha Levin
2020-06-18  1:20 ` [PATCH AUTOSEL 4.19 069/172] slimbus: ngd: get drvdata from correct device Sasha Levin
2020-06-18  1:20 ` [PATCH AUTOSEL 4.19 071/172] soundwire: slave: don't init debugfs on device registration error Sasha Levin
2020-06-18  1:21 ` [PATCH AUTOSEL 4.19 098/172] ASoC: Intel: bytcr_rt5640: Add quirk for Toshiba Encore WT8-A tablet Sasha Levin
2020-06-18  1:21 ` [PATCH AUTOSEL 4.19 119/172] ASoC: fix incomplete error-handling in img_i2s_in_probe Sasha Levin
2020-06-18  1:21 ` [PATCH AUTOSEL 4.19 133/172] ASoC: fsl_asrc_dma: Fix dma_chan leak when config DMA channel failed Sasha Levin
2020-06-18  1:22 ` [PATCH AUTOSEL 4.19 164/172] ASoC: core: only convert non DPCM link to DPCM link Sasha Levin
2020-06-18  1:22 ` [PATCH AUTOSEL 4.19 165/172] ASoC: Intel: bytcr_rt5640: Add quirk for Toshiba Encore WT10-A tablet Sasha Levin
2020-06-18  1:22 ` [PATCH AUTOSEL 4.19 166/172] ASoC: rt5645: Add platform-data for Asus T101HA Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200618012218.607130-11-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peter.ujfalusi@ti.com \
    --cc=stable@vger.kernel.org \
    --cc=tanxin.ctf@gmail.com \
    --cc=xiyuyang19@fudan.edu.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox