Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ethtool: Clarify len/n_stats fields in/out semantics

Document that the 'len' field in ethtool_gstrings and 'n_stats' field in
ethtool_stats optionally serve dual purposes: on entry they specify the
number of items requested, and on return they indicate the number
actually returned (which is not necessarily the same).

Signed-off-by: Gal Pressman <gal@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
Link: https://patch.msgid.link/20260115060544.481550-1-gal@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Gal Pressman and committed by
Jakub Kicinski
56787300 c2702249

+16 -2
+16 -2
include/uapi/linux/ethtool.h
··· 1096 1096 * struct ethtool_gstrings - string set for data tagging 1097 1097 * @cmd: Command number = %ETHTOOL_GSTRINGS 1098 1098 * @string_set: String set ID; one of &enum ethtool_stringset 1099 - * @len: On return, the number of strings in the string set 1099 + * @len: Number of strings in the string set 1100 1100 * @data: Buffer for strings. Each string is null-padded to a size of 1101 1101 * %ETH_GSTRING_LEN. 1102 1102 * 1103 1103 * Users must use %ETHTOOL_GSSET_INFO to find the number of strings in 1104 1104 * the string set. They must allocate a buffer of the appropriate 1105 1105 * size immediately following this structure. 1106 + * 1107 + * Setting @len on input is optional (though preferred), but must be zeroed 1108 + * otherwise. 1109 + * When set, @len will return the requested count if it matches the actual 1110 + * count; otherwise, it will be zero. 1111 + * This prevents issues when the number of strings is different than the 1112 + * userspace allocation. 1106 1113 */ 1107 1114 struct ethtool_gstrings { 1108 1115 __u32 cmd; ··· 1186 1179 /** 1187 1180 * struct ethtool_stats - device-specific statistics 1188 1181 * @cmd: Command number = %ETHTOOL_GSTATS 1189 - * @n_stats: On return, the number of statistics 1182 + * @n_stats: Number of statistics 1190 1183 * @data: Array of statistics 1191 1184 * 1192 1185 * Users must use %ETHTOOL_GSSET_INFO or %ETHTOOL_GDRVINFO to find the 1193 1186 * number of statistics that will be returned. They must allocate a 1194 1187 * buffer of the appropriate size (8 * number of statistics) 1195 1188 * immediately following this structure. 1189 + * 1190 + * Setting @n_stats on input is optional (though preferred), but must be zeroed 1191 + * otherwise. 1192 + * When set, @n_stats will return the requested count if it matches the actual 1193 + * count; otherwise, it will be zero. 1194 + * This prevents issues when the number of stats is different than the 1195 + * userspace allocation. 1196 1196 */ 1197 1197 struct ethtool_stats { 1198 1198 __u32 cmd;