netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Duyck <alexander.duyck@gmail.com>
To: kuba@kernel.org
Cc: netdev@vger.kernel.org, oss-drivers@netronome.com,
	simon.horman@netronome.com, yisen.zhuang@huawei.com,
	salil.mehta@huawei.com, intel-wired-lan@lists.osuosl.org,
	jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com,
	drivers@pensando.io, snelson@pensando.io, netanel@amazon.com,
	akiyano@amazon.com, gtzalik@amazon.com, saeedb@amazon.com,
	GR-Linux-NIC-Dev@marvell.com, skalluru@marvell.com,
	rmody@marvell.com, kys@microsoft.com, haiyangz@microsoft.com,
	sthemmin@microsoft.com, wei.liu@kernel.org, mst@redhat.com,
	jasowang@redhat.com, pv-drivers@vmware.com, doshir@vmware.com,
	alexanderduyck@fb.com
Subject: [RFC PATCH 01/10] ethtool: Add common function for filling out strings
Date: Wed, 10 Mar 2021 17:35:17 -0800	[thread overview]
Message-ID: <161542651749.13546.3959589547085613076.stgit@localhost.localdomain> (raw)
In-Reply-To: <161542634192.13546.4185974647834631704.stgit@localhost.localdomain>

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, ...);
 #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;



  reply	other threads:[~2021-03-11  1:36 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-11  1:35 [RFC PATCH 00/10] ethtool: Factor out common code related to writing ethtool strings Alexander Duyck
2021-03-11  1:35 ` Alexander Duyck [this message]
2021-03-11  2:08   ` [RFC PATCH 01/10] ethtool: Add common function for filling out strings Jakub Kicinski
2021-03-11 20:37     ` Jesse Brandeburg
2021-03-11  1:35 ` [RFC PATCH 02/10] intel: Update drivers to use ethtool_gsprintf Alexander Duyck
2021-03-11 20:32   ` Jesse Brandeburg
2021-03-11  1:35 ` [RFC PATCH 03/10] nfp: Replace nfp_pr_et with ethtool_gsprintf Alexander Duyck
2021-03-11 11:51   ` Simon Horman
2021-03-11  1:35 ` [RFC PATCH 04/10] hisilicon: Update drivers to use ethtool_gsprintf Alexander Duyck
2021-03-11  1:35 ` [RFC PATCH 05/10] ena: Update driver " Alexander Duyck
2021-03-11 13:42   ` Kiyanovski, Arthur
2021-03-11  1:35 ` [RFC PATCH 06/10] netvsc: " Alexander Duyck
2021-03-11  1:35 ` [RFC PATCH 07/10] virtio_net: " Alexander Duyck
2021-03-11  1:36 ` [RFC PATCH 08/10] vmxnet3: " Alexander Duyck
2021-03-11  1:36 ` [RFC PATCH 09/10] bna: " Alexander Duyck
2021-03-11  1:36 ` [RFC PATCH 10/10] ionic: " Alexander Duyck
2021-03-11 17:19   ` Shannon Nelson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=161542651749.13546.3959589547085613076.stgit@localhost.localdomain \
    --to=alexander.duyck@gmail.com \
    --cc=GR-Linux-NIC-Dev@marvell.com \
    --cc=akiyano@amazon.com \
    --cc=alexanderduyck@fb.com \
    --cc=anthony.l.nguyen@intel.com \
    --cc=doshir@vmware.com \
    --cc=drivers@pensando.io \
    --cc=gtzalik@amazon.com \
    --cc=haiyangz@microsoft.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=jasowang@redhat.com \
    --cc=jesse.brandeburg@intel.com \
    --cc=kuba@kernel.org \
    --cc=kys@microsoft.com \
    --cc=mst@redhat.com \
    --cc=netanel@amazon.com \
    --cc=netdev@vger.kernel.org \
    --cc=oss-drivers@netronome.com \
    --cc=pv-drivers@vmware.com \
    --cc=rmody@marvell.com \
    --cc=saeedb@amazon.com \
    --cc=salil.mehta@huawei.com \
    --cc=simon.horman@netronome.com \
    --cc=skalluru@marvell.com \
    --cc=snelson@pensando.io \
    --cc=sthemmin@microsoft.com \
    --cc=wei.liu@kernel.org \
    --cc=yisen.zhuang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).