All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net: marvell: prestera: fix memory leak in prestera_rxtx_switch_init()
@ 2022-11-08  2:56 Zhengchao Shao
  2022-11-08 10:00 ` Vadym Kochan
  2022-11-09  2:00 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Zhengchao Shao @ 2022-11-08  2:56 UTC (permalink / raw)
  To: netdev, tchornyi, davem, edumazet, kuba, pabeni
  Cc: vadym.kochan, andrii.savka, oleksandr.mazur, weiyongjun1,
	yuehaibing, shaozhengchao

When prestera_sdma_switch_init() failed, the memory pointed to by
sw->rxtx isn't released. Fix it. Only be compiled, not be tested.

Fixes: 501ef3066c89 ("net: marvell: prestera: Add driver for Prestera family ASIC devices")
Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 drivers/net/ethernet/marvell/prestera/prestera_rxtx.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/prestera/prestera_rxtx.c b/drivers/net/ethernet/marvell/prestera/prestera_rxtx.c
index 42ee963e9f75..9277a8fd1339 100644
--- a/drivers/net/ethernet/marvell/prestera/prestera_rxtx.c
+++ b/drivers/net/ethernet/marvell/prestera/prestera_rxtx.c
@@ -776,6 +776,7 @@ static netdev_tx_t prestera_sdma_xmit(struct prestera_sdma *sdma,
 int prestera_rxtx_switch_init(struct prestera_switch *sw)
 {
 	struct prestera_rxtx *rxtx;
+	int err;
 
 	rxtx = kzalloc(sizeof(*rxtx), GFP_KERNEL);
 	if (!rxtx)
@@ -783,7 +784,11 @@ int prestera_rxtx_switch_init(struct prestera_switch *sw)
 
 	sw->rxtx = rxtx;
 
-	return prestera_sdma_switch_init(sw);
+	err = prestera_sdma_switch_init(sw);
+	if (err)
+		kfree(rxtx);
+
+	return err;
 }
 
 void prestera_rxtx_switch_fini(struct prestera_switch *sw)
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: marvell: prestera: fix memory leak in prestera_rxtx_switch_init()
  2022-11-08  2:56 [PATCH net] net: marvell: prestera: fix memory leak in prestera_rxtx_switch_init() Zhengchao Shao
@ 2022-11-08 10:00 ` Vadym Kochan
  2022-11-09  2:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Vadym Kochan @ 2022-11-08 10:00 UTC (permalink / raw)
  To: Zhengchao Shao, netdev, tchornyi, davem, edumazet, kuba, pabeni
  Cc: andrii.savka, oleksandr.mazur, weiyongjun1, yuehaibing, shaozhengchao

Hi Shao,

On Tue, 8 Nov 2022 10:56:07 +0800, Zhengchao Shao <shaozhengchao@huawei.com> wrote:
> When prestera_sdma_switch_init() failed, the memory pointed to by
> sw->rxtx isn't released. Fix it. Only be compiled, not be tested.
> 
> Fixes: 501ef3066c89 ("net: marvell: prestera: Add driver for Prestera family ASIC devices")
> Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
> ---
>  drivers/net/ethernet/marvell/prestera/prestera_rxtx.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/marvell/prestera/prestera_rxtx.c b/drivers/net/ethernet/marvell/prestera/prestera_rxtx.c
> index 42ee963e9f75..9277a8fd1339 100644
> --- a/drivers/net/ethernet/marvell/prestera/prestera_rxtx.c
> +++ b/drivers/net/ethernet/marvell/prestera/prestera_rxtx.c
> @@ -776,6 +776,7 @@ static netdev_tx_t prestera_sdma_xmit(struct prestera_sdma *sdma,
>  int prestera_rxtx_switch_init(struct prestera_switch *sw)
>  {
>  	struct prestera_rxtx *rxtx;
> +	int err;
>  
>  	rxtx = kzalloc(sizeof(*rxtx), GFP_KERNEL);
>  	if (!rxtx)
> @@ -783,7 +784,11 @@ int prestera_rxtx_switch_init(struct prestera_switch *sw)
>  
>  	sw->rxtx = rxtx;
>  
> -	return prestera_sdma_switch_init(sw);
> +	err = prestera_sdma_switch_init(sw);
> +	if (err)
> +		kfree(rxtx);
> +
> +	return err;
>  }

Thanks, it makes sense.

Reviewed-by: Vadym Kochan <vadym.kochan@plvision.eu>

>  
>  void prestera_rxtx_switch_fini(struct prestera_switch *sw)
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: marvell: prestera: fix memory leak in prestera_rxtx_switch_init()
  2022-11-08  2:56 [PATCH net] net: marvell: prestera: fix memory leak in prestera_rxtx_switch_init() Zhengchao Shao
  2022-11-08 10:00 ` Vadym Kochan
@ 2022-11-09  2:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-11-09  2:00 UTC (permalink / raw)
  To: shaozhengchao
  Cc: netdev, tchornyi, davem, edumazet, kuba, pabeni, vadym.kochan,
	andrii.savka, oleksandr.mazur, weiyongjun1, yuehaibing

Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 8 Nov 2022 10:56:07 +0800 you wrote:
> When prestera_sdma_switch_init() failed, the memory pointed to by
> sw->rxtx isn't released. Fix it. Only be compiled, not be tested.
> 
> Fixes: 501ef3066c89 ("net: marvell: prestera: Add driver for Prestera family ASIC devices")
> Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
> ---
>  drivers/net/ethernet/marvell/prestera/prestera_rxtx.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)

Here is the summary with links:
  - [net] net: marvell: prestera: fix memory leak in prestera_rxtx_switch_init()
    https://git.kernel.org/netdev/net/c/519b58bbfa82

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-09  2:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-08  2:56 [PATCH net] net: marvell: prestera: fix memory leak in prestera_rxtx_switch_init() Zhengchao Shao
2022-11-08 10:00 ` Vadym Kochan
2022-11-09  2:00 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.