From: Ido Schimmel Date: Thu, 15 Jan 2026 11:50:04 +0000 (+0200) Subject: devlink: Fix resource show output X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2b24087e1546c65593d39ee2ba7cb55d58f8a0b;p=thirdparty%2Fiproute2.git devlink: Fix resource show output When the user asks to show device resources, devlink first queries the device's dpipe tables so that it will be able to show the association between resources and dpipe tables. In this flow, 'ctx->resources' is always NULL as resources have yet to be retrieved. As a result, the dpipe tables are not associated with a resource identifier and the resource show command does not show any dpipe tables: $ devlink resource show pci/0000:03:00.0 pci/0000:03:00.0: name kvd size 258048 unit entry dpipe_tables none resources: name linear size 98304 occ 1 unit entry size_min 0 size_max 159744 size_gran 128 dpipe_tables none resources: name singles size 16384 occ 1 unit entry size_min 0 size_max 159744 size_gran 1 dpipe_tables none name chunks size 49152 occ 0 unit entry size_min 0 size_max 159744 size_gran 32 dpipe_tables none name large_chunks size 32768 occ 0 unit entry size_min 0 size_max 159744 size_gran 512 dpipe_tables none name hash_double size 65408 unit entry size_min 32768 size_max 192512 size_gran 128 dpipe_tables none name hash_single size 94336 unit entry size_min 65536 size_max 225280 size_gran 128 dpipe_tables none name span_agents size 3 occ 0 unit entry dpipe_tables none name counters size 32766 occ 4 unit entry dpipe_tables none resources: name rif size 8192 occ 0 unit entry dpipe_tables none name flow size 24574 occ 4 unit entry dpipe_tables none name global_policers size 1000 unit entry dpipe_tables none resources: name single_rate_policers size 968 occ 0 unit entry dpipe_tables none name rif_mac_profiles size 1 occ 0 unit entry dpipe_tables none name rifs size 1000 occ 1 unit entry dpipe_tables none name port_range_registers size 16 occ 0 unit entry dpipe_tables none name physical_ports size 64 occ 32 unit entry dpipe_tables none Fix by moving the check against 'ctx->resources' to the place where it is actually used. Output after the fix: $ devlink resource show pci/0000:03:00.0 pci/0000:03:00.0: name kvd size 258048 unit entry dpipe_tables none resources: name linear size 98304 occ 1 unit entry size_min 0 size_max 159744 size_gran 128 dpipe_tables: table_name mlxsw_adj resources: name singles size 16384 occ 1 unit entry size_min 0 size_max 159744 size_gran 1 dpipe_tables none name chunks size 49152 occ 0 unit entry size_min 0 size_max 159744 size_gran 32 dpipe_tables none name large_chunks size 32768 occ 0 unit entry size_min 0 size_max 159744 size_gran 512 dpipe_tables none name hash_double size 65408 unit entry size_min 32768 size_max 192512 size_gran 128 dpipe_tables: table_name mlxsw_host6 name hash_single size 94336 unit entry size_min 65536 size_max 225280 size_gran 128 dpipe_tables: table_name mlxsw_host4 name span_agents size 3 occ 0 unit entry dpipe_tables none name counters size 32766 occ 4 unit entry dpipe_tables none resources: name rif size 8192 occ 0 unit entry dpipe_tables none name flow size 24574 occ 4 unit entry dpipe_tables none name global_policers size 1000 unit entry dpipe_tables none resources: name single_rate_policers size 968 occ 0 unit entry dpipe_tables none name rif_mac_profiles size 1 occ 0 unit entry dpipe_tables none name rifs size 1000 occ 1 unit entry dpipe_tables none name port_range_registers size 16 occ 0 unit entry dpipe_tables none name physical_ports size 64 occ 32 unit entry dpipe_tables none Fixes: 0e7e1819453c ("devlink: relax dpipe table show dependency on resources") Reviewed-by: Petr Machata Reviewed-by: Jiri Pirko Signed-off-by: Ido Schimmel Signed-off-by: Stephen Hemminger --- diff --git a/devlink/devlink.c b/devlink/devlink.c index b95fd348..0b3bf197 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -8088,8 +8088,7 @@ static int dpipe_table_show(struct dpipe_ctx *ctx, struct nlattr *nl) size = mnl_attr_get_u32(nla_table[DEVLINK_ATTR_DPIPE_TABLE_SIZE]); counters_enabled = !!mnl_attr_get_u8(nla_table[DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED]); - resource_valid = nla_table[DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_ID] && - ctx->resources; + resource_valid = !!nla_table[DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_ID]; if (resource_valid) { table->resource_id = mnl_attr_get_u64(nla_table[DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_ID]); table->resource_valid = true; @@ -8104,7 +8103,7 @@ static int dpipe_table_show(struct dpipe_ctx *ctx, struct nlattr *nl) print_uint(PRINT_ANY, "size", " size %u", size); print_bool(PRINT_ANY, "counters_enabled", " counters_enabled %s", counters_enabled); - if (resource_valid) { + if (resource_valid && ctx->resources) { resource_units = mnl_attr_get_u32(nla_table[DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_UNITS]); resource_path_print(ctx->dl, ctx->resources, table->resource_id);