diff mbox series

[RFC,01/10] ethtool: Add common function for filling out strings

Message ID 161542651749.13546.3959589547085613076.stgit@localhost.localdomain (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series ethtool: Factor out common code related to writing ethtool strings | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Guessed tree name to be net-next
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cc_maintainers warning 11 maintainers not CCed: ecree@solarflare.com andrew@lunn.ch amitc@mellanox.com gustavo@embeddedor.com magnus.karlsson@intel.com acardace@redhat.com f.fainelli@gmail.com danieller@nvidia.com mkubecek@suse.cz davem@davemloft.net irusskikh@marvell.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 3080 this patch: 3080
netdev/kdoc success Errors and warnings before: 14 this patch: 14
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 31 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 3198 this patch: 3198
netdev/header_inline success Link

Commit Message

Alexander Duyck March 11, 2021, 1:35 a.m. UTC
From: Alexander Duyck <alexanderduyck@fb.com>

Add a function to handle the common pattern of printing a string into the
ethtool strings interface and incrementing the string pointer by the
ETH_GSTRING_LEN. Most of the drivers end up doing this and several have
implemented their own versions of this function so it would make sense to
consolidate on one implementation.

Signed-off-by: Alexander Duyck <alexanderduyck@fb.com>
---
 include/linux/ethtool.h |    9 +++++++++
 net/ethtool/ioctl.c     |   12 ++++++++++++
 2 files changed, 21 insertions(+)

Comments

Jakub Kicinski March 11, 2021, 2:08 a.m. UTC | #1
On Wed, 10 Mar 2021 17:35:17 -0800 Alexander Duyck wrote:
> From: Alexander Duyck <alexanderduyck@fb.com>
> 
> Add a function to handle the common pattern of printing a string into the
> ethtool strings interface and incrementing the string pointer by the
> ETH_GSTRING_LEN. Most of the drivers end up doing this and several have
> implemented their own versions of this function so it would make sense to
> consolidate on one implementation.
> 
> Signed-off-by: Alexander Duyck <alexanderduyck@fb.com>
> ---
>  include/linux/ethtool.h |    9 +++++++++
>  net/ethtool/ioctl.c     |   12 ++++++++++++
>  2 files changed, 21 insertions(+)
> 
> diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
> index ec4cd3921c67..0493f13b2b20 100644
> --- a/include/linux/ethtool.h
> +++ b/include/linux/ethtool.h
> @@ -571,4 +571,13 @@ struct ethtool_phy_ops {
>   */
>  void ethtool_set_ethtool_phy_ops(const struct ethtool_phy_ops *ops);
>  
> +/**
> + * ethtool_gsprintf - Write formatted string to ethtool string data
> + * @data: Pointer to start of string to update
> + * @fmt: Format of string to write
> + *
> + * Write formatted string to data. Update data to point at start of
> + * next string.
> + */
> +extern __printf(2, 3) void ethtool_gsprintf(u8 **data, const char *fmt, ...);

I'd drop the 'g' TBH, it seems to have made its way from the ethtool
command ('gstrings') to various places but without the 'string' after
it - it becomes less and less meaningful. Just ethtool_sprintf() would
be fine IMHO.

Other than that there is a minor rev xmas tree violation in patch 2 :)
Jesse Brandeburg March 11, 2021, 8:37 p.m. UTC | #2
Jakub Kicinski wrote:

> On Wed, 10 Mar 2021 17:35:17 -0800 Alexander Duyck wrote:
> > From: Alexander Duyck <alexanderduyck@fb.com>
> > +/**
> > + * ethtool_gsprintf - Write formatted string to ethtool string data
> > + * @data: Pointer to start of string to update
> > + * @fmt: Format of string to write
> > + *
> > + * Write formatted string to data. Update data to point at start of
> > + * next string.
> > + */
> > +extern __printf(2, 3) void ethtool_gsprintf(u8 **data, const char *fmt, ...);
> 
> I'd drop the 'g' TBH, it seems to have made its way from the ethtool
> command ('gstrings') to various places but without the 'string' after
> it - it becomes less and less meaningful. Just ethtool_sprintf() would
> be fine IMHO.
> 
> Other than that there is a minor rev xmas tree violation in patch 2 :)


I agree with Jakub, and I really like this series, it's a good clean up.

I'll be glad to add a reviewed by tag to v2.
diff mbox series

Patch

diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
index ec4cd3921c67..0493f13b2b20 100644
--- a/include/linux/ethtool.h
+++ b/include/linux/ethtool.h
@@ -571,4 +571,13 @@  struct ethtool_phy_ops {
  */
 void ethtool_set_ethtool_phy_ops(const struct ethtool_phy_ops *ops);
 
+/**
+ * ethtool_gsprintf - Write formatted string to ethtool string data
+ * @data: Pointer to start of string to update
+ * @fmt: Format of string to write
+ *
+ * Write formatted string to data. Update data to point at start of
+ * next string.
+ */
+extern __printf(2, 3) void ethtool_gsprintf(u8 **data, const char *fmt, ...);
 #endif /* _LINUX_ETHTOOL_H */
diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
index 24783b71c584..44ac73780b6e 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -1844,6 +1844,18 @@  static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
 	return ret;
 }
 
+__printf(2, 3) void ethtool_gsprintf(u8 **data, const char *fmt, ...)
+{
+	va_list args;
+
+	va_start(args, fmt);
+	vsnprintf(*data, ETH_GSTRING_LEN, fmt, args);
+	va_end(args);
+
+	*data += ETH_GSTRING_LEN;
+}
+EXPORT_SYMBOL(ethtool_gsprintf);
+
 static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
 {
 	struct ethtool_value id;