Skip to contentSkip to conversation

qed: fix unnecessary call to memset cocci warnings

PATCH In review Vasyl Gomonovych 3 participants 7 messages Nov 15, 2017 – Nov 20, 2017

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

PATCH 1/1 qed: fix unnecessary call to memset cocci warnings

Use kzalloc rather than kmalloc followed by memset with 0 drivers/net/ethernet/qlogic/qed/qed_dcbx.c:1280:13-20: WARNING:
kzalloc should be used for dcbx_info, instead of kmalloc/memset Generated by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci

Originally was fixed in:
'commit 561ed23331df ("qed: fix kzalloc-simple.cocci warnings")' But later warning was introduced in:
'commit 62289ba27558 ("qed: Fix possible system hang in the dcbnl-getdcbx() path.")'

---
 drivers/net/ethernet/qlogic/qed/qed_dcbx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/qlogic/qed/qed_dcbx.c +1 -2
index 8f6ccc0c39e5..9a1bd996a640 100644
@@ -1277,11 +1277,10 @@ static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct qed_hwfn *hwfn,
 {
 	struct qed_dcbx_get *dcbx_info;
 
-	dcbx_info = kmalloc(sizeof(*dcbx_info), GFP_ATOMIC);
+	dcbx_info = kzmalloc(sizeof(*dcbx_info), GFP_ATOMIC);
 	if (!dcbx_info)
 		return NULL;
 
-	memset(dcbx_info, 0, sizeof(*dcbx_info));
 	if (qed_dcbx_query_params(hwfn, dcbx_info, type)) {
 		kfree(dcbx_info);
 		return NULL;
Signature · 1 line
1.9.1
maintainer
#1 lore raw

From: Vasyl Gomonovych <[email protected]>
Date: Wed, 15 Nov 2017 20:58:15 +0100

drivers/net/ethernet/qlogic/qed/qed_dcbx.c static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct qed_hwfn *hwfn, · line 1280

Quoted 6 lines
drivers/net/ethernet/qlogic/qed/qed_dcbx.c +1 -1
@@ -1277,11 +1277,10 @@ static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct qed_hwfn *hwfn,
 {
 	struct qed_dcbx_get *dcbx_info;
 
-	dcbx_info = kmalloc(sizeof(*dcbx_info), GFP_ATOMIC);
+	dcbx_info = kzmalloc(sizeof(*dcbx_info), GFP_ATOMIC);

Thanks for not even compile testing your patch.

#3 lore raw

PATCH 1/1 qed: fix unnecessary call to memset cocci warnings

In reply to Vasyl Gomonovych

Use kzalloc rather than kmalloc followed by memset with 0

drivers/net/ethernet/qlogic/qed/qed_dcbx.c:1280:13-20: WARNING:
kzalloc should be used for dcbx_info, instead of kmalloc/memset Generated by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci

---
 drivers/net/ethernet/qlogic/qed/qed_dcbx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/qlogic/qed/qed_dcbx.c +1 -2
index 8f6ccc0c39e5..cc9e0dfcee48 100644
@@ -1277,11 +1277,10 @@ static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct qed_hwfn *hwfn,
 {
 	struct qed_dcbx_get *dcbx_info;
 
-	dcbx_info = kmalloc(sizeof(*dcbx_info), GFP_ATOMIC);
+	dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_ATOMIC);
 	if (!dcbx_info)
 		return NULL;
 
-	memset(dcbx_info, 0, sizeof(*dcbx_info));
 	if (qed_dcbx_query_params(hwfn, dcbx_info, type)) {
 		kfree(dcbx_info);
 		return NULL;
Signature · 1 line
1.9.1
Reviewed-by on v1 1/1
#4 lore raw
Quoted 5 lines · Vasyl Gomonovych

Use kzalloc rather than kmalloc followed by memset with 0

drivers/net/ethernet/qlogic/qed/qed_dcbx.c:1280:13-20: WARNING:
kzalloc should be used for dcbx_info, instead of kmalloc/memset Generated by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci

While this looks okay per se now, it would be good if you put version of the patch and add a changelog to it.

I think no need to resend this one, just for your information.

Quoted 25 lines
---
 drivers/net/ethernet/qlogic/qed/qed_dcbx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/qlogic/qed/qed_dcbx.c +1 -3
index 8f6ccc0c39e5..cc9e0dfcee48 100644
@@ -1277,11 +1277,10 @@ static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct qed_hwfn *hwfn,
 {
        struct qed_dcbx_get *dcbx_info;
 
-       dcbx_info = kmalloc(sizeof(*dcbx_info), GFP_ATOMIC);
+       dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_ATOMIC);
        if (!dcbx_info)
                return NULL;
 
-       memset(dcbx_info, 0, sizeof(*dcbx_info));
        if (qed_dcbx_query_params(hwfn, dcbx_info, type)) {
                kfree(dcbx_info);
                return NULL;
--

1.9.1

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#5 lore raw
In reply to Vasyl Gomonovych

From: Vasyl Gomonovych <[email protected]>
Date: Thu, 16 Nov 2017 23:04:08 +0100

Quoted 7 lines

Use kzalloc rather than kmalloc followed by memset with 0

drivers/net/ethernet/qlogic/qed/qed_dcbx.c:1280:13-20: WARNING:
kzalloc should be used for dcbx_info, instead of kmalloc/memset Generated by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci

This patch doesn't even apply.