Skip to contentSkip to conversation

Fix detection of dev_addr_set availability on 4.19 kernels

PATCH In review Jan Kiszka 2 participants 3 messages Sep 27, 2023 – Sep 28, 2023

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 Fix detection of dev_addr_set availability on 4.19 kernels

From: Jan Kiszka <[email protected]>

As the SUBLEVEL in LINUX_VERSION_CODE is 8-bits only and is clamped at 255, we cannot detect this way that 4.19.291 also gained support for dev_addr_set and eth_hw_addr_set. Upstream does not care about out-of-tree, so work around this limitation by extracting the true SUBLEVEL in prepare-kernel.sh and exporting it via Kconfig.

This is expected to remain limited to 4.19, thus is stable/v3.2.x only. And since 5.12, upstream has a KERNEL_VERSION_SUBLEVEL define in the generated version.h.

---
 kernel/cobalt/include/asm-generic/xenomai/wrappers.h | 4 +++-
 scripts/Kconfig.frag                                 | 4 ++++
 scripts/prepare-kernel.sh                            | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)
kernel/cobalt/include/asm-generic/xenomai/wrappers.h +3 -1
index 7654047b4d..8ba95af27d 100644
@@ -258,7 +258,9 @@ devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
     (LINUX_VERSION_CODE >= KERNEL_VERSION(5,5,0) || \
      LINUX_VERSION_CODE < KERNEL_VERSION(5,4,251)) && \
     (LINUX_VERSION_CODE >= KERNEL_VERSION(4,20,0) || \
-     LINUX_VERSION_CODE < KERNEL_VERSION(4,19,291))
+     LINUX_VERSION_CODE < KERNEL_VERSION(4,19,255) || \
+     (LINUX_VERSION_CODE == KERNEL_VERSION(4,19,255) && \
+      CONFIG_KVER_SUBLEVEL < 291))
 #define dev_addr_set(dev, addr)		memcpy((dev)->dev_addr, addr, MAX_ADDR_LEN)
 #define eth_hw_addr_set(dev, addr)	memcpy((dev)->dev_addr, addr, ETH_ALEN)
 #endif
scripts/Kconfig.frag +4 -0
index 7921286638..8eae9da693 100644
@@ -47,3 +47,7 @@ config XENO_REVISION_LEVEL
 config XENO_VERSION_STRING
        string
        default "@VERSION_STRING@"
+
+config KVER_SUBLEVEL
+       int
+       default @KVER_SUBLEVEL@
scripts/prepare-kernel.sh +1 -0
index 64e2484e16..a06a9f2308 100755
@@ -399,6 +399,7 @@ case $linux_VERSION.$linux_PATCHLEVEL in
 	    -e "s,@VERSION_MINOR@,$version_minor,g" \
 	    -e "s,@REVISION_LEVEL@,$revision_level,g" \
 	    -e "s,@VERSION_STRING@,$version_string,g" \
+	    -e "s,@KVER_SUBLEVEL@,$linux_SUBLEVEL,g" \
 	    -e "s,@SRCARCH@,$linux_arch,g" \
 	    $xenomai_root/scripts/Kconfig.frag |
             patch_append init/Kconfig
Signature · 1 line
2.35.3
#1 lore raw
Quoted 11 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

As the SUBLEVEL in LINUX_VERSION_CODE is 8-bits only and is clamped at 255, we cannot detect this way that 4.19.291 also gained support for dev_addr_set and eth_hw_addr_set. Upstream does not care about out-of-tree, so work around this limitation by extracting the true SUBLEVEL in prepare-kernel.sh and exporting it via Kconfig.

This is expected to remain limited to 4.19, thus is stable/v3.2.x only. And since 5.12, upstream has a KERNEL_VERSION_SUBLEVEL define in the generated version.h.

I'm not a fan of this solution, but I don't have a better idea ATM.

There is a strong feeling here that this problem will come back at some point in time. We enabled 6.1 support for stable/v3.2.x recently so it is not expected that this branch will disappear soon. Let's hope we manage to maintain it over time.

Best regards,
Florian

Quoted 49 lines
---
 kernel/cobalt/include/asm-generic/xenomai/wrappers.h | 4 +++-
 scripts/Kconfig.frag                                 | 4 ++++
 scripts/prepare-kernel.sh                            | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)
kernel/cobalt/include/asm-generic/xenomai/wrappers.h +3 -1
index 7654047b4d..8ba95af27d 100644
@@ -258,7 +258,9 @@ devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
     (LINUX_VERSION_CODE >= KERNEL_VERSION(5,5,0) || \
      LINUX_VERSION_CODE < KERNEL_VERSION(5,4,251)) && \
     (LINUX_VERSION_CODE >= KERNEL_VERSION(4,20,0) || \
-     LINUX_VERSION_CODE < KERNEL_VERSION(4,19,291))
+     LINUX_VERSION_CODE < KERNEL_VERSION(4,19,255) || \
+     (LINUX_VERSION_CODE == KERNEL_VERSION(4,19,255) && \
+      CONFIG_KVER_SUBLEVEL < 291))
 #define dev_addr_set(dev, addr)		memcpy((dev)->dev_addr, addr, MAX_ADDR_LEN)
 #define eth_hw_addr_set(dev, addr)	memcpy((dev)->dev_addr, addr, ETH_ALEN)
 #endif
scripts/Kconfig.frag +4 -0
index 7921286638..8eae9da693 100644
@@ -47,3 +47,7 @@ config XENO_REVISION_LEVEL
 config XENO_VERSION_STRING
        string
        default "@VERSION_STRING@"
+
+config KVER_SUBLEVEL
+       int
+       default @KVER_SUBLEVEL@
scripts/prepare-kernel.sh +1 -0
index 64e2484e16..a06a9f2308 100755
@@ -399,6 +399,7 @@ case $linux_VERSION.$linux_PATCHLEVEL in
 	    -e "s,@VERSION_MINOR@,$version_minor,g" \
 	    -e "s,@REVISION_LEVEL@,$revision_level,g" \
 	    -e "s,@VERSION_STRING@,$version_string,g" \
+	    -e "s,@KVER_SUBLEVEL@,$linux_SUBLEVEL,g" \
 	    -e "s,@SRCARCH@,$linux_arch,g" \
 	    $xenomai_root/scripts/Kconfig.frag |
             patch_append init/Kconfig
Signature · 1 line
2.35.3
author
#2 lore raw
Quoted 13 lines · Florian Bezdeka
Quoted 11 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

As the SUBLEVEL in LINUX_VERSION_CODE is 8-bits only and is clamped at 255, we cannot detect this way that 4.19.291 also gained support for dev_addr_set and eth_hw_addr_set. Upstream does not care about out-of-tree, so work around this limitation by extracting the true SUBLEVEL in prepare-kernel.sh and exporting it via Kconfig.

This is expected to remain limited to 4.19, thus is stable/v3.2.x only. And since 5.12, upstream has a KERNEL_VERSION_SUBLEVEL define in the generated version.h.

Quoted 6 lines

I'm not a fan of this solution, but I don't have a better idea ATM.

There is a strong feeling here that this problem will come back at some point in time. We enabled 6.1 support for stable/v3.2.x recently so it is not expected that this branch will disappear soon. Let's hope we manage to maintain it over time.

For this branch, we now have a solution. I think we won't need it anymore for master as only 5.10 could be affected there, and it also still takes a later breaking backport to actually trigger it. Nevertheless, I will split up this commit into infrastructure and the actual application to wrapper.h so that it would be easier to cherry-pick the infrastructure into master/3.3.x if needed in the future.

Jan

Signature · 2 lines
Siemens AG, Technology
Linux Expert Center