diff mbox series

[net] net: marvell: prestera: fix memory leak in prestera_rxtx_switch_init()

Message ID 20221108025607.338450-1-shaozhengchao@huawei.com (mailing list archive)
State Accepted
Commit 519b58bbfa825f042fcf80261cc18e1e35f85ffd
Delegated to: Netdev Maintainers
Headers show
Series [net] net: marvell: prestera: fix memory leak in prestera_rxtx_switch_init() | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers fail 1 blamed authors not CCed: volodymyr.mytnyk@plvision.eu; 1 maintainers not CCed: volodymyr.mytnyk@plvision.eu
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 19 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

shaozhengchao Nov. 8, 2022, 2:56 a.m. UTC
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(-)

Comments

Vadym Kochan Nov. 8, 2022, 10 a.m. UTC | #1
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
>
patchwork-bot+netdevbpf@kernel.org Nov. 9, 2022, 2 a.m. UTC | #2
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!
diff mbox series

Patch

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)