netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ionic_lif: Use devm_kcalloc() in ionic_qcq_alloc()
@ 2020-08-10  2:38 Xu Wang
  2020-08-10  3:20 ` Joe Perches
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Xu Wang @ 2020-08-10  2:38 UTC (permalink / raw)
  To: snelson, drivers, davem, kuba, netdev; +Cc: linux-kernel, Xu Wang

A multiplication for the size determination of a memory allocation
indicated that an array data structure should be processed.
Thus use the corresponding function "devm_kcalloc".

Signed-off-by: Xu Wang <vulab@iscas.ac.cn>
---
 drivers/net/ethernet/pensando/ionic/ionic_lif.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.c b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
index 1944bf5264db..26988ad7ec97 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_lif.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
@@ -412,7 +412,7 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
 
 	new->flags = flags;
 
-	new->q.info = devm_kzalloc(dev, sizeof(*new->q.info) * num_descs,
+	new->q.info = devm_kcalloc(dev, num_descs, sizeof(*new->q.info),
 				   GFP_KERNEL);
 	if (!new->q.info) {
 		netdev_err(lif->netdev, "Cannot allocate queue info\n");
@@ -462,7 +462,7 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
 		new->intr.index = IONIC_INTR_INDEX_NOT_ASSIGNED;
 	}
 
-	new->cq.info = devm_kzalloc(dev, sizeof(*new->cq.info) * num_descs,
+	new->cq.info = devm_kcalloc(dev, num_descs, sizeof(*new->cq.info),
 				    GFP_KERNEL);
 	if (!new->cq.info) {
 		netdev_err(lif->netdev, "Cannot allocate completion queue info\n");
-- 
2.17.1


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

* Re: [PATCH] ionic_lif: Use devm_kcalloc() in ionic_qcq_alloc()
  2020-08-10  2:38 [PATCH] ionic_lif: Use devm_kcalloc() in ionic_qcq_alloc() Xu Wang
@ 2020-08-10  3:20 ` Joe Perches
  2020-08-10  3:50   ` Shannon Nelson
  2020-08-10  3:54 ` Shannon Nelson
  2020-08-11 17:36 ` David Miller
  2 siblings, 1 reply; 6+ messages in thread
From: Joe Perches @ 2020-08-10  3:20 UTC (permalink / raw)
  To: Xu Wang, snelson, drivers, davem, kuba, netdev; +Cc: linux-kernel

On Mon, 2020-08-10 at 02:38 +0000, Xu Wang wrote:
> A multiplication for the size determination of a memory allocation
> indicated that an array data structure should be processed.
> Thus use the corresponding function "devm_kcalloc".
[]
> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.c b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
[]
> @@ -412,7 +412,7 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
>  
>  	new->flags = flags;
>  
> -	new->q.info = devm_kzalloc(dev, sizeof(*new->q.info) * num_descs,
> +	new->q.info = devm_kcalloc(dev, num_descs, sizeof(*new->q.info),
>  				   GFP_KERNEL);
>  	if (!new->q.info) {
>  		netdev_err(lif->netdev, "Cannot allocate queue info\n");

You could also remove these unnecessary allocation error messages.
There is an existing dump_stack() on allocation failure.

> @@ -462,7 +462,7 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
>  		new->intr.index = IONIC_INTR_INDEX_NOT_ASSIGNED;
>  	}
>  
> -	new->cq.info = devm_kzalloc(dev, sizeof(*new->cq.info) * num_descs,
> +	new->cq.info = devm_kcalloc(dev, num_descs, sizeof(*new->cq.info),
>  				    GFP_KERNEL);
>  	if (!new->cq.info) {
>  		netdev_err(lif->netdev, "Cannot allocate completion queue info\n");


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

* Re: [PATCH] ionic_lif: Use devm_kcalloc() in ionic_qcq_alloc()
  2020-08-10  3:20 ` Joe Perches
@ 2020-08-10  3:50   ` Shannon Nelson
  2020-08-10  3:54     ` Joe Perches
  0 siblings, 1 reply; 6+ messages in thread
From: Shannon Nelson @ 2020-08-10  3:50 UTC (permalink / raw)
  To: Joe Perches, Xu Wang, drivers, davem, kuba, netdev; +Cc: linux-kernel

On 8/9/20 8:20 PM, Joe Perches wrote:
> On Mon, 2020-08-10 at 02:38 +0000, Xu Wang wrote:
>> A multiplication for the size determination of a memory allocation
>> indicated that an array data structure should be processed.
>> Thus use the corresponding function "devm_kcalloc".
> []
>> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.c b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
> []
>> @@ -412,7 +412,7 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
>>   
>>   	new->flags = flags;
>>   
>> -	new->q.info = devm_kzalloc(dev, sizeof(*new->q.info) * num_descs,
>> +	new->q.info = devm_kcalloc(dev, num_descs, sizeof(*new->q.info),
>>   				   GFP_KERNEL);
>>   	if (!new->q.info) {
>>   		netdev_err(lif->netdev, "Cannot allocate queue info\n");
> You could also remove these unnecessary allocation error messages.
> There is an existing dump_stack() on allocation failure.
>
Yes, the dump_stack() tells you which function had the allocation 
failure, but since there are multiple allocation operations in this same 
function, I find these helpful in knowing quickly which one of the 
allocations failed, without having to track down the symbols and source 
for whatever distro's kernel this might have happened in.

sln


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

* Re: [PATCH] ionic_lif: Use devm_kcalloc() in ionic_qcq_alloc()
  2020-08-10  2:38 [PATCH] ionic_lif: Use devm_kcalloc() in ionic_qcq_alloc() Xu Wang
  2020-08-10  3:20 ` Joe Perches
@ 2020-08-10  3:54 ` Shannon Nelson
  2020-08-11 17:36 ` David Miller
  2 siblings, 0 replies; 6+ messages in thread
From: Shannon Nelson @ 2020-08-10  3:54 UTC (permalink / raw)
  To: Xu Wang, drivers, davem, kuba, netdev; +Cc: linux-kernel

On 8/9/20 7:38 PM, Xu Wang wrote:
> A multiplication for the size determination of a memory allocation
> indicated that an array data structure should be processed.
> Thus use the corresponding function "devm_kcalloc".
>
> Signed-off-by: Xu Wang <vulab@iscas.ac.cn>

Acked-by: Shannon Nelson <snelson@pensando.io>

> ---
>   drivers/net/ethernet/pensando/ionic/ionic_lif.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.c b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
> index 1944bf5264db..26988ad7ec97 100644
> --- a/drivers/net/ethernet/pensando/ionic/ionic_lif.c
> +++ b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
> @@ -412,7 +412,7 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
>   
>   	new->flags = flags;
>   
> -	new->q.info = devm_kzalloc(dev, sizeof(*new->q.info) * num_descs,
> +	new->q.info = devm_kcalloc(dev, num_descs, sizeof(*new->q.info),
>   				   GFP_KERNEL);
>   	if (!new->q.info) {
>   		netdev_err(lif->netdev, "Cannot allocate queue info\n");
> @@ -462,7 +462,7 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
>   		new->intr.index = IONIC_INTR_INDEX_NOT_ASSIGNED;
>   	}
>   
> -	new->cq.info = devm_kzalloc(dev, sizeof(*new->cq.info) * num_descs,
> +	new->cq.info = devm_kcalloc(dev, num_descs, sizeof(*new->cq.info),
>   				    GFP_KERNEL);
>   	if (!new->cq.info) {
>   		netdev_err(lif->netdev, "Cannot allocate completion queue info\n");


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

* Re: [PATCH] ionic_lif: Use devm_kcalloc() in ionic_qcq_alloc()
  2020-08-10  3:50   ` Shannon Nelson
@ 2020-08-10  3:54     ` Joe Perches
  0 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2020-08-10  3:54 UTC (permalink / raw)
  To: Shannon Nelson, Xu Wang, drivers, davem, kuba, netdev; +Cc: linux-kernel

On Sun, 2020-08-09 at 20:50 -0700, Shannon Nelson wrote:
> On 8/9/20 8:20 PM, Joe Perches wrote:
> > On Mon, 2020-08-10 at 02:38 +0000, Xu Wang wrote:
> > > A multiplication for the size determination of a memory allocation
> > > indicated that an array data structure should be processed.
> > > Thus use the corresponding function "devm_kcalloc".
> > []
> > > diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.c b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
> > []
> > > @@ -412,7 +412,7 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
> > >   
> > >   	new->flags = flags;
> > >   
> > > -	new->q.info = devm_kzalloc(dev, sizeof(*new->q.info) * num_descs,
> > > +	new->q.info = devm_kcalloc(dev, num_descs, sizeof(*new->q.info),
> > >   				   GFP_KERNEL);
> > >   	if (!new->q.info) {
> > >   		netdev_err(lif->netdev, "Cannot allocate queue info\n");
> > You could also remove these unnecessary allocation error messages.
> > There is an existing dump_stack() on allocation failure.
> > 
> Yes, the dump_stack() tells you which function had the allocation 
> failure, but since there are multiple allocation operations in this same 
> function, I find these helpful in knowing quickly which one of the 
> allocations failed, without having to track down the symbols and source 
> for whatever distro's kernel this might have happened in.

If you do chose the message, might as well add __GFP_NOWARN
to the allocation to avoid the dump_stack().

But honestly, if any allocation fails, you're OOM anyway.


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

* Re: [PATCH] ionic_lif: Use devm_kcalloc() in ionic_qcq_alloc()
  2020-08-10  2:38 [PATCH] ionic_lif: Use devm_kcalloc() in ionic_qcq_alloc() Xu Wang
  2020-08-10  3:20 ` Joe Perches
  2020-08-10  3:54 ` Shannon Nelson
@ 2020-08-11 17:36 ` David Miller
  2 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2020-08-11 17:36 UTC (permalink / raw)
  To: vulab; +Cc: snelson, drivers, kuba, netdev, linux-kernel

From: Xu Wang <vulab@iscas.ac.cn>
Date: Mon, 10 Aug 2020 02:38:07 +0000

> A multiplication for the size determination of a memory allocation
> indicated that an array data structure should be processed.
> Thus use the corresponding function "devm_kcalloc".
> 
> Signed-off-by: Xu Wang <vulab@iscas.ac.cn>

Applied, thanks.

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

end of thread, other threads:[~2020-08-11 17:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-10  2:38 [PATCH] ionic_lif: Use devm_kcalloc() in ionic_qcq_alloc() Xu Wang
2020-08-10  3:20 ` Joe Perches
2020-08-10  3:50   ` Shannon Nelson
2020-08-10  3:54     ` Joe Perches
2020-08-10  3:54 ` Shannon Nelson
2020-08-11 17:36 ` David Miller

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