]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
riscv: selftests: Fix warnings pointer masking test
authorCharlie Jenkins <charlie@rivosinc.com>
Thu, 12 Dec 2024 07:01:43 +0000 (23:01 -0800)
committerPalmer Dabbelt <palmer@rivosinc.com>
Tue, 17 Dec 2024 22:23:18 +0000 (14:23 -0800)
When compiling the pointer masking tests with -Wall this warning
is present:

pointer_masking.c: In function ‘test_tagged_addr_abi_sysctl’:
pointer_masking.c:203:9: warning: ignoring return value of ‘pwrite’
declared with attribute ‘warn_unused_result’ [-Wunused-result]
  203 |         pwrite(fd, &value, 1, 0); |
      ^~~~~~~~~~~~~~~~~~~~~~~~ pointer_masking.c:208:9: warning:
ignoring return value of ‘pwrite’ declared with attribute
‘warn_unused_result’ [-Wunused-result]
  208 |         pwrite(fd, &value, 1, 0);

I came across this on riscv64-linux-gnu-gcc (Ubuntu
11.4.0-1ubuntu1~22.04).

Fix this by checking that the number of bytes written equal the expected
number of bytes written.

Fixes: 7470b5afd150 ("riscv: selftests: Add a pointer masking test")
Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Link: https://lore.kernel.org/r/20241211-fix_warnings_pointer_masking_tests-v6-1-c7ae708fbd2f@rivosinc.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
tools/testing/selftests/riscv/abi/pointer_masking.c

index dee41b7ee3e323150d55523c8acbf3ec38857b87..059d2e87eb1f737caf44f692b239bf3e49c233b4 100644 (file)
@@ -185,8 +185,20 @@ static void test_fork_exec(void)
        }
 }
 
+static bool pwrite_wrapper(int fd, void *buf, size_t count, const char *msg)
+{
+       int ret = pwrite(fd, buf, count, 0);
+
+       if (ret != count) {
+               ksft_perror(msg);
+               return false;
+       }
+       return true;
+}
+
 static void test_tagged_addr_abi_sysctl(void)
 {
+       char *err_pwrite_msg = "failed to write to /proc/sys/abi/tagged_addr_disabled\n";
        char value;
        int fd;
 
@@ -200,14 +212,18 @@ static void test_tagged_addr_abi_sysctl(void)
        }
 
        value = '1';
-       pwrite(fd, &value, 1, 0);
-       ksft_test_result(set_tagged_addr_ctrl(min_pmlen, true) == -EINVAL,
-                        "sysctl disabled\n");
+       if (!pwrite_wrapper(fd, &value, 1, "write '1'"))
+               ksft_test_result_fail(err_pwrite_msg);
+       else
+               ksft_test_result(set_tagged_addr_ctrl(min_pmlen, true) == -EINVAL,
+                                "sysctl disabled\n");
 
        value = '0';
-       pwrite(fd, &value, 1, 0);
-       ksft_test_result(set_tagged_addr_ctrl(min_pmlen, true) == 0,
-                        "sysctl enabled\n");
+       if (!pwrite_wrapper(fd, &value, 1, "write '0'"))
+               ksft_test_result_fail(err_pwrite_msg);
+       else
+               ksft_test_result(set_tagged_addr_ctrl(min_pmlen, true) == 0,
+                                "sysctl enabled\n");
 
        set_tagged_addr_ctrl(0, false);