Skip to contentSkip to conversation

selftests/nolibc: Remove unneeded variable

PATCH New [email protected] 2 participants 2 messages Jun 14, 2023 – Jun 16, 2023 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 selftests/nolibc: Remove unneeded variable

Fix the following coccicheck warning:

tools/testing/selftests/nolibc/nolibc-test.c:646:5-8: Unneeded variable: "ret". Return "0"

---
 tools/testing/selftests/nolibc/nolibc-test.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
tools/testing/selftests/nolibc/nolibc-test.c +0 -1
index 486334981e60..2b723354e085 100644
@@ -546,7 +546,6 @@ int run_syscall(int min, int max)
     int proc;
     int test;
     int tmp;
-    int ret = 0;
     void *p1, *p2;
 
     /* <proc> indicates whether or not /proc is mounted */
@@ -632,18 +631,17 @@ int run_syscall(int min, int max)
         CASE_TEST(syscall_noargs);    EXPECT_SYSEQ(1, 

syscall(__NR_getpid), getpid()); break;
CASE_TEST(syscall_args); EXPECT_SYSER(1,

syscall(__NR_statx, 0, NULL, 0, 0, NULL), -1, EFAULT); break;
         case __LINE__:
-            return ret; /* must be last */
+            return 0; /* must be last */
         /* note: do not set any defaults so as to permit holes above */
         }
     }

- return ret;
+ return 0;
}

int run_stdlib(int min, int max)

 {
     int test;
     int tmp;
-    int ret = 0;
     void *p1, *p2;

     for (test = min; test >= 0 && test <= max; test++) {
@@ -726,11 +724,11 @@ int run_stdlib(int min, int max)
 # warning "__SIZEOF_LONG__ is undefined"
 #endif /* __SIZEOF_LONG__ */
         case __LINE__:
-            return ret; /* must be last */
+            return 0; /* must be last */
         /* note: do not set any defaults so as to permit holes above */
         }
     }
-    return ret;
+    return 0;
 }

#define EXPECT_VFPRINTF(c, expected, fmt, ...) \
@@ -790,7 +788,6 @@ static int run_vfprintf(int min, int max)

 {
     int test;
     int tmp;
-    int ret = 0;
     void *p1, *p2;

     for (test = min; test >= 0 && test <= max; test++) {
@@ -810,11 +807,11 @@ static int run_vfprintf(int min, int max)
         CASE_TEST(hex);          EXPECT_VFPRINTF(1, "f", "%x", 0xf); 
break;
         CASE_TEST(pointer);      EXPECT_VFPRINTF(3, "0x1", "%p", (void 
*) 0x1); break;
         case __LINE__:
-            return ret; /* must be last */
+            return 0; /* must be last */
         /* note: do not set any defaults so as to permit holes above */
         }
     }

- return ret;
+ return 0;
}

static int smash_stack(void)

#2 lore raw

PATCH 1/1 selftests/nolibc: Remove unneeded variable

Hi, Yonggang

The 'ret' variable is extractly used by the macros to record the failures, removing it would directly break the compiling.

    $ gcc -o nolibc-test tools/testing/selftests/nolibc/nolibc-test.c
    tools/testing/selftests/nolibc/nolibc-test.c: In function ‘run_syscall’:
    tools/testing/selftests/nolibc/nolibc-test.c:285:57: error: ‘ret’ undeclared (first use in this function)
      285 |  do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_sysne(expr, llen, val); } while (0)

You can re-check all of the used 'ret' like this:

    $ grep "ret += expect" -ur tools/testing/selftests/nolibc/nolibc-test.c

To avoid sending such patches, simple local tests are required, for this patch, the 'libc-test' or 'nolibc-test' target may help us to find the above compile error:

    $ cd tools/testing/selftests/nolibc/
    $ make libc-test
    or
    $ make nolibc-test

Thanks,
Zhangjin

Quoted 85 lines

Fix the following coccicheck warning:

tools/testing/selftests/nolibc/nolibc-test.c:646:5-8: Unneeded variable:
"ret". Return "0"

---
  tools/testing/selftests/nolibc/nolibc-test.c | 15 ++++++---------
  1 file changed, 6 insertions(+), 9 deletions(-)
tools/testing/selftests/nolibc/nolibc-test.c +2 -4
index 486334981e60..2b723354e085 100644
@@ -546,7 +546,6 @@ int run_syscall(int min, int max)
      int proc;
      int test;
      int tmp;
-    int ret = 0;
      void *p1, *p2;
 
      /* <proc> indicates whether or not /proc is mounted */
@@ -632,18 +631,17 @@ int run_syscall(int min, int max)
          CASE_TEST(syscall_noargs);    EXPECT_SYSEQ(1, 
 syscall(__NR_getpid), getpid()); break;
          CASE_TEST(syscall_args);      EXPECT_SYSER(1, 
 syscall(__NR_statx, 0, NULL, 0, 0, NULL), -1, EFAULT); break;
          case __LINE__:
-            return ret; /* must be last */
+            return 0; /* must be last */
          /* note: do not set any defaults so as to permit holes above */
          }
      }
-    return ret;
+    return 0;
  }
 
  int run_stdlib(int min, int max)
  {
      int test;
      int tmp;
-    int ret = 0;
      void *p1, *p2;
      for (test = min; test >= 0 && test <= max; test++) {
tools/testing/selftests/nolibc/nolibc-test.c +4 -5
@@ -726,11 +724,11 @@ int run_stdlib(int min, int max)
  # warning "__SIZEOF_LONG__ is undefined"
  #endif /* __SIZEOF_LONG__ */
          case __LINE__:
-            return ret; /* must be last */
+            return 0; /* must be last */
          /* note: do not set any defaults so as to permit holes above */
          }
      }
-    return ret;
+    return 0;
  }
 
  #define EXPECT_VFPRINTF(c, expected, fmt, ...)                \
@@ -790,7 +788,6 @@ static int run_vfprintf(int min, int max)
  {
      int test;
      int tmp;
-    int ret = 0;
      void *p1, *p2;
 
      for (test = min; test >= 0 && test <= max; test++) {
@@ -810,11 +807,11 @@ static int run_vfprintf(int min, int max)
          CASE_TEST(hex);          EXPECT_VFPRINTF(1, "f", "%x", 0xf); 
 break;
          CASE_TEST(pointer);      EXPECT_VFPRINTF(3, "0x1", "%p", (void 
 *) 0x1); break;
          case __LINE__:
-            return ret; /* must be last */
+            return 0; /* must be last */
          /* note: do not set any defaults so as to permit holes above */
          }
      }
-    return ret;
+    return 0;
  }

static int smash_stack(void)