mirror of
https://github.com/linux-msm/laptops-kernel.git
synced 2026-08-13 14:19:53 -07:00
devlink: support index-based lookup via bus_name/dev_name handle
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 <jiri@nvidia.com> Link: https://patch.msgid.link/20260312100407.551173-6-jiri@resnulli.us Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
committed by
Jakub Kicinski
parent
d85a8af57d
commit
725d5fdb7b
@@ -19,6 +19,8 @@
|
||||
#define DEVLINK_GENL_VERSION 0x1
|
||||
#define DEVLINK_GENL_MCGRP_CONFIG_NAME "config"
|
||||
|
||||
#define DEVLINK_INDEX_BUS_NAME "devlink_index"
|
||||
|
||||
enum devlink_command {
|
||||
/* don't change the order or add anything between, this is ABI! */
|
||||
DEVLINK_CMD_UNSPEC,
|
||||
|
||||
@@ -203,6 +203,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(-ENODEV);
|
||||
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(devlink), busname) == 0 &&
|
||||
strcmp(devlink_dev_name(devlink), devname) == 0)
|
||||
|
||||
Reference in New Issue
Block a user