tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 712e14250dd2907346617eba275c46f53db8fae7
commit: 6e79b375adb38219099d7e3ccc973a7808108a3e proc: test /proc/${pid}/statm
compiler: gcc-12 (Ubuntu 12.3.0-9ubuntu2) 12.3.0
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/
All warnings (new ones prefixed by >>):
proc-empty-vm.c: In function 'test_proc_pid_statm':
>> proc-empty-vm.c:342:17: warning: ignoring return value of 'write' declared with attribute 'warn_unused_result' [-Wunused-result]
342 | write(1, buf, rv);
| ^~~~~~~~~~~~~~~~~
vim +342 tools/testing/selftests/proc/proc-empty-vm.c
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 320
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 321 /*
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 322 * There seems to be 2 types of valid output:
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 323 * "0 A A B 0 0 0\n" for dynamic exeuctables,
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 324 * "0 0 0 B 0 0 0\n" for static executables.
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 325 */
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 326 static int test_proc_pid_statm(pid_t pid)
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 327 {
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 328 char buf[4096];
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 329 snprintf(buf, sizeof(buf), "/proc/%u/statm", pid);
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 330 int fd = open(buf, O_RDONLY);
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 331 if (fd == -1) {
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 332 perror("open /proc/${pid}/statm");
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 333 return EXIT_FAILURE;
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 334 }
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 335
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 336 ssize_t rv = read(fd, buf, sizeof(buf));
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 337 close(fd);
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 338
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 339 assert(rv >= 0);
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 340 assert(rv <= sizeof(buf));
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 341 if (0) {
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 @342 write(1, buf, rv);
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 343 }
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 344
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 345 const char *p = buf;
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 346 const char *const end = p + rv;
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 347
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 348 /* size */
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 349 assert(p != end && *p++ == '0');
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 350 assert(p != end && *p++ == ' ');
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 351
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 352 uint64_t resident;
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 353 p = parse_u64(p, end, &resident);
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 354 assert(p != end && *p++ == ' ');
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 355
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 356 uint64_t shared;
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 357 p = parse_u64(p, end, &shared);
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 358 assert(p != end && *p++ == ' ');
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 359
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 360 uint64_t text;
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 361 p = parse_u64(p, end, &text);
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 362 assert(p != end && *p++ == ' ');
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 363
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 364 assert(p != end && *p++ == '0');
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 365 assert(p != end && *p++ == ' ');
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 366
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 367 /* data */
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 368 assert(p != end && *p++ == '0');
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 369 assert(p != end && *p++ == ' ');
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 370
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 371 assert(p != end && *p++ == '0');
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 372 assert(p != end && *p++ == '\n');
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 373
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 374 assert(p == end);
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 375
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 376 /*
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 377 * "text" is "mm->end_code - mm->start_code" at execve(2) time.
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 378 * munmap() doesn't change it. It can be anything (just link
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 379 * statically). It can't be 0 because executing to this point
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 380 * implies at least 1 page of code.
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 381 */
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 382 assert(text > 0);
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 383
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 384 /*
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 385 * These two are always equal. Always 0 for statically linked
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 386 * executables and sometimes 0 for dynamically linked executables.
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 387 * There is no way to tell one from another without parsing ELF
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 388 * which is too much for this test.
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 389 */
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 390 assert(resident == shared);
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 391
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 392 return EXIT_SUCCESS;
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 393 }
6e79b375adb382 Swarup Laxman Kotiaklapudi 2023-10-09 394
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
fix the following warning:
proc-empty-vm.c:385:17: warning: ignoring return value of ‘write’
declared with attribute ‘warn_unused_result’ [-Wunused-result]
385 | write(1, buf, rv);
| ^~~~~~~~~~~~~~~~~
Reported-by: kernel test robot <[email protected]>
Closes: https://lore.kernel.org/r/[email protected]/
Signed-off-by: Amer Al Shanawany <[email protected]>
---
tools/testing/selftests/proc/proc-empty-vm.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/tools/testing/selftests/proc/proc-empty-vm.c b/tools/testing/selftests/proc/proc-empty-vm.c
index 56198d4ca2bf..b3f898aab4ab 100644
--- a/tools/testing/selftests/proc/proc-empty-vm.c
+++ b/tools/testing/selftests/proc/proc-empty-vm.c
@@ -381,9 +381,6 @@ static int test_proc_pid_statm(pid_t pid)
assert(rv >= 0);
assert(rv <= sizeof(buf));
- if (0) {
- write(1, buf, rv);
- }
const char *p = buf;
const char *const end = p + rv;
--
2.43.0
On Mon, Jun 03, 2024 at 02:42:20PM +0200, Amer Al Shanawany wrote:
> fix the following warning:
> proc-empty-vm.c:385:17: warning: ignoring return value of ‘write’
> --- a/tools/testing/selftests/proc/proc-empty-vm.c
> +++ b/tools/testing/selftests/proc/proc-empty-vm.c
> @@ -381,9 +381,6 @@ static int test_proc_pid_statm(pid_t pid)
> - if (0) {
> - write(1, buf, rv);
> - }
no thanks
On Mon, 3 Jun 2024 17:24:47 +0300 Alexey Dobriyan <[email protected]> wrote:
> On Mon, Jun 03, 2024 at 02:42:20PM +0200, Amer Al Shanawany wrote:
> > fix the following warning:
> > proc-empty-vm.c:385:17: warning: ignoring return value of ‘write’
>
> > --- a/tools/testing/selftests/proc/proc-empty-vm.c
> > +++ b/tools/testing/selftests/proc/proc-empty-vm.c
> > @@ -381,9 +381,6 @@ static int test_proc_pid_statm(pid_t pid)
>
> > - if (0) {
> > - write(1, buf, rv);
> > - }
>
> no thanks
Why not?
Why does that code exist anyway? It at least needs a comment.
On Tue, Jun 04, 2024 at 08:25:31PM -0700, Andrew Morton wrote:
> On Mon, 3 Jun 2024 17:24:47 +0300 Alexey Dobriyan <[email protected]> wrote:
>
> > On Mon, Jun 03, 2024 at 02:42:20PM +0200, Amer Al Shanawany wrote:
> > > fix the following warning:
> > > proc-empty-vm.c:385:17: warning: ignoring return value of ‘write’
> >
> > > --- a/tools/testing/selftests/proc/proc-empty-vm.c
> > > +++ b/tools/testing/selftests/proc/proc-empty-vm.c
> > > @@ -381,9 +381,6 @@ static int test_proc_pid_statm(pid_t pid)
> >
> > > - if (0) {
> > > - write(1, buf, rv);
> > > - }
> >
> > no thanks
>
> Why not?
>
> Why does that code exist anyway? It at least needs a comment.
OK, whatever.
If test fails, it better record buggy output somewhere (to coredump or to terminal).
On 6/7/24 09:25, Alexey Dobriyan wrote:
> On Tue, Jun 04, 2024 at 08:25:31PM -0700, Andrew Morton wrote:
>> On Mon, 3 Jun 2024 17:24:47 +0300 Alexey Dobriyan <[email protected]> wrote:
>>
>>> On Mon, Jun 03, 2024 at 02:42:20PM +0200, Amer Al Shanawany wrote:
>>>> fix the following warning:
>>>> proc-empty-vm.c:385:17: warning: ignoring return value of ‘write’
>>>
>>>> --- a/tools/testing/selftests/proc/proc-empty-vm.c
>>>> +++ b/tools/testing/selftests/proc/proc-empty-vm.c
>>>> @@ -381,9 +381,6 @@ static int test_proc_pid_statm(pid_t pid)
>>>
>>>> - if (0) {
>>>> - write(1, buf, rv);
>>>> - }
>>>
>>> no thanks
>>
>> Why not?
>>
>> Why does that code exist anyway? It at least needs a comment.
>
> OK, whatever.
>
> If test fails, it better record buggy output somewhere (to coredump or to terminal).
+1 on reporting results - the best way to do this is to add a meaningful message
for users to understand what went wrong.
Please suggest how you would like this warning addressed and report the error.
thanks,
-- Shuah