From: Vladimir Oltean <olteanv@gmail.com>
To: Yuan Can <yuancan@huawei.com>
Cc: ioana.ciornei@nxp.com, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org
Subject: Re: [PATCH] dpaa2-switch: Fix memory leak in dpaa2_switch_acl_entry_add() and dpaa2_switch_acl_entry_remove()
Date: Wed, 7 Dec 2022 13:55:37 +0200 [thread overview]
Message-ID: <20221207115537.zf2ikns77bxyt74m@skbuf> (raw)
In-Reply-To: <20221205061515.115012-1-yuancan@huawei.com>
Hi Yuan,
On Mon, Dec 05, 2022 at 06:15:15AM +0000, Yuan Can wrote:
> The cmd_buff needs to be freed when error happened in
> dpaa2_switch_acl_entry_add() and dpaa2_switch_acl_entry_remove().
>
> Fixes: 1110318d83e8 ("dpaa2-switch: add tc flower hardware offload on ingress traffic")
> Signed-off-by: Yuan Can <yuancan@huawei.com>
> ---
> drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-flower.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-flower.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-flower.c
> index cacd454ac696..c39b866e2582 100644
> --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-flower.c
> +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-flower.c
> @@ -132,6 +132,7 @@ int dpaa2_switch_acl_entry_add(struct dpaa2_switch_filter_block *filter_block,
> DMA_TO_DEVICE);
> if (unlikely(dma_mapping_error(dev, acl_entry_cfg->key_iova))) {
> dev_err(dev, "DMA mapping failed\n");
> + kfree(cmd_buff);
> return -EFAULT;
> }
>
> @@ -142,6 +143,7 @@ int dpaa2_switch_acl_entry_add(struct dpaa2_switch_filter_block *filter_block,
> DMA_TO_DEVICE);
> if (err) {
> dev_err(dev, "dpsw_acl_add_entry() failed %d\n", err);
> + kfree(cmd_buff);
To reduce the number of kfree() calls, this last one can be put right
before checking for error, and we could remove the kfree(cmd_buff) call at
the very end. I mean that was already the intention, if you look at the
dma_unmap_single() call compared to the error checking. Like this:
err = dpsw_acl_add_entry(...);
dma_unmap_single(dev, acl_entry_cfg->key_iova, sizeof(cmd_buff),
DMA_TO_DEVICE);
kfree(cmd_buff);
if (err) {
dev_err(dev, "dpsw_acl_add_entry() failed %d\n", err);
return err;
}
return 0;
}
> return err;
> }
>
> @@ -172,6 +174,7 @@ dpaa2_switch_acl_entry_remove(struct dpaa2_switch_filter_block *block,
> DMA_TO_DEVICE);
> if (unlikely(dma_mapping_error(dev, acl_entry_cfg->key_iova))) {
> dev_err(dev, "DMA mapping failed\n");
> + kfree(cmd_buff);
> return -EFAULT;
> }
>
> @@ -182,6 +185,7 @@ dpaa2_switch_acl_entry_remove(struct dpaa2_switch_filter_block *block,
> DMA_TO_DEVICE);
> if (err) {
> dev_err(dev, "dpsw_acl_remove_entry() failed %d\n", err);
> + kfree(cmd_buff);
Similar here:
err = dpsw_acl_remove_entry(ethsw->mc_io, 0, ethsw->dpsw_handle,
block->acl_id, acl_entry_cfg);
dma_unmap_single(dev, acl_entry_cfg->key_iova, sizeof(cmd_buff),
DMA_TO_DEVICE);
kfree(cmd_buff);
if (err) {
dev_err(dev, "dpsw_acl_remove_entry() failed %d\n", err);
return err;
}
return 0;
}
> return err;
> }
>
> --
> 2.17.1
>
next prev parent reply other threads:[~2022-12-07 11:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-05 6:15 [PATCH] dpaa2-switch: Fix memory leak in dpaa2_switch_acl_entry_add() and dpaa2_switch_acl_entry_remove() Yuan Can
2022-12-07 11:20 ` patchwork-bot+netdevbpf
2022-12-07 11:55 ` Vladimir Oltean [this message]
2022-12-08 1:51 ` Yuan Can
2022-12-08 14:20 ` Vladimir Oltean
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=20221207115537.zf2ikns77bxyt74m@skbuf \
--to=olteanv@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=ioana.ciornei@nxp.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=yuancan@huawei.com \
/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