[SRU][J:linux-azure][PATCH 1/3] ethtool: Implement ethtool_puts()
John Cabaj
john.cabaj at canonical.com
Wed Aug 6 21:53:27 UTC 2025
From: "justinstitt at google.com" <justinstitt at google.com>
BugLink: https://bugs.launchpad.net/bugs/2119686
Use strscpy() to implement ethtool_puts().
Functionally the same as ethtool_sprintf() when it's used with two
arguments or with just "%s" format specifier.
Signed-off-by: Justin Stitt <justinstitt at google.com>
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel at intel.com>
Reviewed-by: Andrew Lunn <andrew at lunn.ch>
Reviewed-by: Madhuri Sripada <madhuri.sripada at microchip.com>
Signed-off-by: David S. Miller <davem at davemloft.net>
(backported from commit 2a48c635fd9a48699805bbfeee1e4b94b8fe819d)
[john-cabaj: leaving out changes introduced in upstream
26c5334d344db: "ethtool: Add forced speed to supported
link modes maps" and 20c6e05bd33de: "ethtool: untangle the
linkmode and ethtool headers"]
Signed-off-by: John Cabaj <john.cabaj at canonical.com>
---
include/linux/ethtool.h | 13 +++++++++++++
net/ethtool/ioctl.c | 7 +++++++
2 files changed, 20 insertions(+)
diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
index c998f9c139edd..ff7c5f2f4bef6 100644
--- a/include/linux/ethtool.h
+++ b/include/linux/ethtool.h
@@ -788,4 +788,17 @@ int ethtool_get_phc_vclocks(struct net_device *dev, int **vclock_index);
* next string.
*/
extern __printf(2, 3) void ethtool_sprintf(u8 **data, const char *fmt, ...);
+
+/**
+ * ethtool_puts - Write string to ethtool string data
+ * @data: Pointer to a pointer to the start of string to update
+ * @str: String to write
+ *
+ * Write string to *data without a trailing newline. Update *data
+ * to point at start of next string.
+ *
+ * Prefer this function to ethtool_sprintf() when given only
+ * two arguments or if @fmt is just "%s".
+ */
+extern void ethtool_puts(u8 **data, const char *str);
#endif /* _LINUX_ETHTOOL_H */
diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
index 1e9e70a633d1c..b47181e96479e 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -1957,6 +1957,13 @@ __printf(2, 3) void ethtool_sprintf(u8 **data, const char *fmt, ...)
}
EXPORT_SYMBOL(ethtool_sprintf);
+void ethtool_puts(u8 **data, const char *str)
+{
+ strscpy(*data, str, ETH_GSTRING_LEN);
+ *data += ETH_GSTRING_LEN;
+}
+EXPORT_SYMBOL(ethtool_puts);
+
static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
{
struct ethtool_value id;
--
2.43.0
More information about the kernel-team
mailing list