Subject: Re: [PATCH net-next] sfc: handle VI shortage on ef100 by readjusting the channels

From: Simon Horman <[email-masked]>
Date: Wed, 24 May 2023 12:09:56 +0200

On Wed, May 24, 2023 at 10:36:38AM +0100, Pieter Jansen van Vuuren wrote:
> When fewer VIs are allocated than what is allowed we can readjust
> the channels by calling efx_mcdi_alloc_vis() again.
> 
> Signed-off-by: Pieter Jansen van Vuuren <[email-masked]>
> Reviewed-by: Martin Habets <[email-masked]>

Hi Pieter,

this patch looks good to me.

Reviewed-by: Simon Horman <[email-masked]>

But during the review I noticed that Smatch flags some
problems in ef100_netdev.c that you may wish to address.
Please see below.

> ---
>  drivers/net/ethernet/sfc/ef100_netdev.c | 51 ++++++++++++++++++++++---
>  1 file changed, 45 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/ethernet/sfc/ef100_netdev.c b/drivers/net/ethernet/sfc/ef100_netdev.c
> index d916877b5a9a..c201e001f3b8 100644
> --- a/drivers/net/ethernet/sfc/ef100_netdev.c
> +++ b/drivers/net/ethernet/sfc/ef100_netdev.c

...

> @@ -133,9 +140,41 @@ static int ef100_net_open(struct net_device *net_dev)
>  		goto fail;
>  
>  	rc = ef100_alloc_vis(efx, &allocated_vis);
> -	if (rc)
> +	if (rc && rc != -EAGAIN)
>  		goto fail;
>  
> +	/* Try one more time but with the maximum number of channels
> +	 * equal to the allocated VIs, which would more likely succeed.
> +	 */
> +	if (rc == -EAGAIN) {
> +		rc = efx_mcdi_free_vis(efx);
> +		if (rc)
> +			goto fail;
> +
> +		efx_remove_interrupts(efx);
> +		efx->max_channels = allocated_vis;
> +
> +		rc = efx_probe_interrupts(efx);
> +		if (rc)
> +			goto fail;
> +
> +		rc = efx_set_channels(efx);
> +		if (rc)
> +			goto fail;
> +
> +		rc = ef100_alloc_vis(efx, &allocated_vis);
> +		if (rc && rc != -EAGAIN)
> +			goto fail;
> +
> +		/* It should be very unlikely that we failed here again, but in
> +		 * such a case we return ENOSPC.
> +		 */
> +		if (rc == -EAGAIN) {
> +			rc = -ENOSPC;
> +			goto fail;
> +		}
> +	}
> +
>  	rc = efx_probe_channels(efx);
>  	if (rc)
>  		return rc;

Not strictly related to this patch, but Smatch says that on error this should
probably free some resources. So perhaps:

		goto fail;

Also not strictly related this patch, but Smatch also noticed that
in ef100_probe_netdev net_dev does not seem to be freed on the error path.