octeontx2-pf: Add check for devm_kcalloc

Message ID 20221122055449.31247-1-jiasheng@iscas.ac.cn
State New
Headers
Series octeontx2-pf: Add check for devm_kcalloc |

Commit Message

Jiasheng Jiang Nov. 22, 2022, 5:54 a.m. UTC
  As the devm_kcalloc may return NULL pointer,
it should be better to add check for the return
value, as same as the others.

Fixes: e8e095b3b370 ("octeontx2-af: cn10k: Bandwidth profiles config support")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Maciej Fijalkowski Nov. 22, 2022, noon UTC | #1
On Tue, Nov 22, 2022 at 01:54:49PM +0800, Jiasheng Jiang wrote:
> As the devm_kcalloc may return NULL pointer,
> it should be better to add check for the return
> value, as same as the others.
> 
> Fixes: e8e095b3b370 ("octeontx2-af: cn10k: Bandwidth profiles config support")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
>  drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c
> index 7646bb2ec89b..a62c1b322012 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c
> @@ -4985,6 +4985,8 @@ static int nix_setup_ipolicers(struct rvu *rvu,
>  		ipolicer->ref_count = devm_kcalloc(rvu->dev,
>  						   ipolicer->band_prof.max,
>  						   sizeof(u16), GFP_KERNEL);
> +		if (!ipolicer->ref_count)
> +			return -ENOMEM;

So every other successful devm_kcalloc() calls in here don't have to be
explicitly freed in case of an error as in the end rvu_nix_init() will
fail and therefore the probe() itself.

Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>

Please also remember to state which tree you are targetting your patch
(this is a fix so you should have [PATCH net])

>  	}
>  
>  	/* Set policer timeunit to 2us ie  (19 + 1) * 100 nsec = 2us */
> -- 
> 2.25.1
>
  
patchwork-bot+netdevbpf@kernel.org Nov. 24, 2022, 8 a.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (master)
by Paolo Abeni <pabeni@redhat.com>:

On Tue, 22 Nov 2022 13:54:49 +0800 you wrote:
> As the devm_kcalloc may return NULL pointer,
> it should be better to add check for the return
> value, as same as the others.
> 
> Fixes: e8e095b3b370 ("octeontx2-af: cn10k: Bandwidth profiles config support")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> 
> [...]

Here is the summary with links:
  - octeontx2-pf: Add check for devm_kcalloc
    https://git.kernel.org/netdev/net/c/cd07eadd5147

You are awesome, thank you!
  

Patch

diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c
index 7646bb2ec89b..a62c1b322012 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c
@@ -4985,6 +4985,8 @@  static int nix_setup_ipolicers(struct rvu *rvu,
 		ipolicer->ref_count = devm_kcalloc(rvu->dev,
 						   ipolicer->band_prof.max,
 						   sizeof(u16), GFP_KERNEL);
+		if (!ipolicer->ref_count)
+			return -ENOMEM;
 	}
 
 	/* Set policer timeunit to 2us ie  (19 + 1) * 100 nsec = 2us */