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 <jiri@nvidia.com>
Link: https://patch.msgid.link/20260312100407.551173-4-jiri@resnulli.us
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jiri Pirko 2026-03-12 11:03:57 +01:00 committed by Jakub Kicinski
parent 0f5531879a
commit e2e3666fd3

View File

@ -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,