Message ID | 20240311085726.273193-1-shayd@nvidia.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net] devlink: Fix devlink parallel commands processing | expand |
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);
diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index 499885c8b9ca..cffc7274de8c 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -193,15 +193,20 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs, devname = nla_data(attrs[DEVLINK_ATTR_DEV_NAME]); 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; 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); }