Skip to contentSkip to conversation

amd/pds_core: core: No need for Null pointer check before kfree

PATCH Applied Bragatheswaran Manickavel 4 participants 5 messages Oct 24, 2023 – Oct 25, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 amd/pds_core: core: No need for Null pointer check before kfree

kfree()/vfree() internally perform NULL check on the pointer handed to it and take no action if it indeed is NULL. Hence there is no need for a pre-check of the memory pointer before handing it to kfree()/vfree().

Issue reported by ifnullfree.cocci Coccinelle semantic patch script.

---
 drivers/net/ethernet/amd/pds_core/core.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/ethernet/amd/pds_core/core.c +2 -5
index 2a8643e167e1..0d2091e9eb28 100644
@@ -152,11 +152,8 @@ void pdsc_qcq_free(struct pdsc *pdsc, struct pdsc_qcq *qcq)
 		dma_free_coherent(dev, qcq->cq_size,
 				  qcq->cq_base, qcq->cq_base_pa);
 
-	if (qcq->cq.info)
-		vfree(qcq->cq.info);
-
-	if (qcq->q.info)
-		vfree(qcq->q.info);
+	vfree(qcq->cq.info);
+	vfree(qcq->q.info);
 
 	memset(qcq, 0, sizeof(*qcq));
 }
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Bragatheswaran Manickavel

kfree()/vfree() internally perform NULL check on the pointer handed to it and take no action if it indeed is NULL. Hence there is no need for a pre-check of the memory pointer before handing it to kfree()/vfree().

Issue reported by ifnullfree.cocci Coccinelle semantic patch script.

Thanks -sln

Quoted 25 lines
---
  drivers/net/ethernet/amd/pds_core/core.c | 7 ++-----
  1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/ethernet/amd/pds_core/core.c +2 -6
index 2a8643e167e1..0d2091e9eb28 100644
@@ -152,11 +152,8 @@ void pdsc_qcq_free(struct pdsc *pdsc, struct pdsc_qcq *qcq)
                 dma_free_coherent(dev, qcq->cq_size,
                                   qcq->cq_base, qcq->cq_base_pa);
 
-       if (qcq->cq.info)
-               vfree(qcq->cq.info);
-
-       if (qcq->q.info)
-               vfree(qcq->q.info);
+       vfree(qcq->cq.info);
+       vfree(qcq->q.info);
 
         memset(qcq, 0, sizeof(*qcq));
  }
--

2.34.1

Reviewed-by on v1 1/1
#2 lore raw
In reply to Bragatheswaran Manickavel
Quoted 10 lines · Bragatheswaran Manickavel

kfree()/vfree() internally perform NULL check on the pointer handed to it and take no action if it indeed is NULL. Hence there is no need for a pre-check of the memory pointer before handing it to kfree()/vfree().

Issue reported by ifnullfree.cocci Coccinelle semantic patch script.

---

Thanks for the patch!
One nit, you're missing a target tag. It should be [PATCH net-next] since this not a fix IMO.

Quoted 21 lines
 drivers/net/ethernet/amd/pds_core/core.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/ethernet/amd/pds_core/core.c +2 -5
index 2a8643e167e1..0d2091e9eb28 100644
@@ -152,11 +152,8 @@ void pdsc_qcq_free(struct pdsc *pdsc, struct pdsc_qcq *qcq)
 		dma_free_coherent(dev, qcq->cq_size,
 				  qcq->cq_base, qcq->cq_base_pa);
 
-	if (qcq->cq.info)
-		vfree(qcq->cq.info);
-
-	if (qcq->q.info)
-		vfree(qcq->q.info);
+	vfree(qcq->cq.info);
+	vfree(qcq->q.info);
 
 	memset(qcq, 0, sizeof(*qcq));
 }
#3 lore raw

Thanks Shannon!

Quoted 7 lines · Wojciech Drewek
Quoted 5 lines · Bragatheswaran Manickavel

kfree()/vfree() internally perform NULL check on the pointer handed to it and take no action if it indeed is NULL. Hence there is no need for a pre-check of the memory pointer before handing it to kfree()/vfree().

Quoted 8 lines
Quoted 5 lines

Issue reported by ifnullfree.cocci Coccinelle semantic patch script.

---

Thanks for the patch!
One nit, you're missing a target tag. It should be [PATCH net-next] since this not a fix IMO.

Hi Wojciech,
Will take care of this next time. Thanks!

Quoted 21 lines
Quoted 21 lines
  drivers/net/ethernet/amd/pds_core/core.c | 7 ++-----
  1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/ethernet/amd/pds_core/core.c +2 -5
index 2a8643e167e1..0d2091e9eb28 100644
@@ -152,11 +152,8 @@ void pdsc_qcq_free(struct pdsc *pdsc, struct pdsc_qcq *qcq)
  		dma_free_coherent(dev, qcq->cq_size,
  				  qcq->cq_base, qcq->cq_base_pa);
 
-	if (qcq->cq.info)
-		vfree(qcq->cq.info);
-
-	if (qcq->q.info)
-		vfree(qcq->q.info);
+	vfree(qcq->cq.info);
+	vfree(qcq->q.info);
 
  	memset(qcq, 0, sizeof(*qcq));
  }
#4 lore raw
In reply to Bragatheswaran Manickavel
This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Hello:

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

Quoted 9 lines · On Tue, 24 Oct 2023 23:50:51 +0530 you wrote:

kfree()/vfree() internally perform NULL check on the pointer handed to it and take no action if it indeed is NULL. Hence there is no need for a pre-check of the memory pointer before handing it to kfree()/vfree().

Issue reported by ifnullfree.cocci Coccinelle semantic patch script.

[...]

Here is the summary with links:
- amd/pds_core: core: No need for Null pointer check before kfree

    https://git.kernel.org/netdev/net-next/c/d0110443cf4a

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html