From 76614d52006ae484a78076ee94635c9d669e528a Mon Sep 17 00:00:00 2001 From: Kinsey Moore Date: Thu, 29 Jan 2026 14:14:49 -0600 Subject: [PATCH] jffs2: Resolve signed comparison warnings JFFS2 uses the high values of the unsigned flash offset in a raw node reference as special identifiers and specifies them using negative integer literals. This disables those errors for non-RTEMS source and constrains such comparisons in RTEMS code to avoid larger reworks of the JFFS2 upstream source. --- contrib/cpukit/jffs2/nodelist.h | 22 ++++++++++++++++++++++ cpukit/libfs/src/jffs2/src/malloc-rtems.c | 6 +++--- spec/build/cpukit/objjffs2contrib.yml | 1 + 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/contrib/cpukit/jffs2/nodelist.h b/contrib/cpukit/jffs2/nodelist.h index b30aa5bbf6..2f7f9b395e 100644 --- a/contrib/cpukit/jffs2/nodelist.h +++ b/contrib/cpukit/jffs2/nodelist.h @@ -98,6 +98,25 @@ struct jffs2_raw_node_ref /* Use blocks of about 256 bytes */ #define REFS_PER_BLOCK ((255/sizeof(struct jffs2_raw_node_ref))-1) +#ifdef __rtems__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsign-compare" +/* + * The REF_LINK_NODE and REF_EMPTY_NODE macros should really be uint32_t bit + * patterns instead of signed integer literals to avoid signed comparison + * warnings. This contains all comparisons using them to this section where + * signed comparison warnings are disabled. + */ +static inline bool rtems_jffs2_is_ref_link(struct jffs2_raw_node_ref *ref) +{ + return ref->flash_offset == REF_LINK_NODE; +} + +static inline bool rtems_jffs2_is_ref_empty(struct jffs2_raw_node_ref *ref) +{ + return ref->flash_offset == REF_EMPTY_NODE; +} +#endif static inline struct jffs2_raw_node_ref *ref_next(struct jffs2_raw_node_ref *ref) { ref++; @@ -115,6 +134,9 @@ static inline struct jffs2_raw_node_ref *ref_next(struct jffs2_raw_node_ref *ref return ref; } +#ifdef __rtems__ +#pragma GCC diagnostic pop +#endif static inline struct jffs2_inode_cache *jffs2_raw_ref_to_ic(struct jffs2_raw_node_ref *raw) { diff --git a/cpukit/libfs/src/jffs2/src/malloc-rtems.c b/cpukit/libfs/src/jffs2/src/malloc-rtems.c index 81c3cec2ae..3201f762cd 100644 --- a/cpukit/libfs/src/jffs2/src/malloc-rtems.c +++ b/cpukit/libfs/src/jffs2/src/malloc-rtems.c @@ -72,7 +72,7 @@ static struct jffs2_raw_node_ref *jffs2_alloc_refblock(void) ret = malloc((REFS_PER_BLOCK + 1) * sizeof(*ret)); if (ret) { - int i = 0; + uint32_t i = 0; for (i=0; i < REFS_PER_BLOCK; i++) { ret[i].flash_offset = REF_EMPTY_NODE; ret[i].next_in_ino = NULL; @@ -95,7 +95,7 @@ int jffs2_prealloc_raw_node_refs(struct jffs2_sb_info *c, ref = *p; /* If jeb->last_node is really a valid node then skip over it */ - if (ref && ref->flash_offset != REF_EMPTY_NODE) + if (ref && !rtems_jffs2_is_ref_empty(ref)) ref++; while (i) { @@ -104,7 +104,7 @@ int jffs2_prealloc_raw_node_refs(struct jffs2_sb_info *c, if (!ref) return -ENOMEM; } - if (ref->flash_offset == REF_LINK_NODE) { + if (rtems_jffs2_is_ref_link(ref)) { p = &ref->next_in_ino; ref = *p; continue; diff --git a/spec/build/cpukit/objjffs2contrib.yml b/spec/build/cpukit/objjffs2contrib.yml index f730e80d10..b9bab1922b 100644 --- a/spec/build/cpukit/objjffs2contrib.yml +++ b/spec/build/cpukit/objjffs2contrib.yml @@ -3,6 +3,7 @@ build-type: objects cflags: - ${COVERAGE_COMPILER_FLAGS} - -Wno-pointer-sign +- -Wno-sign-compare copyrights: - Copyright (C) 2020 embedded brains GmbH & Co. KG cppflags: []