From: Jiri Pirko Date: Thu, 12 Mar 2026 10:03:57 +0000 (+0100) Subject: devlink: avoid extra iterations when found devlink is not registered X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e2e3666fd3609bfc03c42bd8544be8cbd080d24d;p=thirdparty%2Flinux.git devlink: avoid extra iterations when found devlink is not registered 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 Link: https://patch.msgid.link/20260312100407.551173-4-jiri@resnulli.us Signed-off-by: Jakub Kicinski --- diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index 56817b85a3f9e..7b205f677b7ae 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(devlink), busname) == 0 && - strcmp(devlink_dev_name(devlink), 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(devlink), 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,