Skip to content

Commit 498d5b1

Browse files
charlie-rivospalmer-dabbelt
authored andcommitted
riscv: selftests: Fix warnings pointer masking test
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: 7470b5a ("riscv: selftests: Add a pointer masking test") Signed-off-by: Charlie Jenkins <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Link: https://lore.kernel.org/r/20241211-fix_warnings_pointer_masking_tests-v6-1-c7ae708fbd2f@rivosinc.com Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 78d4f34 commit 498d5b1

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

tools/testing/selftests/riscv/abi/pointer_masking.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,20 @@ static void test_fork_exec(void)
185185
}
186186
}
187187

188+
static bool pwrite_wrapper(int fd, void *buf, size_t count, const char *msg)
189+
{
190+
int ret = pwrite(fd, buf, count, 0);
191+
192+
if (ret != count) {
193+
ksft_perror(msg);
194+
return false;
195+
}
196+
return true;
197+
}
198+
188199
static void test_tagged_addr_abi_sysctl(void)
189200
{
201+
char *err_pwrite_msg = "failed to write to /proc/sys/abi/tagged_addr_disabled\n";
190202
char value;
191203
int fd;
192204

@@ -200,14 +212,18 @@ static void test_tagged_addr_abi_sysctl(void)
200212
}
201213

202214
value = '1';
203-
pwrite(fd, &value, 1, 0);
204-
ksft_test_result(set_tagged_addr_ctrl(min_pmlen, true) == -EINVAL,
205-
"sysctl disabled\n");
215+
if (!pwrite_wrapper(fd, &value, 1, "write '1'"))
216+
ksft_test_result_fail(err_pwrite_msg);
217+
else
218+
ksft_test_result(set_tagged_addr_ctrl(min_pmlen, true) == -EINVAL,
219+
"sysctl disabled\n");
206220

207221
value = '0';
208-
pwrite(fd, &value, 1, 0);
209-
ksft_test_result(set_tagged_addr_ctrl(min_pmlen, true) == 0,
210-
"sysctl enabled\n");
222+
if (!pwrite_wrapper(fd, &value, 1, "write '0'"))
223+
ksft_test_result_fail(err_pwrite_msg);
224+
else
225+
ksft_test_result(set_tagged_addr_ctrl(min_pmlen, true) == 0,
226+
"sysctl enabled\n");
211227

212228
set_tagged_addr_ctrl(0, false);
213229

0 commit comments

Comments
 (0)