diff mbox series

[net-next] nfp: nsp: Simplify array allocation

Message ID af578bd3eb471b9613bcba7f714cca7e297a4620.1643214385.git.robin.murphy@arm.com (mailing list archive)
State Accepted
Commit d9f393f468aa939b53cc81b43169953ce37d7cdb
Delegated to: Netdev Maintainers
Headers show
Series [net-next] nfp: nsp: Simplify array allocation | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Robin Murphy Jan. 26, 2022, 4:30 p.m. UTC
Prefer kcalloc() to kzalloc(array_size()) for allocating an array.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
 drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Simon Horman Jan. 27, 2022, 9:06 a.m. UTC | #1
On Wed, Jan 26, 2022 at 04:30:33PM +0000, Robin Murphy wrote:
> Prefer kcalloc() to kzalloc(array_size()) for allocating an array.
> 
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>

Hi Robin,

thanks for the cleanup.

One minor nit: I think "nfp: " would be a slightly more normal prefix
than "nfp: nsp: ".

That notwithstanding,

Acked-by: Simon Horman <simon.horman@corigine.com>

> ---
>  drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.c b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.c
> index 10e7d8b21c46..730fea214b8a 100644
> --- a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.c
> +++ b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.c
> @@ -513,7 +513,7 @@ nfp_nsp_command_buf_dma_sg(struct nfp_nsp *nsp,
>  	dma_size = BIT_ULL(dma_order);
>  	nseg = DIV_ROUND_UP(max_size, chunk_size);
>  
> -	chunks = kzalloc(array_size(sizeof(*chunks), nseg), GFP_KERNEL);
> +	chunks = kcalloc(nseg, sizeof(*chunks), GFP_KERNEL);
>  	if (!chunks)
>  		return -ENOMEM;
>  
> -- 
> 2.28.0.dirty
>
Robin Murphy Jan. 27, 2022, 12:42 p.m. UTC | #2
On 2022-01-27 09:06, Simon Horman wrote:
> On Wed, Jan 26, 2022 at 04:30:33PM +0000, Robin Murphy wrote:
>> Prefer kcalloc() to kzalloc(array_size()) for allocating an array.
>>
>> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
> 
> Hi Robin,
> 
> thanks for the cleanup.
> 
> One minor nit: I think "nfp: " would be a slightly more normal prefix
> than "nfp: nsp: ".

Ah, OK - from the git history it seemed about 50/50 one way or the 
other, so I guessed at the one that looked more specific to this 
particular file. I ran into this little anti-pattern in code I was 
working on, and this was the only other instance that a quick grep 
turned up so I figured I may as well fix it too.

> That notwithstanding,
> 
> Acked-by: Simon Horman <simon.horman@corigine.com>

Thanks!
Robin.

>> ---
>>   drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.c b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.c
>> index 10e7d8b21c46..730fea214b8a 100644
>> --- a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.c
>> +++ b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.c
>> @@ -513,7 +513,7 @@ nfp_nsp_command_buf_dma_sg(struct nfp_nsp *nsp,
>>   	dma_size = BIT_ULL(dma_order);
>>   	nseg = DIV_ROUND_UP(max_size, chunk_size);
>>   
>> -	chunks = kzalloc(array_size(sizeof(*chunks), nseg), GFP_KERNEL);
>> +	chunks = kcalloc(nseg, sizeof(*chunks), GFP_KERNEL);
>>   	if (!chunks)
>>   		return -ENOMEM;
>>   
>> -- 
>> 2.28.0.dirty
>>
patchwork-bot+netdevbpf@kernel.org Jan. 27, 2022, 2 p.m. UTC | #3
Hello:

This patch was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:

On Wed, 26 Jan 2022 16:30:33 +0000 you wrote:
> Prefer kcalloc() to kzalloc(array_size()) for allocating an array.
> 
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
> ---
>  drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Here is the summary with links:
  - [net-next] nfp: nsp: Simplify array allocation
    https://git.kernel.org/netdev/net-next/c/d9f393f468aa

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.c b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.c
index 10e7d8b21c46..730fea214b8a 100644
--- a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.c
+++ b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.c
@@ -513,7 +513,7 @@  nfp_nsp_command_buf_dma_sg(struct nfp_nsp *nsp,
 	dma_size = BIT_ULL(dma_order);
 	nseg = DIV_ROUND_UP(max_size, chunk_size);
 
-	chunks = kzalloc(array_size(sizeof(*chunks), nseg), GFP_KERNEL);
+	chunks = kcalloc(nseg, sizeof(*chunks), GFP_KERNEL);
 	if (!chunks)
 		return -ENOMEM;