Re: [PATCH] ASoC: davinci-mcasp: Fix dma_chan refcnt leak when getting dma type

From: Peter Ujfalusi
Date: Tue Apr 28 2020 - 04:13:56 EST




On 25/04/2020 15.48, Xiyu Yang wrote:
> 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@xxxxxxxxxxxx>
> Signed-off-by: Xin Tan <tanxin.ctf@xxxxxxxxx>
> ---
> sound/soc/ti/davinci-mcasp.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/sound/soc/ti/davinci-mcasp.c b/sound/soc/ti/davinci-mcasp.c
> index 734ffe925c4d..7a7db743dc5b 100644
> --- a/sound/soc/ti/davinci-mcasp.c
> +++ b/sound/soc/ti/davinci-mcasp.c
> @@ -1896,8 +1896,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 we get a channel then chan->device and chan->device->dev never NULL,
it can not be.
I think the reason why this is here is that static checkers tends to
scream at us.

Acked-by: Peter Ujfalusi <peter.ujfalusi@xxxxxx>

>
> if (chan->device->dev->of_node)
> ret = of_property_read_string(chan->device->dev->of_node,
>

- PÃter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki