Subject: Re: [net PATCH v2 6/7] octeontx2-af: Skip PFs if not enabled

From: Simon Horman <[email-masked]>
Date: Sat, 8 Apr 2023 16:56:22 +0200

On Fri, Apr 07, 2023 at 05:53:43PM +0530, Sai Krishna wrote:
> From: Ratheesh Kannoth <[email-masked]>
> 
> Skip mbox initialization of disabled PFs. Firmware configures PFs
> and allocate mbox resources etc. Linux should configure particular
> PFs, which ever are enabled by firmware.
> 
> Fixes: 9bdc47a6e328 ("octeontx2-af: Mbox communication support btw AF and it's VFs")
> Signed-off-by: Ratheesh Kannoth <[email-masked]>
> Signed-off-by: Sunil Kovvuri Goutham <[email-masked]>
> Signed-off-by: Sai Krishna <[email-masked]>

...

> @@ -2343,8 +2349,27 @@ static int rvu_mbox_init(struct rvu *rvu, struct mbox_wq_info *mw,
>  	int err = -EINVAL, i, dir, dir_up;
>  	void __iomem *reg_base;
>  	struct rvu_work *mwork;
> +	unsigned long *pf_bmap;
>  	void **mbox_regions;
>  	const char *name;
> +	u64 cfg;
> +
> +	pf_bmap = devm_kcalloc(rvu->dev, BITS_TO_LONGS(num), sizeof(long), GFP_KERNEL);

Hi Sai and Ratheesh,

I am a little confused about the lifecycle of pf_bmap.
It is a local variable of this function.
But it is allocated using devm_kcalloc(), so it will persist for
the life of the device.

Also, I note that rvu_mbox_init() has too call sites.
So is there a situation where a pf_bmap is allocated more than once
for the same rvu->dev instance?

It seems to me it would be more appropriate to allocate bf_bmap using
kcalloc() take clear to free it before leaving rvu_mbox_init(),
as is already done for mbox_regions.

> +	if (!pf_bmap)
> +		return -ENOMEM;

...