proc-empty-vm.c:342:17: warning: ignoring return value of 'write' declared with attribute 'warn_unused_result'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <yujie.liu@xxxxxxxxx>
| Closes: https://lore.kernel.org/r/202404010211.ygidvMwa-lkp@xxxxxxxxx/

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





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux