Skip to content

Conversation

Copy link

Copilot AI commented Nov 23, 2025

Build fails on drivers/xen/gnttab.c when compiling with -Werror due to uninitialized variable warnings for ret and gfn in gnttab_get_pages().

Changes

  • Initialize ret = 0 and gfn = 0 at declaration in gnttab_get_pages()

The compiler cannot statically prove these variables are assigned before use in the error logging path, though runtime logic guarantees they are (loop always executes at least once when npages > 0).

void *gnttab_get_pages(unsigned int npages)
{
-	int ret;
+	int ret = 0;
	void *page_addr;
	unsigned int removed;
-	xen_pfn_t gfn;
+	xen_pfn_t gfn = 0;
Original prompt

Building C object zephyr/CMakeFiles/zephyr.dir/drivers/xen/events.c.obj
[37/133] Building C object zephyr/CMakeFiles/zephyr.dir/drivers/xen/gnttab.c.obj
FAILED: zephyr/CMakeFiles/zephyr.dir/drivers/xen/gnttab.c.obj
ccache /opt/toolchains/zephyr-sdk-0.17.4/aarch64-zephyr-elf/bin/aarch64-zephyr-elf-gcc -DKERNEL -DK_HEAP_MEM_POOL_SIZE=16384 -DPICOLIBC_DOUBLE_PRINTF_SCANF -DZVFS_OPEN_SIZE=0 -D_POSIX_THREAD_SAFE_FUNCTIONS=200809L -D__LINUX_ERRNO_EXTENSIONS__ -D__ZEPHYR__=1 -I/__w/zephyr/zephyr/kernel/include -I/__w/zephyr/zephyr/arch/arm64/include -I/__w/zephyr/zephyr/twister-out/xenvm_xenvm_gicv3/zephyr/tests/arch/common/stack_unwind/arch.common.stack_unwind.arm64/zephyr/include/generated/zephyr -I/__w/zephyr/zephyr/include -I/__w/zephyr/zephyr/twister-out/xenvm_xenvm_gicv3/zephyr/tests/arch/common/stack_unwind/arch.common.stack_unwind.arm64/zephyr/include/generated -I/__w/zephyr/zephyr/soc/xen -I/__w/zephyr/zephyr/lib/libc/picolibc/include -I/__w/zephyr/zephyr/lib/posix/c_lib_ext/getopt -I/__w/zephyr/zephyr/lib/midi2/. -I/__w/zephyr/zephyr/subsys/testsuite/include -I/__w/zephyr/modules/hal/microchip/include -I/__w/zephyr/modules/hal/st/sensor/inc -I/__w/zephyr/modules/hal/ti/mspm0/source/ti/devices/msp/. -I/__w/zephyr/modules/hal/ti/mspm0/source/ti/devices/msp/m0p -I/__w/zephyr/modules/hal/ti/mspm0/source/ti/devices/msp/peripherals -I/__w/zephyr/modules/hal/ti/mspm0/source/ti/devices/msp/peripherals/m0p -I/__w/zephyr/modules/hal/ti/mspm0/source/ti/devices/msp/peripherals/m0p/sysctl -isystem /__w/zephyr/zephyr/lib/libc/common/include -fno-strict-aliasing -Werror -Og -imacros /__w/zephyr/zephyr/twister-out/xenvm_xenvm_gicv3/zephyr/tests/arch/common/stack_unwind/arch.common.stack_unwind.arm64/zephyr/include/generated/zephyr/autoconf.h -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-a72 -mabi=lp64 --sysroot=/opt/toolchains/zephyr-sdk-0.17.4/aarch64-zephyr-elf/aarch64-zephyr-elf -imacros /__w/zephyr/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wdouble-promotion -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -ftls-model=local-exec -fno-omit-frame-pointer -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=/__w/zephyr/zephyr/tests/arch/common/stack_unwind=CMAKE_SOURCE_DIR -fmacro-prefix-map=/__w/zephyr/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/__w/zephyr=WEST_TOPDIR -ffunction-sections -fdata-sections -mno-omit-leaf-frame-pointer -moverride=tune=no_ldp_stp_qregs -specs=picolibc.specs -std=c17 -MD -MT zephyr/CMakeFiles/zephyr.dir/drivers/xen/gnttab.c.obj -MF zephyr/CMakeFiles/zephyr.dir/drivers/xen/gnttab.c.obj.d -o zephyr/CMakeFiles/zephyr.dir/drivers/xen/gnttab.c.obj -c /__w/zephyr/zephyr/drivers/xen/gnttab.c
In file included from /__w/zephyr/zephyr/include/zephyr/logging/log.h:11,
from /__w/zephyr/zephyr/drivers/xen/gnttab.c:31:
/__w/zephyr/zephyr/include/zephyr/logging/log_core.h: In function 'gnttab_get_pages':
/__w/zephyr/zephyr/include/zephyr/logging/log_core.h:221:9: error: 'gfn' may be used uninitialized [-Werror=maybe-uninitialized]
221 | z_log_minimal_printk("%c: " fmt "\n",
| ^~~~~~~~~~~~~~~~~~~~
/__w/zephyr/zephyr/drivers/xen/gnttab.c:202:19: note: 'gfn' was declared here
202 | xen_pfn_t gfn;
| ^~~
/__w/zephyr/zephyr/include/zephyr/logging/log_core.h:221:9: error: 'ret' may be used uninitialized [-Werror=maybe-uninitialized]
221 | z_log_minimal_printk("%c: " fmt "\n",
| ^~~~~~~~~~~~~~~~~~~~
/__w/zephyr/zephyr/drivers/xen/gnttab.c:199:13: note: 'ret' was declared here
199 | int ret;
| ^~~
cc1: all warnings being treated as errors
ninja: build stopped: subcommand failed.

INFO - /__w/zephyr/zephyr/twister-out/xenvm_xenvm_gicv3/zephyr/tests/arch/common/stack_unwind/

fix this bug


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix build error in gnttab.c for zephyr Initialize variables to fix -Werror=maybe-uninitialized in gnttab.c Nov 23, 2025
Copilot AI requested a review from kartben November 23, 2025 17:17
Copilot finished work on behalf of kartben November 23, 2025 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants