linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] qed: fix kzalloc-simple.cocci warnings
       [not found] <201704210853.tUPLU4Mh%fengguang.wu@intel.com>
@ 2017-04-21  0:20 ` kbuild test robot
  2017-04-24 16:03   ` David Miller
  0 siblings, 1 reply; 6+ messages in thread
From: kbuild test robot @ 2017-04-21  0:20 UTC (permalink / raw)
  To: sudarsana.kalluru
  Cc: kbuild-all, netdev, Sudarsana Reddy Kalluru, Yuval Mintz,
	Ariel Elior, everest-linux-l2, linux-kernel

drivers/net/ethernet/qlogic/qed/qed_dcbx.c:1267: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.kalluru@cavium.com <sudarsana.kalluru@cavium.com>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
---

 qed_dcbx.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

--- a/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
@@ -1264,11 +1264,10 @@ static struct qed_dcbx_get *qed_dcbnl_ge
 {
 	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;

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] qed: fix kzalloc-simple.cocci warnings
  2017-04-21  0:20 ` [PATCH] qed: fix kzalloc-simple.cocci warnings kbuild test robot
@ 2017-04-24 16:03   ` David Miller
  0 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2017-04-24 16:03 UTC (permalink / raw)
  To: fengguang.wu
  Cc: sudarsana.kalluru, kbuild-all, netdev, Yuval.Mintz, Ariel.Elior,
	everest-linux-l2, linux-kernel

From: kbuild test robot <fengguang.wu@intel.com>
Date: Fri, 21 Apr 2017 08:20:07 +0800

> drivers/net/ethernet/qlogic/qed/qed_dcbx.c:1267: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.kalluru@cavium.com <sudarsana.kalluru@cavium.com>
> Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>

I intentionally let this change happen.

It was less risky than asking the submitter who introduced it to
make another respin to keep the kzalloc().

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] qed: fix kzalloc-simple.cocci warnings
  2016-09-01  7:37   ` Yuval Mintz
  2016-09-01 16:48     ` David Miller
@ 2016-09-02 17:44     ` Joe Perches
  1 sibling, 0 replies; 6+ messages in thread
From: Joe Perches @ 2016-09-02 17:44 UTC (permalink / raw)
  To: Yuval Mintz, kbuild test robot, David Miller
  Cc: kbuild-all, netdev, Ariel Elior, Dept-Eng Everest Linux L2,
	linux-kernel, Sudarsana Kalluru

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] qed: fix kzalloc-simple.cocci warnings
  2016-09-01  7:37   ` Yuval Mintz
@ 2016-09-01 16:48     ` David Miller
  2016-09-02 17:44     ` Joe Perches
  1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2016-09-01 16:48 UTC (permalink / raw)
  To: Yuval.Mintz
  Cc: fengguang.wu, kbuild-all, netdev, Ariel.Elior,
	Dept-EngEverestLinuxL2, linux-kernel, Sudarsana.Kalluru

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH] qed: fix kzalloc-simple.cocci warnings
  2016-09-01  6:45 ` kbuild test robot
@ 2016-09-01  7:37   ` Yuval Mintz
  2016-09-01 16:48     ` David Miller
  2016-09-02 17:44     ` Joe Perches
  0 siblings, 2 replies; 6+ messages in thread
From: Yuval Mintz @ 2016-09-01  7:37 UTC (permalink / raw)
  To: kbuild test robot, David Miller
  Cc: kbuild-all, netdev, Ariel Elior, Dept-Eng Everest Linux L2,
	linux-kernel, Sudarsana Kalluru

> 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?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] qed: fix kzalloc-simple.cocci warnings
       [not found] <201609011409.GGSqCknq%fengguang.wu@intel.com>
@ 2016-09-01  6:45 ` kbuild test robot
  2016-09-01  7:37   ` Yuval Mintz
  0 siblings, 1 reply; 6+ messages in thread
From: kbuild test robot @ 2016-09-01  6:45 UTC (permalink / raw)
  To: Sudarsana Reddy Kalluru
  Cc: kbuild-all, netdev, Yuval Mintz, Ariel Elior, everest-linux-l2,
	linux-kernel

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(-)

--- 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;

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-04-24 16:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <201704210853.tUPLU4Mh%fengguang.wu@intel.com>
2017-04-21  0:20 ` [PATCH] qed: fix kzalloc-simple.cocci warnings kbuild test robot
2017-04-24 16:03   ` David Miller
     [not found] <201609011409.GGSqCknq%fengguang.wu@intel.com>
2016-09-01  6:45 ` kbuild test robot
2016-09-01  7:37   ` Yuval Mintz
2016-09-01 16:48     ` David Miller
2016-09-02 17:44     ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).