diff mbox

qed: fix kzalloc-simple.cocci warnings

Message ID 20160901064512.GA49421@lkp-sb04
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

kbuild test robot Sept. 1, 2016, 6:45 a.m. UTC
drivers/net/ethernet/qlogic/qed/qed_dcbx.c:1230:13-20: WARNING: kzalloc should be used for dcbx_info, instead of kmalloc/memset
drivers/net/ethernet/qlogic/qed/qed_dcbx.c:1192:13-20: WARNING: kzalloc should be used for dcbx_info, instead of kmalloc/memset


 Use kzalloc rather than kmalloc followed by memset with 0

 This considers some simple cases that are common and easy to validate
 Note in particular that there are no ...s in the rule, so all of the
 matched code has to be contiguous

Generated by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci

CC: Sudarsana Reddy Kalluru <sudarsana.kalluru@qlogic.com>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
---

 qed_dcbx.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Yuval Mintz Sept. 1, 2016, 7:37 a.m. UTC | #1
> drivers/net/ethernet/qlogic/qed/qed_dcbx.c:1230:13-20: WARNING: kzalloc
> should be used for dcbx_info, instead of kmalloc/memset
> drivers/net/ethernet/qlogic/qed/qed_dcbx.c:1192:13-20: WARNING: kzalloc
> should be used for dcbx_info, instead of kmalloc/memset
> 
> 
>  Use kzalloc rather than kmalloc followed by memset with 0
> 
>  This considers some simple cases that are common and easy to validate  Note in
> particular that there are no ...s in the rule, so all of the  matched code has to be
> contiguous
> 
> Generated by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
> 
> CC: Sudarsana Reddy Kalluru <sudarsana.kalluru@qlogic.com>
> Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>

This looks fine; But what's the right process here -
Dave - do we need to re-post this with the the right 'destination' in title
[net/net-next]? Or is it good as-is?
In case of latter,
Acked-by: Yuval Mintz <Yuval.Mintz@qlogic.com>

One question the automated script -
Can't it [relative] easily be upgraded to also have 'Fixes:' as part of its message?
David Miller Sept. 1, 2016, 4:48 p.m. UTC | #2
From: Yuval Mintz <Yuval.Mintz@qlogic.com>
Date: Thu, 1 Sep 2016 07:37:13 +0000

>> drivers/net/ethernet/qlogic/qed/qed_dcbx.c:1230:13-20: WARNING: kzalloc
>> should be used for dcbx_info, instead of kmalloc/memset
>> drivers/net/ethernet/qlogic/qed/qed_dcbx.c:1192:13-20: WARNING: kzalloc
>> should be used for dcbx_info, instead of kmalloc/memset
>> 
>> 
>>  Use kzalloc rather than kmalloc followed by memset with 0
>> 
>>  This considers some simple cases that are common and easy to validate  Note in
>> particular that there are no ...s in the rule, so all of the  matched code has to be
>> contiguous
>> 
>> Generated by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
>> 
>> CC: Sudarsana Reddy Kalluru <sudarsana.kalluru@qlogic.com>
>> Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
> 
> This looks fine; But what's the right process here -
> Dave - do we need to re-post this with the the right 'destination' in title
> [net/net-next]? Or is it good as-is?
> In case of latter,
> Acked-by: Yuval Mintz <Yuval.Mintz@qlogic.com>

I'll apply this as-is, thanks.
Joe Perches Sept. 2, 2016, 5:44 p.m. UTC | #3
On Thu, 2016-09-01 at 07:37 +0000, Yuval Mintz wrote:
> > drivers/net/ethernet/qlogic/qed/qed_dcbx.c:1230:13-20: WARNING: kzalloc
> > should be used for dcbx_info, instead of kmalloc/memset
> > drivers/net/ethernet/qlogic/qed/qed_dcbx.c:1192:13-20: WARNING: kzalloc
> > should be used for dcbx_info, instead of kmalloc/memset
> > 
> >  Use kzalloc rather than kmalloc followed by memset with 0
[]
> One question the automated script -
> Can't it [relative] easily be upgraded to also have 'Fixes:' as part
> of its message?

It's really not a "fix" as it has no real effect on behavior.

The code is perfectly fine as is really.

It is a code size reduction though.

Another thing with a behavior change and one that would also
reduce code size would be to remove the unnecessary OOM
messages after the allocs.

I'll send a patch for that.
diff mbox

Patch

--- a/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
@@ -1189,13 +1189,12 @@  int qed_dcbx_get_config_params(struct qe
 		return 0;
 	}
 
-	dcbx_info = kmalloc(sizeof(*dcbx_info), GFP_KERNEL);
+	dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_KERNEL);
 	if (!dcbx_info) {
 		DP_ERR(p_hwfn, "Failed to allocate struct qed_dcbx_info\n");
 		return -ENOMEM;
 	}
 
-	memset(dcbx_info, 0, sizeof(*dcbx_info));
 	rc = qed_dcbx_query_params(p_hwfn, dcbx_info, QED_DCBX_OPERATIONAL_MIB);
 	if (rc) {
 		kfree(dcbx_info);
@@ -1227,13 +1226,12 @@  static struct qed_dcbx_get *qed_dcbnl_ge
 {
 	struct qed_dcbx_get *dcbx_info;
 
-	dcbx_info = kmalloc(sizeof(*dcbx_info), GFP_KERNEL);
+	dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_KERNEL);
 	if (!dcbx_info) {
 		DP_ERR(hwfn->cdev, "Failed to allocate memory for dcbx_info\n");
 		return NULL;
 	}
 
-	memset(dcbx_info, 0, sizeof(*dcbx_info));
 	if (qed_dcbx_query_params(hwfn, dcbx_info, type)) {
 		kfree(dcbx_info);
 		return NULL;