From: Jiri Pirko <[email protected]> Since the one found is not registered, very unlikely another one with the same bus_name/dev_name is going to be found. Stop right away and prepare common "found" path for the follow-up patch.
Signed-off-by: Jiri Pirko <[email protected]> --- net/devlink/netlink.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index 3f73ced2d879..a517d42c7b96 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -194,16 +194,20 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs, devlinks_xa_for_each_registered_get(net, index, devlink) { if (strcmp(devlink->bus_name, busname) == 0 && - strcmp(devlink->dev_name, devname) == 0) { - devl_dev_lock(devlink, dev_lock); - if (devl_is_registered(devlink)) - return devlink; - devl_dev_unlock(devlink, dev_lock); - } + strcmp(devlink->dev_name, devname) == 0) + 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); } static int __devlink_nl_pre_doit(struct sk_buff *skb, struct genl_info *info, -- 2.51.1
