diff mbox series

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

Message ID 20231027-ethtool_puts_impl-v3-1-3466ac679304@google.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series ethtool: Add ethtool_puts() | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 3239 this patch: 3239
netdev/cc_maintainers warning 2 maintainers not CCed: d-tatianin@yandex-team.ru jdamato@fastly.com
netdev/build_clang success Errors and warnings before: 1565 this patch: 1565
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 3455 this patch: 3455
netdev/checkpatch warning CHECK: extern prototypes should be avoided in .h files
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Justin Stitt Oct. 27, 2023, 10:05 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

Andrew Lunn Oct. 27, 2023, 11:43 p.m. UTC | #1
> +/**
> + * ethtool_puts - Write string to ethtool string data
> + * @data: Pointer to start of string to update

Isn't it actually a pointer to a pointer to the start of string to
update?

> +extern void ethtool_puts(u8 **data, const char *str);

	Andrew
Justin Stitt Oct. 28, 2023, 1:20 a.m. UTC | #2
On Fri, Oct 27, 2023 at 4:43 PM Andrew Lunn <andrew@lunn.ch> wrote:
>
> > +/**
> > + * ethtool_puts - Write string to ethtool string data
> > + * @data: Pointer to start of string to update
>
> Isn't it actually a pointer to a pointer to the start of string to
> update?

I suppose.

FWIW, I just copy-pasted the sprintf doc and tweaked:
/**
 * ethtool_sprintf - 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 void ethtool_puts(u8 **data, const char *str);
>
>         Andrew
Andrew Lunn Oct. 28, 2023, 3:06 p.m. UTC | #3
On Fri, Oct 27, 2023 at 06:20:08PM -0700, Justin Stitt wrote:
> On Fri, Oct 27, 2023 at 4:43 PM Andrew Lunn <andrew@lunn.ch> wrote:
> >
> > > +/**
> > > + * ethtool_puts - Write string to ethtool string data
> > > + * @data: Pointer to start of string to update
> >
> > Isn't it actually a pointer to a pointer to the start of string to
> > update?
> 
> I suppose.

Its kind of relevant because you increment by the length, which you
can only do because it is **. I also find it a pretty strange API, so
documenting it correctly is important for me.

> 
> FWIW, I just copy-pasted the sprintf doc and tweaked:
> /**
>  * ethtool_sprintf - Write formatted string to ethtool string data
>  * @data: Pointer to start of string to update

So that need fixing as well. I will cook up a patch for this one.

   Andrew
diff mbox series

Patch

diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
index 226a36ed5aa1..e340ed822cc2 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 start of string to update
+ * @str: String to write
+ *
+ * Write string to data. 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;