diff mbox series

octeontx2-pf: Fix a memleak otx2_sq_init

Message ID 20240201124714.3053525-1-alexious@zju.edu.cn (mailing list archive)
State Accepted
Commit b09b58e31b0f43d76f79b9943da3fb7c2843dcbb
Delegated to: Netdev Maintainers
Headers show
Series octeontx2-pf: Fix a memleak otx2_sq_init | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 0 of 0 maintainers
netdev/build_clang success Errors and warnings before: 1065 this patch: 1065
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
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: 1070 this patch: 1070
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 27 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-02-02--15-00 (tests: 720)

Commit Message

Zhipeng Lu Feb. 1, 2024, 12:47 p.m. UTC
When qmem_alloc and pfvf->hw_ops->sq_aq_init fails, sq->sg should be
freed to prevent memleak.

Fixes: c9c12d339d93 ("octeontx2-pf: Add support for PTP clock")
Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
---
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

Comments

Jiri Pirko Feb. 1, 2024, 2:01 p.m. UTC | #1
Thu, Feb 01, 2024 at 01:47:13PM CET, alexious@zju.edu.cn wrote:
>When qmem_alloc and pfvf->hw_ops->sq_aq_init fails, sq->sg should be
>freed to prevent memleak.
>
>Fixes: c9c12d339d93 ("octeontx2-pf: Add support for PTP clock")
>Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>

Acked-by: Jiri Pirko <jiri@nvidia.com>
Subbaraya Sundeep Bhatta Feb. 2, 2024, 5:01 a.m. UTC | #2
Looks good to me.

Thanks,
Sundeep

>-----Original Message-----
>From: Zhipeng Lu <alexious@zju.edu.cn>
>Sent: Thursday, February 1, 2024 6:17 PM
>To: alexious@zju.edu.cn
>Cc: Sunil Kovvuri Goutham <sgoutham@marvell.com>; Geethasowjanya Akula
><gakula@marvell.com>; Subbaraya Sundeep Bhatta <sbhatta@marvell.com>;
>Hariprasad Kelam <hkelam@marvell.com>; David S. Miller
><davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub Kicinski
><kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; Jesse Brandeburg
><jesse.brandeburg@intel.com>; Richard Cochran <richardcochran@gmail.com>;
>netdev@vger.kernel.org; linux-kernel@vger.kernel.org
>Subject: [EXT] [PATCH] octeontx2-pf: Fix a memleak otx2_sq_init
>
>External Email
>
>----------------------------------------------------------------------
>When qmem_alloc and pfvf->hw_ops->sq_aq_init fails, sq->sg should be freed to
>prevent memleak.
>
>Fixes: c9c12d339d93 ("octeontx2-pf: Add support for PTP clock")
>Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
>---
> .../ethernet/marvell/octeontx2/nic/otx2_common.c   | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
>b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
>index 7ca6941ea0b9..02d0b707aea5 100644
>--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
>+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
>@@ -951,8 +951,11 @@ int otx2_sq_init(struct otx2_nic *pfvf, u16 qidx, u16
>sqb_aura)
> 	if (pfvf->ptp && qidx < pfvf->hw.tx_queues) {
> 		err = qmem_alloc(pfvf->dev, &sq->timestamps, qset->sqe_cnt,
> 				 sizeof(*sq->timestamps));
>-		if (err)
>+		if (err) {
>+			kfree(sq->sg);
>+			sq->sg = NULL;
> 			return err;
>+		}
> 	}
>
> 	sq->head = 0;
>@@ -968,7 +971,14 @@ int otx2_sq_init(struct otx2_nic *pfvf, u16 qidx, u16
>sqb_aura)
> 	sq->stats.bytes = 0;
> 	sq->stats.pkts = 0;
>
>-	return pfvf->hw_ops->sq_aq_init(pfvf, qidx, sqb_aura);
>+	err = pfvf->hw_ops->sq_aq_init(pfvf, qidx, sqb_aura);
>+	if (err) {
>+		kfree(sq->sg);
>+		sq->sg = NULL;
>+		return err;
>+	}
>+
>+	return 0;
>
> }
>
>--
>2.34.1
patchwork-bot+netdevbpf@kernel.org Feb. 3, 2024, 12:50 p.m. UTC | #3
Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:

On Thu,  1 Feb 2024 20:47:13 +0800 you wrote:
> When qmem_alloc and pfvf->hw_ops->sq_aq_init fails, sq->sg should be
> freed to prevent memleak.
> 
> Fixes: c9c12d339d93 ("octeontx2-pf: Add support for PTP clock")
> Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
> ---
>  .../ethernet/marvell/octeontx2/nic/otx2_common.c   | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)

Here is the summary with links:
  - octeontx2-pf: Fix a memleak otx2_sq_init
    https://git.kernel.org/netdev/net/c/b09b58e31b0f

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
index 7ca6941ea0b9..02d0b707aea5 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
@@ -951,8 +951,11 @@  int otx2_sq_init(struct otx2_nic *pfvf, u16 qidx, u16 sqb_aura)
 	if (pfvf->ptp && qidx < pfvf->hw.tx_queues) {
 		err = qmem_alloc(pfvf->dev, &sq->timestamps, qset->sqe_cnt,
 				 sizeof(*sq->timestamps));
-		if (err)
+		if (err) {
+			kfree(sq->sg);
+			sq->sg = NULL;
 			return err;
+		}
 	}
 
 	sq->head = 0;
@@ -968,7 +971,14 @@  int otx2_sq_init(struct otx2_nic *pfvf, u16 qidx, u16 sqb_aura)
 	sq->stats.bytes = 0;
 	sq->stats.pkts = 0;
 
-	return pfvf->hw_ops->sq_aq_init(pfvf, qidx, sqb_aura);
+	err = pfvf->hw_ops->sq_aq_init(pfvf, qidx, sqb_aura);
+	if (err) {
+		kfree(sq->sg);
+		sq->sg = NULL;
+		return err;
+	}
+
+	return 0;
 
 }