From: Jiri Pirko Devlink instances without a backing device use bus_name "devlink_index" and dev_name set to the decimal index string. When user space sends this handle, detect the pattern and perform a direct xarray lookup by index instead of iterating all instances. Signed-off-by: Jiri Pirko --- net/devlink/netlink.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index b73cec31089f..127f337489c0 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -200,6 +200,15 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs, busname = nla_data(attrs[DEVLINK_ATTR_BUS_NAME]); devname = nla_data(attrs[DEVLINK_ATTR_DEV_NAME]); + if (!strcmp(busname, DEVLINK_INDEX_BUS_NAME)) { + if (kstrtoul(devname, 10, &index)) + return ERR_PTR(-EINVAL); + devlink = devlinks_xa_lookup_get(net, index); + if (!devlink) + return ERR_PTR(-ENODEV); + goto found; + } + devlinks_xa_for_each_registered_get(net, index, devlink) { if (strcmp(devlink->bus_name, busname) == 0 && strcmp(devlink->dev_name, devname) == 0) -- 2.51.1