* [PATCH] erofs-utils: avoid unsigned long if possible (incomplete)
@ 2026-10-07 19:49 Gao Xiang
0 siblings, 0 replies; only message in thread
From: Gao Xiang @ 2026-10-07 19:49 UTC (permalink / raw)
To: linux-erofs; +Cc: Gao Xiang
long is always 32 bits on Windows, even on 64-bit systems.
Link: https://github.com/chenxiaolong/erofs-utils/commit/becfc45e8372992d96bea103e1284875a397111e
Link: https://github.com/erofs/go-erofs/blob/main/.github/workflows/patches/erofs-utils/001-windows.patch
Signed-off-by: Gao Xiang <xiang@kernel.org>
---
include/erofs/err.h | 9 +++++----
include/erofs/internal.h | 2 +-
lib/dedupe.c | 31 +++++++++++++++----------------
lib/inode.c | 4 ++--
lib/kite_deflate.c | 3 +--
5 files changed, 24 insertions(+), 25 deletions(-)
diff --git a/include/erofs/err.h b/include/erofs/err.h
index 28de701..1d18d54 100644
--- a/include/erofs/err.h
+++ b/include/erofs/err.h
@@ -13,6 +13,7 @@ extern "C"
#endif
#include <errno.h>
+#include <stdint.h>
#include <string.h>
#include <stdio.h>
@@ -30,7 +31,7 @@ static inline const char *erofs_strerror(int err)
#define MAX_ERRNO (4095)
#define IS_ERR_VALUE(x) \
- ((unsigned long)(void *)(x) >= (unsigned long)-MAX_ERRNO)
+ ((uintptr_t)(void *)(x) >= (uintptr_t)-MAX_ERRNO)
static inline void *ERR_PTR(long error)
{
@@ -39,18 +40,18 @@ static inline void *ERR_PTR(long error)
static inline int IS_ERR(const void *ptr)
{
- return IS_ERR_VALUE((unsigned long)ptr);
+ return IS_ERR_VALUE((uintptr_t)ptr);
}
static inline long PTR_ERR(const void *ptr)
{
- return (long) ptr;
+ return (intptr_t)ptr;
}
static inline void * ERR_CAST(const void *ptr)
{
/* cast away the const */
- return (void *) ptr;
+ return (void *)ptr;
}
/* EROFS-specific error codes */
diff --git a/include/erofs/internal.h b/include/erofs/internal.h
index d905077..19e38fb 100644
--- a/include/erofs/internal.h
+++ b/include/erofs/internal.h
@@ -348,7 +348,7 @@ static inline unsigned int erofs_inode_datalayout(unsigned int ifmt)
static inline struct erofs_inode *erofs_parent_inode(struct erofs_inode *inode)
{
- return (struct erofs_inode *)((unsigned long)inode->i_parent & ~1UL);
+ return (struct erofs_inode *)((uintptr_t)inode->i_parent & ~(uintptr_t)1);
}
#define IS_ROOT(x) ((x) == erofs_parent_inode(x))
diff --git a/lib/dedupe.c b/lib/dedupe.c
index ec9e2bb..b242f7d 100644
--- a/lib/dedupe.c
+++ b/lib/dedupe.c
@@ -9,18 +9,17 @@
#include "liberofs_xxhash.h"
#include "liberofs_sha256.h"
-unsigned long erofs_memcmp2(const u8 *s1, const u8 *s2,
- unsigned long sz)
+uintptr_t erofs_memcmp2(const u8 *s1, const u8 *s2, uintptr_t sz)
{
- const unsigned long *a1, *a2;
- unsigned long n = sz;
+ const uintptr_t *a1, *a2;
+ uintptr_t n = sz;
- if (sz < sizeof(long))
+ if (sz < sizeof(uintptr_t))
goto out_bytes;
- if (((long)s1 & (sizeof(long) - 1)) ==
- ((long)s2 & (sizeof(long) - 1))) {
- while ((long)s1 & (sizeof(long) - 1)) {
+ if (((uintptr_t)s1 & (sizeof(uintptr_t) - 1)) ==
+ ((uintptr_t)s2 & (sizeof(uintptr_t) - 1))) {
+ while ((uintptr_t)s1 & (sizeof(uintptr_t) - 1)) {
if (*s1 != *s2)
break;
++s1;
@@ -28,25 +27,25 @@ unsigned long erofs_memcmp2(const u8 *s1, const u8 *s2,
--sz;
}
- a1 = (const unsigned long *)s1;
- a2 = (const unsigned long *)s2;
- while (sz >= sizeof(long)) {
+ a1 = (const uintptr_t *)s1;
+ a2 = (const uintptr_t *)s2;
+ while (sz >= sizeof(uintptr_t)) {
if (*a1 != *a2)
break;
++a1;
++a2;
- sz -= sizeof(long);
+ sz -= sizeof(uintptr_t);
}
} else {
- a1 = (const unsigned long *)s1;
- a2 = (const unsigned long *)s2;
+ a1 = (const uintptr_t *)s1;
+ a2 = (const uintptr_t *)s2;
do {
if (get_unaligned(a1) != get_unaligned(a2))
break;
++a1;
++a2;
- sz -= sizeof(long);
- } while (sz >= sizeof(long));
+ sz -= sizeof(uintptr_t);
+ } while (sz >= sizeof(uintptr_t));
}
s1 = (const u8 *)a1;
s2 = (const u8 *)a2;
diff --git a/lib/inode.c b/lib/inode.c
index 489c44e..d819659 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -2169,13 +2169,13 @@ static int erofs_mkfs_handle_inode(const struct erofs_mkfs_btctx *ctx,
static bool erofs_inode_visited(struct erofs_inode *inode)
{
- return (unsigned long)inode->i_parent & 1UL;
+ return (uintptr_t)inode->i_parent & 1;
}
static void erofs_mark_parent_inode(struct erofs_inode *inode,
struct erofs_inode *dir)
{
- inode->i_parent = (void *)((unsigned long)dir | 1);
+ inode->i_parent = (void *)((uintptr_t)dir | 1);
}
static int erofs_mkfs_dump_tree(const struct erofs_mkfs_btctx *ctx)
diff --git a/lib/kite_deflate.c b/lib/kite_deflate.c
index c1d3c6d..67b01c9 100644
--- a/lib/kite_deflate.c
+++ b/lib/kite_deflate.c
@@ -13,8 +13,7 @@
#include <ctype.h>
#include <stdio.h>
-unsigned long erofs_memcmp2(const u8 *s1, const u8 *s2,
- unsigned long sz);
+uintptr_t erofs_memcmp2(const u8 *s1, const u8 *s2, uintptr_t sz);
#ifdef TEST
#define kite_dbg(x, ...) fprintf(stderr, x "\n", ##__VA_ARGS__)
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-07 19:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-07 19:49 [PATCH] erofs-utils: avoid unsigned long if possible (incomplete) Gao Xiang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox