Thread (7 messages) 7 messages, 4 authors, 2024-10-28

Re: [PATCH net-next] net: freescale: use ethtool string helpers

From: Michael Ellerman <mpe@ellerman.id.au>
Date: 2024-10-28 02:32:00
Also in: lkml, netdev

Rosen Penev [off-list ref] writes:
On Fri, Oct 25, 2024 at 5:57 AM Simon Horman [off-list ref] wrote:
quoted
On Thu, Oct 24, 2024 at 01:52:57PM -0700, Rosen Penev wrote:
quoted
The latter is the preferred way to copy ethtool strings.

Avoids manually incrementing the pointer. Cleans up the code quite well.

Signed-off-by: Rosen Penev <redacted>
...
quoted
diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c b/drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c
index b0060cf96090..10c5fa4d23d2 100644
--- a/drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c
+++ b/drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c
@@ -243,38 +243,24 @@ static void dpaa_get_ethtool_stats(struct net_device *net_dev,
 static void dpaa_get_strings(struct net_device *net_dev, u32 stringset,
                           u8 *data)
 {
-     unsigned int i, j, num_cpus, size;
-     char string_cpu[ETH_GSTRING_LEN];
-     u8 *strings;
+     unsigned int i, j, num_cpus;

-     memset(string_cpu, 0, sizeof(string_cpu));
-     strings   = data;
-     num_cpus  = num_online_cpus();
-     size      = DPAA_STATS_GLOBAL_LEN * ETH_GSTRING_LEN;
+     num_cpus = num_online_cpus();

      for (i = 0; i < DPAA_STATS_PERCPU_LEN; i++) {
-             for (j = 0; j < num_cpus; j++) {
-                     snprintf(string_cpu, ETH_GSTRING_LEN, "%s [CPU %d]",
-                              dpaa_stats_percpu[i], j);
-                     memcpy(strings, string_cpu, ETH_GSTRING_LEN);
-                     strings += ETH_GSTRING_LEN;
-             }
-             snprintf(string_cpu, ETH_GSTRING_LEN, "%s [TOTAL]",
-                      dpaa_stats_percpu[i]);
-             memcpy(strings, string_cpu, ETH_GSTRING_LEN);
-             strings += ETH_GSTRING_LEN;
-     }
-     for (j = 0; j < num_cpus; j++) {
-             snprintf(string_cpu, ETH_GSTRING_LEN,
-                      "bpool [CPU %d]", j);
-             memcpy(strings, string_cpu, ETH_GSTRING_LEN);
-             strings += ETH_GSTRING_LEN;
+             for (j = 0; j < num_cpus; j++)
+                     ethtool_sprintf(&data, "%s [CPU %d]",
+                                     dpaa_stats_percpu[i], j);
+
+             ethtool_sprintf(&data, "%s [TOTAL]", dpaa_stats_percpu[i]);
      }
-     snprintf(string_cpu, ETH_GSTRING_LEN, "bpool [TOTAL]");
-     memcpy(strings, string_cpu, ETH_GSTRING_LEN);
-     strings += ETH_GSTRING_LEN;
+     for (i = 0; j < num_cpus; i++)
Perhaps this should consistently use i, rather than i and j:

        for (i = 0; i < num_cpus; i++)

Flagged by W=1 builds with clang-18.
I really need to compile test this on a PPC system.
Cross compiling should be sufficient.

There's some pointers here:
  https://github.com/linuxppc/wiki/wiki/Building-powerpc-kernels

Or there's also libc-less cross compilers on kernel.org, eg:
  https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/14.2.0/x86_64-gcc-14.2.0-nolibc-powerpc64-linux.tar.xz


cheers
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help