Skip to content

Commit

Permalink
ethtool: Add common function for filling out strings
Browse files Browse the repository at this point in the history
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
ahduyck authored and davem330 committed Mar 17, 2021
1 parent 0c88eda commit 7888fe5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/linux/ethtool.h
Original file line number Diff line number Diff line change
Expand Up @@ -571,4 +571,13 @@ struct ethtool_phy_ops {
*/
void ethtool_set_ethtool_phy_ops(const struct ethtool_phy_ops *ops);

/**
* 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 __printf(2, 3) void ethtool_sprintf(u8 **data, const char *fmt, ...);
#endif /* _LINUX_ETHTOOL_H */
12 changes: 12 additions & 0 deletions net/ethtool/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,18 @@ static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
return ret;
}

__printf(2, 3) void ethtool_sprintf(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_sprintf);

static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
{
struct ethtool_value id;
Expand Down

0 comments on commit 7888fe5

Please sign in to comment.