2024-02-01 12:50:16

by Zhipeng Lu

[permalink] [raw]
Subject: [PATCH] octeontx2-pf: Fix a memleak otx2_sq_init

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 <[email protected]>
---
.../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



2024-02-01 14:02:31

by Jiri Pirko

[permalink] [raw]
Subject: Re: [PATCH] octeontx2-pf: Fix a memleak otx2_sq_init

Thu, Feb 01, 2024 at 01:47:13PM CET, [email protected] 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 <[email protected]>

Acked-by: Jiri Pirko <[email protected]>

2024-02-02 05:04:26

by Subbaraya Sundeep

[permalink] [raw]
Subject: RE: [EXT] [PATCH] octeontx2-pf: Fix a memleak otx2_sq_init

Looks good to me.

Thanks,
Sundeep

>-----Original Message-----
>From: Zhipeng Lu <[email protected]>
>Sent: Thursday, February 1, 2024 6:17 PM
>To: [email protected]
>Cc: Sunil Kovvuri Goutham <[email protected]>; Geethasowjanya Akula
><[email protected]>; Subbaraya Sundeep Bhatta <[email protected]>;
>Hariprasad Kelam <[email protected]>; David S. Miller
><[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski
><[email protected]>; Paolo Abeni <[email protected]>; Jesse Brandeburg
><[email protected]>; Richard Cochran <[email protected]>;
>[email protected]; [email protected]
>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 <[email protected]>
>---
> .../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


2024-02-03 12:50:55

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH] octeontx2-pf: Fix a memleak otx2_sq_init

Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:

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 <[email protected]>
> ---
> .../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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html