Merge branch 'misc/queue' into 'master'
Misc fixes
See merge request kvm-unit-tests/kvm-unit-tests!24
diff --git a/lib/alloc.c b/lib/alloc.c
index f4266f5..51d774d 100644
--- a/lib/alloc.c
+++ b/lib/alloc.c
@@ -1,48 +1,19 @@
-#include "alloc.h"
-#include "asm/page.h"
-#include "bitops.h"
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include <alloc.h>
+#include <bitops.h>
+#include <asm/page.h>
+#include <linux/compiler.h>
void *malloc(size_t size)
{
return memalign(sizeof(long), size);
}
-static bool mult_overflow(size_t a, size_t b)
-{
-#if BITS_PER_LONG == 32
- /* 32 bit system, easy case: just use u64 */
- return (u64)a * (u64)b >= (1ULL << 32);
-#else
-#ifdef __SIZEOF_INT128__
- /* if __int128 is available use it (like the u64 case above) */
- unsigned __int128 res = a;
- res *= b;
- res >>= 64;
- return res != 0;
-#else
- u64 tmp;
-
- if ((a >> 32) && (b >> 32))
- return true;
- if (!(a >> 32) && !(b >> 32))
- return false;
- tmp = (u32)a;
- tmp *= (u32)b;
- tmp >>= 32;
- if (a < b)
- tmp += a * (b >> 32);
- else
- tmp += b * (a >> 32);
- return tmp >> 32;
-#endif /* __SIZEOF_INT128__ */
-#endif /* BITS_PER_LONG == 32 */
-}
-
void *calloc(size_t nmemb, size_t size)
{
void *ptr;
- assert(!mult_overflow(nmemb, size));
+ assert(!check_mul_overflow(nmemb, size));
ptr = malloc(nmemb * size);
if (ptr)
memset(ptr, 0, nmemb * size);
diff --git a/lib/devicetree.c b/lib/devicetree.c
index 409d18b..fa8399a 100644
--- a/lib/devicetree.c
+++ b/lib/devicetree.c
@@ -288,7 +288,7 @@
int dt_get_initrd(const char **initrd, u32 *size)
{
const struct fdt_property *prop;
- const char *start, *end;
+ u64 start, end;
int node, len;
u32 *data;
@@ -303,7 +303,12 @@
if (!prop)
return len;
data = (u32 *)prop->data;
- start = (const char *)(unsigned long)fdt32_to_cpu(*data);
+ start = fdt32_to_cpu(*data);
+ if (len == 8) {
+ assert(sizeof(long) == 8);
+ data++;
+ start = (start << 32) | fdt32_to_cpu(*data);
+ }
prop = fdt_get_property(fdt, node, "linux,initrd-end", &len);
if (!prop) {
@@ -311,10 +316,14 @@
return len;
}
data = (u32 *)prop->data;
- end = (const char *)(unsigned long)fdt32_to_cpu(*data);
+ end = fdt32_to_cpu(*data);
+ if (len == 8) {
+ data++;
+ end = (end << 32) | fdt32_to_cpu(*data);
+ }
- *initrd = start;
- *size = (unsigned long)end - (unsigned long)start;
+ *initrd = (char *)(unsigned long)start;
+ *size = end - start;
return 0;
}