1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
From 4e18b842b3dae5486adb2c6cc11bdfdd53ee8646 Mon Sep 17 00:00:00 2001
From: Tobias Stoeckmann <tobias@stoeckmann.org>
Date: Wed, 14 Jan 2026 20:58:50 +0100
Subject: [PATCH] util: Add s390 31 bit mode support
Even though size_t is of the same size as a uint32_t, the s390
architecture is a bit picky about its 31 bit mode with size_t.
Use custom code to fix this issue in a rather architecture
independent but unfortunately slower way for s390 31 bit mode.
Reference: https://github.com/kmod-project/kmod/issues/402
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
---
shared/util.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/shared/util.h b/shared/util.h
index bf3f1009..b785f5b1 100644
--- a/shared/util.h
+++ b/shared/util.h
@@ -123,7 +123,15 @@ static inline bool uaddsz_overflow(size_t a, size_t b, size_t *res)
#if __SIZEOF_SIZE_T__ == 8
return uadd64_overflow(a, b, res);
#elif __SIZEOF_SIZE_T__ == 4
+#ifdef __s390__
+ if (b < SIZE_MAX - a) {
+ *res = a + b;
+ return true;
+ }
+ return false;
+#else
return uadd32_overflow(a, b, res);
+#endif
#else
#error "Unknown sizeof(size_t)"
#endif
@@ -167,7 +175,15 @@ static inline bool umulsz_overflow(size_t a, size_t b, size_t *res)
#if __SIZEOF_SIZE_T__ == 8
return umul64_overflow(a, b, res);
#elif __SIZEOF_SIZE_T__ == 4
+#ifdef __s390__
+ if (a == 0 || b <= SIZE_MAX / a) {
+ *res = a * b;
+ return true;
+ }
+ return false;
+#else
return umul32_overflow(a, b, res);
+#endif
#else
#error "Unknown sizeof(size_t)"
#endif
|