From 610f6f8a297e6d4b3457c46d73611edb9e46405c Mon Sep 17 00:00:00 2001
From: Peter Jung <admin@ptr1337.dev>
Date: Tue, 29 Apr 2025 11:24:31 +0200
Subject: [PATCH] CFLAGS: Set -std=gnu17 for all compilation flags

GCC15 uses C23 by default, which breaks a lot of compatibility with the
kernel and this module. Explicitly use -std=gnu17, which was the default in
GCC14.

Signed-off-by: Peter Jung <admin@ptr1337.dev>
Signed-off-by: Eric Naim <dnaim@cachyos.org>
---
 kernel-open/Kbuild      | 1 +
 kernel-open/conftest.sh | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel-open/Kbuild b/kernel-open/Kbuild
index 3d6a8de6c..c78740236 100644
--- a/kernel-open/Kbuild
+++ b/kernel-open/Kbuild
@@ -75,6 +75,7 @@ $(foreach _module, $(NV_KERNEL_MODULES), \
  $(eval include $(src)/$(_module)/$(_module).Kbuild))
 
 
+ccflags-y += -std=gnu17
 ccflags-y += -I$(src)/common/inc
 ccflags-y += -I$(src)
 ccflags-y += -Wall $(DEFINES) $(INCLUDES) -Wno-cast-qual -Wno-format-extra-args
diff --git a/kernel-open/conftest.sh b/kernel-open/conftest.sh
index 20f694ecb..0019e67c7 100755
--- a/kernel-open/conftest.sh
+++ b/kernel-open/conftest.sh
@@ -69,7 +69,7 @@ test_header_presence() {
     # NV_LINUX_FENCE_H_PRESENT, and that is either defined or undefined, in the
     # output (which goes to stdout, just like the rest of this file).
 
-    TEST_CFLAGS="-E -M $CFLAGS"
+    TEST_CFLAGS="-std=gnu17 -E -M $CFLAGS"
 
     file="$1"
     file_define=NV_`echo $file | tr '/.-' '___' | tr 'a-z' 'A-Z'`_PRESENT
@@ -94,7 +94,7 @@ test_header_presence() {
 
 build_cflags() {
     ISYSTEM=`$CC -print-file-name=include 2> /dev/null`
-    BASE_CFLAGS="-O2 -D__KERNEL__ \
+    BASE_CFLAGS="-std=gnu17 -O2 -D__KERNEL__ \
 -DKBUILD_BASENAME=\"#conftest$$\" -DKBUILD_MODNAME=\"#conftest$$\" \
 -nostdinc -isystem $ISYSTEM \
 -Wno-implicit-function-declaration -Wno-strict-prototypes"
