Staging: rtl8192e: Refactored rtllib_modes
authorFelix Schlepper <f3sch.git@outlook.com>
Fri, 1 Jul 2022 09:24:49 +0000 (11:24 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Jul 2022 12:25:45 +0000 (14:25 +0200)
The initial reason for looking at this code was an
issue raised by checkpatch.pl:

     $ ./scripts/checkpatch.pl --terse -f drivers/staging/rtl8192e/rtllib_wx.c
     CHECK: Please use a blank line after function/struct/union/enum
     declarations

The additional blank line above the struct/before the headers is
just cleaner.

However, as it turns out since there is no str formatting required
One can replace the error prone str + size struct with a char array.
The rest of this patch fixes the usecases.

Tested-by: Philipp Hortmann <philipp.g.hortmann@gmail.com>
Signed-off-by: Felix Schlepper <f3sch.git@outlook.com>
Link: https://lore.kernel.org/r/4dbc4939e88a2c94f1819b4b0cc2c81dc332710b.1656667089.git.f3sch.git@outlook.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/rtl8192e/rtllib_wx.c

index cf9a240..b7f19b3 100644 (file)
 #include <linux/module.h>
 #include <linux/etherdevice.h>
 #include "rtllib.h"
-struct modes_unit {
-       char *mode_string;
-       int mode_size;
-};
-static struct modes_unit rtllib_modes[] = {
-       {"a", 1},
-       {"b", 1},
-       {"g", 1},
-       {"?", 1},
-       {"N-24G", 5},
-       {"N-5G", 4},
+
+static const char * const rtllib_modes[] = {
+       "a", "b", "g", "?", "N-24G", "N-5G"
 };
 
 #define MAX_CUSTOM_LEN 64
@@ -72,10 +64,9 @@ static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
        /* Add the protocol name */
        iwe.cmd = SIOCGIWNAME;
        for (i = 0; i < ARRAY_SIZE(rtllib_modes); i++) {
-               if (network->mode&(1<<i)) {
-                       sprintf(pname, rtllib_modes[i].mode_string,
-                               rtllib_modes[i].mode_size);
-                       pname += rtllib_modes[i].mode_size;
+               if (network->mode & BIT(i)) {
+                       strcpy(pname, rtllib_modes[i]);
+                       pname += strlen(rtllib_modes[i]);
                }
        }
        *pname = '\0';