public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v2] ethtool: Clarify len/n_stats fields in/out semantics
@ 2026-01-12 11:57 Gal Pressman
  2026-01-14  3:06 ` Jakub Kicinski
  0 siblings, 1 reply; 4+ messages in thread
From: Gal Pressman @ 2026-01-12 11:57 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, netdev
  Cc: Andrew Lunn, Simon Horman, Gal Pressman, Dragos Tatulea

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).

Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
Signed-off-by: Gal Pressman <gal@nvidia.com>
---
v1->v2: https://lore.kernel.org/all/20260105163923.49104-1-gal@nvidia.com/
* Reword comments (Jakub).
---
 include/uapi/linux/ethtool.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h
index eb7ff2602fbb..de810f1c3bfb 100644
--- a/include/uapi/linux/ethtool.h
+++ b/include/uapi/linux/ethtool.h
@@ -1101,6 +1101,13 @@ enum ethtool_module_fw_flash_status {
  * Users must use %ETHTOOL_GSSET_INFO to find the number of strings in
  * the string set.  They must allocate a buffer of the appropriate
  * size immediately following this structure.
+ *
+ * Setting @len on input is optional (though preferred), but must be zeroed
+ * otherwise.
+ * When set, @len will return the requested count if it matches the actual
+ * count; otherwise, it will be zero.
+ * This prevents issues when the number of strings is different than the
+ * userspace allocation.
  */
 struct ethtool_gstrings {
 	__u32	cmd;
@@ -1184,6 +1191,13 @@ struct ethtool_test {
  * number of statistics that will be returned.  They must allocate a
  * buffer of the appropriate size (8 * number of statistics)
  * immediately following this structure.
+ *
+ * Setting @n_stats on input is optional (though preferred), but must be zeroed
+ * otherwise.
+ * When set, @n_stats will return the requested count if it matches the actual
+ * count; otherwise, it will be zero.
+ * This prevents issues when the number of stats is different than the
+ * userspace allocation.
  */
 struct ethtool_stats {
 	__u32	cmd;
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next v2] ethtool: Clarify len/n_stats fields in/out semantics
  2026-01-12 11:57 [PATCH net-next v2] ethtool: Clarify len/n_stats fields in/out semantics Gal Pressman
@ 2026-01-14  3:06 ` Jakub Kicinski
  2026-01-14  6:50   ` Gal Pressman
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2026-01-14  3:06 UTC (permalink / raw)
  To: Gal Pressman
  Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Andrew Lunn, netdev,
	Andrew Lunn, Simon Horman, Dragos Tatulea

On Mon, 12 Jan 2026 13:57:08 +0200 Gal Pressman wrote:
> --- a/include/uapi/linux/ethtool.h
> +++ b/include/uapi/linux/ethtool.h
> @@ -1101,6 +1101,13 @@ enum ethtool_module_fw_flash_status {
>   * Users must use %ETHTOOL_GSSET_INFO to find the number of strings in
>   * the string set.  They must allocate a buffer of the appropriate
>   * size immediately following this structure.
> + *
> + * Setting @len on input is optional (though preferred), but must be zeroed
> + * otherwise.
> + * When set, @len will return the requested count if it matches the actual
> + * count; otherwise, it will be zero.
> + * This prevents issues when the number of strings is different than the
> + * userspace allocation.

Thanks the new text looks good, but we should also remove the 
"On return, the " from the field kdoc?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next v2] ethtool: Clarify len/n_stats fields in/out semantics
  2026-01-14  3:06 ` Jakub Kicinski
@ 2026-01-14  6:50   ` Gal Pressman
  2026-01-15  3:31     ` Jakub Kicinski
  0 siblings, 1 reply; 4+ messages in thread
From: Gal Pressman @ 2026-01-14  6:50 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Andrew Lunn, netdev,
	Andrew Lunn, Simon Horman, Dragos Tatulea

On 14/01/2026 5:06, Jakub Kicinski wrote:
> On Mon, 12 Jan 2026 13:57:08 +0200 Gal Pressman wrote:
>> --- a/include/uapi/linux/ethtool.h
>> +++ b/include/uapi/linux/ethtool.h
>> @@ -1101,6 +1101,13 @@ enum ethtool_module_fw_flash_status {
>>   * Users must use %ETHTOOL_GSSET_INFO to find the number of strings in
>>   * the string set.  They must allocate a buffer of the appropriate
>>   * size immediately following this structure.
>> + *
>> + * Setting @len on input is optional (though preferred), but must be zeroed
>> + * otherwise.
>> + * When set, @len will return the requested count if it matches the actual
>> + * count; otherwise, it will be zero.
>> + * This prevents issues when the number of strings is different than the
>> + * userspace allocation.
> 
> Thanks the new text looks good, but we should also remove the 
> "On return, the " from the field kdoc?

I think it makes sense to keep.

The new text clarifies the in behavior, but the out behavior remains.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next v2] ethtool: Clarify len/n_stats fields in/out semantics
  2026-01-14  6:50   ` Gal Pressman
@ 2026-01-15  3:31     ` Jakub Kicinski
  0 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2026-01-15  3:31 UTC (permalink / raw)
  To: Gal Pressman
  Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Andrew Lunn, netdev,
	Andrew Lunn, Simon Horman, Dragos Tatulea

On Wed, 14 Jan 2026 08:50:01 +0200 Gal Pressman wrote:
> On 14/01/2026 5:06, Jakub Kicinski wrote:
> > On Mon, 12 Jan 2026 13:57:08 +0200 Gal Pressman wrote:  
> >> --- a/include/uapi/linux/ethtool.h
> >> +++ b/include/uapi/linux/ethtool.h
> >> @@ -1101,6 +1101,13 @@ enum ethtool_module_fw_flash_status {
> >>   * Users must use %ETHTOOL_GSSET_INFO to find the number of strings in
> >>   * the string set.  They must allocate a buffer of the appropriate
> >>   * size immediately following this structure.
> >> + *
> >> + * Setting @len on input is optional (though preferred), but must be zeroed
> >> + * otherwise.
> >> + * When set, @len will return the requested count if it matches the actual
> >> + * count; otherwise, it will be zero.
> >> + * This prevents issues when the number of strings is different than the
> >> + * userspace allocation.  
> > 
> > Thanks the new text looks good, but we should also remove the 
> > "On return, the " from the field kdoc?  
> 
> I think it makes sense to keep.
> 
> The new text clarifies the in behavior, but the out behavior remains.

I'd interpret the "On return," as an indication that it's an output
only field. Not saying that's an intelligent interpretation, but it's
an existence proof. The uAPI comments should avoid ambiguity...

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-01-15  3:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-12 11:57 [PATCH net-next v2] ethtool: Clarify len/n_stats fields in/out semantics Gal Pressman
2026-01-14  3:06 ` Jakub Kicinski
2026-01-14  6:50   ` Gal Pressman
2026-01-15  3:31     ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox