[tip:x86/sgx 2/2] arch/x86/kernel/cpu/sgx/main.c:496:7: warning: variable 'nid' is used uninitialized whenever 'if' condition is false

From: kernel test robot
Date: Thu Mar 18 2021 - 17:04:47 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/sgx
head: 5b8719504e3adf47646273781591ad439b3c3c7a
commit: 5b8719504e3adf47646273781591ad439b3c3c7a [2/2] x86/sgx: Add a basic NUMA allocation scheme to sgx_alloc_epc_page()
config: x86_64-randconfig-r004-20210318 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 6db3ab2903f42712f44000afb5aa467efbd25f35)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=5b8719504e3adf47646273781591ad439b3c3c7a
git remote add tip https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git
git fetch --no-tags tip x86/sgx
git checkout 5b8719504e3adf47646273781591ad439b3c3c7a
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>

All warnings (new ones prefixed by >>):

>> arch/x86/kernel/cpu/sgx/main.c:496:7: warning: variable 'nid' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
if (page)
^~~~
arch/x86/kernel/cpu/sgx/main.c:502:22: note: uninitialized use occurs here
nid = next_node_in(nid, sgx_numa_mask);
^~~
include/linux/nodemask.h:278:46: note: expanded from macro 'next_node_in'
#define next_node_in(n, src) __next_node_in((n), &(src))
^
arch/x86/kernel/cpu/sgx/main.c:496:3: note: remove the 'if' if its condition is always true
if (page)
^~~~~~~~~
arch/x86/kernel/cpu/sgx/main.c:494:6: warning: variable 'nid' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
if (node_isset(nid_of_current, sgx_numa_mask)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/nodemask.h:152:36: note: expanded from macro 'node_isset'
#define node_isset(node, nodemask) test_bit((node), (nodemask).bits)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/kernel/cpu/sgx/main.c:502:22: note: uninitialized use occurs here
nid = next_node_in(nid, sgx_numa_mask);
^~~
include/linux/nodemask.h:278:46: note: expanded from macro 'next_node_in'
#define next_node_in(n, src) __next_node_in((n), &(src))
^
arch/x86/kernel/cpu/sgx/main.c:494:2: note: remove the 'if' if its condition is always true
if (node_isset(nid_of_current, sgx_numa_mask)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/kernel/cpu/sgx/main.c:492:9: note: initialize the variable 'nid' to silence this warning
int nid;
^
= 0
2 warnings generated.


vim +496 arch/x86/kernel/cpu/sgx/main.c

d2285493bef310 Jarkko Sakkinen 2020-11-13 477
d2285493bef310 Jarkko Sakkinen 2020-11-13 478 /**
d2285493bef310 Jarkko Sakkinen 2020-11-13 479 * __sgx_alloc_epc_page() - Allocate an EPC page
d2285493bef310 Jarkko Sakkinen 2020-11-13 480 *
5b8719504e3adf Jarkko Sakkinen 2021-03-18 481 * Iterate through NUMA nodes and reserve ia free EPC page to the caller. Start
5b8719504e3adf Jarkko Sakkinen 2021-03-18 482 * from the NUMA node, where the caller is executing.
d2285493bef310 Jarkko Sakkinen 2020-11-13 483 *
d2285493bef310 Jarkko Sakkinen 2020-11-13 484 * Return:
5b8719504e3adf Jarkko Sakkinen 2021-03-18 485 * - an EPC page: A borrowed EPC pages were available.
5b8719504e3adf Jarkko Sakkinen 2021-03-18 486 * - NULL: Out of EPC pages.
d2285493bef310 Jarkko Sakkinen 2020-11-13 487 */
d2285493bef310 Jarkko Sakkinen 2020-11-13 488 struct sgx_epc_page *__sgx_alloc_epc_page(void)
d2285493bef310 Jarkko Sakkinen 2020-11-13 489 {
d2285493bef310 Jarkko Sakkinen 2020-11-13 490 struct sgx_epc_page *page;
5b8719504e3adf Jarkko Sakkinen 2021-03-18 491 int nid_of_current = numa_node_id();
5b8719504e3adf Jarkko Sakkinen 2021-03-18 492 int nid;
d2285493bef310 Jarkko Sakkinen 2020-11-13 493
5b8719504e3adf Jarkko Sakkinen 2021-03-18 494 if (node_isset(nid_of_current, sgx_numa_mask)) {
5b8719504e3adf Jarkko Sakkinen 2021-03-18 495 page = __sgx_alloc_epc_page_from_node(nid_of_current);
d2285493bef310 Jarkko Sakkinen 2020-11-13 @496 if (page)
d2285493bef310 Jarkko Sakkinen 2020-11-13 497 return page;
d2285493bef310 Jarkko Sakkinen 2020-11-13 498 }
d2285493bef310 Jarkko Sakkinen 2020-11-13 499
5b8719504e3adf Jarkko Sakkinen 2021-03-18 500 /* Fall back to the non-local NUMA nodes: */
5b8719504e3adf Jarkko Sakkinen 2021-03-18 501 while (true) {
5b8719504e3adf Jarkko Sakkinen 2021-03-18 502 nid = next_node_in(nid, sgx_numa_mask);
5b8719504e3adf Jarkko Sakkinen 2021-03-18 503 if (nid == nid_of_current)
5b8719504e3adf Jarkko Sakkinen 2021-03-18 504 break;
5b8719504e3adf Jarkko Sakkinen 2021-03-18 505
5b8719504e3adf Jarkko Sakkinen 2021-03-18 506 page = __sgx_alloc_epc_page_from_node(nid);
5b8719504e3adf Jarkko Sakkinen 2021-03-18 507 if (page)
5b8719504e3adf Jarkko Sakkinen 2021-03-18 508 break;
5b8719504e3adf Jarkko Sakkinen 2021-03-18 509 }
5b8719504e3adf Jarkko Sakkinen 2021-03-18 510
5b8719504e3adf Jarkko Sakkinen 2021-03-18 511 return page;
d2285493bef310 Jarkko Sakkinen 2020-11-13 512 }
d2285493bef310 Jarkko Sakkinen 2020-11-13 513

:::::: The code at line 496 was first introduced by commit
:::::: d2285493bef310b66b56dfe4eb75c1e2f431ea5c x86/sgx: Add SGX page allocator functions

:::::: TO: Jarkko Sakkinen <jarkko@xxxxxxxxxx>
:::::: CC: Borislav Petkov <bp@xxxxxxx>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx

Attachment: .config.gz
Description: application/gzip