mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: Guangshuo Li <lgs201920130244@gmail.com>
Cc: Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
	Kees Cook <kees@kernel.org>, Peng Ma <peng.ma@nxp.com>,
	dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] dmaengine: fsl-dpaa2-qdma: fix ppriv memory leaks
Date: Mon, 14 Sep 2026 10:12:36 -0500	[thread overview]
Message-ID: <aqgO5PfShs5FG--f@SMW015318> (raw)
In-Reply-To: <20260913045001.1126563-1-lgs201920130244@gmail.com>

On Sun, Sep 13, 2026 at 12:50:01PM +0800, Guangshuo Li wrote:
> dpaa2_qdma_setup() allocates priv->ppriv separately from priv, but the
> allocation is not released on all teardown paths.
>
> If dpdmai_get_rx_queue() or dpdmai_get_tx_queue() fails after
> priv->ppriv has been allocated, dpaa2_qdma_setup() returns through the
> error path without freeing it.
>
> The normal remove path has the same issue. dpaa2_qdma_remove() frees
> priv without first releasing priv->ppriv, losing the only reference to
> the separately allocated array.
>
> Free priv->ppriv on setup failures that occur after its allocation and
> during normal driver removal before freeing priv.
>
> This issue was found by manual code inspection.
>
> Fixes: 7fdf9b05c73b ("dmaengine: fsl-dpaa2-qdma: Add NXP dpaa2 qDMA controller driver for Layerscape SoCs")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---

qdma_setup() is called by probe() only use devm_ allocate function

Frank

>  drivers/dma/fsl-dpaa2-qdma/dpaa2-qdma.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/dma/fsl-dpaa2-qdma/dpaa2-qdma.c b/drivers/dma/fsl-dpaa2-qdma/dpaa2-qdma.c
> index bf771251264d..0f0fe0291a06 100644
> --- a/drivers/dma/fsl-dpaa2-qdma/dpaa2-qdma.c
> +++ b/drivers/dma/fsl-dpaa2-qdma/dpaa2-qdma.c
> @@ -365,7 +365,7 @@ static int __cold dpaa2_qdma_setup(struct fsl_mc_device *ls_dev)
>  					  i, 0, &priv->rx_queue_attr[i]);
>  		if (err) {
>  			dev_err(dev, "dpdmai_get_rx_queue() failed\n");
> -			goto exit;
> +			goto err_free_ppriv;
>  		}
>  		ppriv->rsp_fqid = priv->rx_queue_attr[i].fqid;
>
> @@ -373,7 +373,7 @@ static int __cold dpaa2_qdma_setup(struct fsl_mc_device *ls_dev)
>  					  i, 0, &priv->tx_queue_attr[i]);
>  		if (err) {
>  			dev_err(dev, "dpdmai_get_tx_queue() failed\n");
> -			goto exit;
> +			goto err_free_ppriv;
>  		}
>  		ppriv->req_fqid = priv->tx_queue_attr[i].fqid;
>  		ppriv->prio = DPAA2_QDMA_DEFAULT_PRIORITY;
> @@ -382,6 +382,9 @@ static int __cold dpaa2_qdma_setup(struct fsl_mc_device *ls_dev)
>  	}
>
>  	return 0;
> +
> +err_free_ppriv:
> +	kfree(priv->ppriv);
>  exit:
>  	dpdmai_close(priv->mc_io, 0, ls_dev->mc_handle);
>  	return err;
> @@ -787,6 +790,7 @@ static void dpaa2_qdma_remove(struct fsl_mc_device *ls_dev)
>  	dpaa2_dpdmai_free_channels(dpaa2_qdma);
>
>  	dma_async_device_unregister(&dpaa2_qdma->dma_dev);
> +	kfree(priv->ppriv);
>  	kfree(priv);
>  	kfree(dpaa2_qdma);
>  }
> --
> 2.43.0
>

      reply	other threads:[~2026-09-14 15:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-13  4:50 Guangshuo Li
2026-09-14 15:12 ` Frank Li [this message]

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=aqgO5PfShs5FG--f@SMW015318 \
    --to=frank.li@oss.nxp.com \
    --cc=Frank.Li@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=kees@kernel.org \
    --cc=lgs201920130244@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peng.ma@nxp.com \
    --cc=stable@vger.kernel.org \
    --cc=vkoul@kernel.org \
    /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

all inboxes | Powered by JetHome®