Subject: Re: [PATCH net] devlink: Fix devlink parallel commands processing

From: Jakub Kicinski <[email-masked]>
Date: Mon, 11 Mar 2024 11:10:20 -0700

On Mon, 11 Mar 2024 10:57:26 +0200 Shay Drory wrote:
>  	devlinks_xa_for_each_registered_get(net, index, devlink) {
> -		devl_dev_lock(devlink, dev_lock);
> -		if (devl_is_registered(devlink) &&
> -		    strcmp(devlink->dev->bus->name, busname) == 0 &&
> +		if (strcmp(devlink->dev->bus->name, busname) == 0 &&
>  		    strcmp(dev_name(devlink->dev), devname) == 0)
> -			return devlink;
> -		devl_dev_unlock(devlink, dev_lock);
> +			goto found;

there's no need for a goto here:

		if (strcmp(devlink->dev->bus->name, busname) == 0 &&
		    strcmp(dev_name(devlink->dev), devname) == 0) {
			devl_dev_lock(devlink, dev_lock);
			if (devl_is_registered(devlink))
				return devlink;
			devl_dev_unlock(devlink, dev_lock);
		}

simpler, and also no change in behavior (in case some impossible
race happens and we have 2 devlinks with the same name, one already
unregistered and one registered).

>  		devlink_put(devlink);
>  	}
> +	return ERR_PTR(-ENODEV);
> +
> +found:
> +	devl_dev_lock(devlink, dev_lock);
> +	if (devl_is_registered(devlink))
> +		return devlink;
>  
> +	devl_dev_unlock(devlink, dev_lock);
> +	devlink_put(devlink);
>  	return ERR_PTR(-ENODEV);
-- 
pw-bot: cr