[net-next,v5,1/3] ethtool: Implement ethtool_puts()

Message ID 20231206-ethtool_puts_impl-v5-1-5a2528e17bf8@google.com
State New
Headers
Series ethtool: Add ethtool_puts() |

Commit Message

Justin Stitt Dec. 6, 2023, 11:16 p.m. UTC
  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@google.com>
---
 include/linux/ethtool.h | 13 +++++++++++++
 net/ethtool/ioctl.c     |  7 +++++++
 2 files changed, 20 insertions(+)
  

Comments

Przemek Kitszel Dec. 7, 2023, 7:12 a.m. UTC | #1
On 12/7/23 00:16, justinstitt@google.com wrote:
> 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@google.com>
> ---
>   include/linux/ethtool.h | 13 +++++++++++++
>   net/ethtool/ioctl.c     |  7 +++++++
>   2 files changed, 20 insertions(+)
> 


Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
  
Andrew Lunn Dec. 7, 2023, 3:27 p.m. UTC | #2
On Wed, Dec 06, 2023 at 11:16:10PM +0000, justinstitt@google.com wrote:
> 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@google.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
  
Madhuri.Sripada@microchip.com Dec. 8, 2023, 10:45 a.m. UTC | #3
> 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@google.com>

Reviewed-by: Madhuri Sripada <madhuri.sripada@microchip.com>
  

Patch

diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
index 689028257fcc..2480a4e4a331 100644
--- a/include/linux/ethtool.h
+++ b/include/linux/ethtool.h
@@ -1053,6 +1053,19 @@  static inline int ethtool_mm_frag_size_min_to_add(u32 val_min, u32 *val_add,
  */
 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);
+
 /* Link mode to forced speed capabilities maps */
 struct ethtool_forced_speed_map {
 	u32		speed;
diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
index 0b0ce4f81c01..abdf05edf804 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -1991,6 +1991,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;