Skip to contentSkip to conversation

kbuild: Fix <linux/version.h> for empty SUBLEVEL or PATCHLEVEL again

PATCH In review Masahiro Yamada 3 participants 3 messages Feb 27, 2021 – Mar 1, 2021 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kbuild: Fix <linux/version.h> for empty SUBLEVEL or PATCHLEVEL again

Commit 9b82f13e7ef3 ("kbuild: clamp SUBLEVEL to 255") breaks the build if SUBLEVEL or PATCHLEVEL is empty.

Commit 78d3bb4483ba ("kbuild: Fix <linux/version.h> for empty SUBLEVEL or PATCHLEVEL") fixed the issue by prepending a zero.

This time, we cannot take the same approach because we have C code:

  #define LINUX_VERSION_PATCHLEVEL $(PATCHLEVEL)
  #define LINUX_VERSION_SUBLEVEL $(SUBLEVEL)

Replace empty SUBLEVEL or PATCHLEVEL with a zero.

Fixes 9b82f13e7ef3 ("kbuild: clamp SUBLEVEL to 255")

---

 Makefile | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Makefile +4 -2
index f2dc2f953e23..14c13b09a9e7 100644
@@ -1283,10 +1283,10 @@ endef
 define filechk_version.h
 	if [ $(SUBLEVEL) -gt 255 ]; then                                 \
 		echo \#define LINUX_VERSION_CODE $(shell                 \
-		expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 255); \
+		expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + 255); \
 	else                                                             \
 		echo \#define LINUX_VERSION_CODE $(shell                 \
-		expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \
+		expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \
 	fi;                                                              \
 	echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) +  \
 	((c) > 255 ? 255 : (c)))';                                       \
@@ -1295,6 +1295,8 @@ define filechk_version.h
 	echo \#define LINUX_VERSION_SUBLEVEL $(SUBLEVEL)
 endef
 
+$(version_h): PATCHLEVEL := $(if $(PATCHLEVEL), $(PATCHLEVEL), 0)
+$(version_h): SUBLEVEL := $(if $(SUBLEVEL), $(SUBLEVEL), 0)
 $(version_h): FORCE
 	$(call filechk,version.h)
 
Signature · 1 line
2.27.0
#1 lore raw
Quoted 8 lines · Masahiro Yamada

Commit 9b82f13e7ef3 ("kbuild: clamp SUBLEVEL to 255") breaks the build if SUBLEVEL or PATCHLEVEL is empty.

Commit 78d3bb4483ba ("kbuild: Fix <linux/version.h> for empty SUBLEVEL or PATCHLEVEL") fixed the issue by prepending a zero.

This time, we cannot take the same approach because we have C code:

Quoted 8 lines

#define LINUX_VERSION_PATCHLEVEL $(PATCHLEVEL)
#define LINUX_VERSION_SUBLEVEL $(SUBLEVEL)

Replace empty SUBLEVEL or PATCHLEVEL with a zero.

Fixes 9b82f13e7ef3 ("kbuild: clamp SUBLEVEL to 255")
Reviewed-and-tested-by Sasha Levin <[email protected]>

Thank you!

Signature · 2 lines
Thanks,
Sasha
#2 lore raw
In reply to Masahiro Yamada

From: Masahiro Yamada

Quoted 8 lines

Sent: 27 February 2021 14:20

Commit 9b82f13e7ef3 ("kbuild: clamp SUBLEVEL to 255") breaks the build if SUBLEVEL or PATCHLEVEL is empty.

Commit 78d3bb4483ba ("kbuild: Fix <linux/version.h> for empty SUBLEVEL or PATCHLEVEL") fixed the issue by prepending a zero.

Quoted 6 lines

This time, we cannot take the same approach because we have C code:

  #define LINUX_VERSION_PATCHLEVEL $(PATCHLEVEL)
  #define LINUX_VERSION_SUBLEVEL $(SUBLEVEL)

Replace empty SUBLEVEL or PATCHLEVEL with a zero.

You could do:

#define LINUX_VERSION_PATCHLEVEL ($(PATCHLEVEL) + 0)

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)