Skip to contentSkip to conversation

erofs-utils: introduce `fallthrough;`

PATCH New Gao Xiang 1 participant 4 messages Jul 8, 2025 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/4 erofs-utils: introduce `fallthrough;`

To silence the Missing break in switch (MISSING_BREAK) warning.

Coverity-id: 569459

---
 include/erofs/defs.h | 6 ++++++
 lib/namei.c          | 1 +
 lib/rebuild.c        | 2 +-
 lib/zmap.c           | 2 +-
 4 files changed, 9 insertions(+), 2 deletions(-)
include/erofs/defs.h +6 -0
index 21e0f09d..0f3e7546 100644
@@ -369,6 +369,12 @@ unsigned long __roundup_pow_of_two(unsigned long n)
 #define __erofs_likely(x)      __builtin_expect(!!(x), 1)
 #define __erofs_unlikely(x)    __builtin_expect(!!(x), 0)
 
+#if __has_attribute(__fallthrough__)
+# define fallthrough	__attribute__((__fallthrough__))
+#else
+# define fallthrough	do {} while (0)  /* fallthrough */
+#endif
+
 #ifdef __cplusplus
 }
 #endif
lib/namei.c +1 -0
index 5da8ed98..d6013e5c 100644
@@ -102,6 +102,7 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi)
 	switch (vi->i_mode & S_IFMT) {
 	case S_IFDIR:
 		vi->dot_omitted = (ifmt >> EROFS_I_DOT_OMITTED_BIT) & 1;
+		fallthrough;
 	case S_IFREG:
 	case S_IFLNK:
 		vi->u.i_blkaddr = le32_to_cpu(copied.i_u.startblk_lo) |
lib/rebuild.c +1 -1
index 576d9d05..c580f81f 100644
@@ -231,7 +231,7 @@ static int erofs_rebuild_update_inode(struct erofs_sb_info *dst_sb,
 	case S_IFCHR:
 		if (erofs_inode_is_whiteout(inode))
 			inode->i_parent->whiteouts = true;
-		/* fallthrough */
+		fallthrough;
 	case S_IFBLK:
 	case S_IFIFO:
 	case S_IFSOCK:
lib/zmap.c +1 -1
index 99f40887..43e76e55 100644
@@ -474,7 +474,7 @@ static int z_erofs_map_blocks_fo(struct erofs_inode *vi,
 		end = (m.lcn << lclusterbits) | m.clusterofs;
 		map->m_flags |= EROFS_MAP_FULL_MAPPED;
 		m.delta[0] = 1;
-		/* fallthrough */
+		fallthrough;
 	case Z_EROFS_LCLUSTER_TYPE_NONHEAD:
 		/* get the corresponding first chunk */
 		err = z_erofs_extent_lookback(&m, m.delta[0]);
Signature · 1 line
2.43.5
author
#1 lore raw

PATCH 2/4 erofs-utils: silence `Unintentional integer overflow`

Coverity-id: 569450
Coverity-id: 569460

---
 lib/blobchunk.c | 2 +-
 lib/zmap.c      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
lib/blobchunk.c +1 -1
index ccc77b0b..024a3927 100644
@@ -150,7 +150,7 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,
 	else
 		unit = EROFS_BLOCK_MAP_ENTRY_SIZE;
 
-	chunkblks = 1U << (inode->u.chunkformat & EROFS_CHUNK_FORMAT_BLKBITS_MASK);
+	chunkblks = 1ULL << (inode->u.chunkformat & EROFS_CHUNK_FORMAT_BLKBITS_MASK);
 	_48bit = inode->u.chunkformat & EROFS_CHUNK_FORMAT_48BIT;
 	for (dst = src = 0; dst < inode->extent_isize;
 	     src += sizeof(void *), dst += unit) {
lib/zmap.c +1 -1
index 43e76e55..22d7a092 100644
@@ -604,7 +604,7 @@ static int z_erofs_map_blocks_ext(struct erofs_inode *vi,
 		}
 		last = (lstart >= round_up(lend, 1 << vi->z_lclusterbits));
 		lend = min(lstart, lend);
-		lstart -= 1 << vi->z_lclusterbits;
+		lstart -= 1ULL << vi->z_lclusterbits;
 	} else {
 		lstart = lend;
 		for (l = 0, r = vi->z_extents; l < r; ) {
Signature · 1 line
2.43.5
author
#2 lore raw

PATCH 3/4 erofs-utils: resolve `PRINTF_ARGS`

In reply to Gao Xiang

Coverity-id: 569452
Coverity-id: 569454
Coverity-id: 569455

---
 lib/blobchunk.c |  4 ++--
 lib/cache.c     |  3 ++-
 lib/dir.c       | 11 ++++++-----
 3 files changed, 10 insertions(+), 8 deletions(-)
lib/blobchunk.c +2 -2
index 024a3927..54644cd4 100644
@@ -73,8 +73,8 @@ static struct erofs_blobchunk *erofs_blob_getchunk(struct erofs_sb_info *sbi,
 			chunk = &erofs_holechunk;
 			erofs_dbg("Found duplicated hole chunk");
 		} else {
-			erofs_dbg("Found duplicated chunk at %u",
-				  chunk->blkaddr);
+			erofs_dbg("Found duplicated chunk at %llu",
+				  chunk->blkaddr | 0ULL);
 		}
 		return chunk;
 	}
lib/cache.c +2 -1
index b91a2887..2c730169 100644
@@ -487,7 +487,8 @@ int erofs_bflush(struct erofs_bufmgr *bmgr,
 
 		if (p->type != DATA)
 			bmgr->metablkcnt += p->buffers.nblocks;
-		erofs_dbg("block %u to %u flushed", p->blkaddr, blkaddr - 1);
+		erofs_dbg("block %llu to %llu flushed", p->blkaddr | 0ULL,
+			  (blkaddr - 1) | 0ULL);
 		erofs_bfree(p);
 	}
 	return 0;
lib/dir.c +6 -5
index 3405844c..821a364f 100644
@@ -18,7 +18,7 @@ static bool erofs_validate_filename(const char *dname, int size)
 }
 
 static int traverse_dirents(struct erofs_dir_context *ctx,
-			    void *dentry_blk, unsigned int lblk,
+			    void *dentry_blk, erofs_off_t lblk,
 			    unsigned int next_nameoff, unsigned int maxsize,
 			    bool fsck)
 {
@@ -132,8 +132,8 @@ static int traverse_dirents(struct erofs_dir_context *ctx,
 	}
 out:
 	if (ret && !silent)
-		erofs_err("%s @ nid %llu, lblk %u, index %lu",
-			  errmsg, ctx->dir->nid | 0ULL, lblk,
+		erofs_err("%s @ nid %llu, lblk %llu, index %lu",
+			  errmsg, ctx->dir->nid | 0ULL, lblk | 0ULL,
 			  (de - (struct erofs_dirent *)dentry_blk) | 0UL);
 	return ret;
 }
@@ -162,8 +162,9 @@ int erofs_iterate_dir(struct erofs_dir_context *ctx, bool fsck)
 
 		err = erofs_pread(dir, buf, maxsize, pos);
 		if (err) {
-			erofs_err("I/O error occurred when reading dirents @ nid %llu, lblk %u: %d",
-				  dir->nid | 0ULL, lblk, err);
+			erofs_err("I/O error when reading dirents @ nid %llu, lblk %llu: %s",
+				  dir->nid | 0ULL, lblk | 0ULL,
+				  erofs_strerror(err));
 			return err;
 		}
 
Signature · 1 line
2.43.5
author
#3 lore raw

PATCH 4/4 erofs-utils: lib: fix `INTEGER_OVERFLOW`

In reply to Gao Xiang

Coverity-id: 569453

Fixes 341d23a878a2 ("erofs-utils: mkfs: speed up uncompressed data handling")
---
 lib/compress.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
lib/compress.c +8 -11
index 8999b2c7..bf471218 100644
@@ -579,18 +579,15 @@ static int __z_erofs_compress_one(struct z_erofs_compress_sctx *ctx,
 	if (len <= ctx->pclustersize) {
 		if (!final || !len)
 			return 1;
-		if (may_packing) {
-			if (inode->fragment_size && !ictx->fix_dedupedfrag) {
-				ctx->pclustersize = roundup(len, blksz);
-				goto fix_dedupedfrag;
-			}
-			e->length = len;
-			goto frag_packing;
+		if (may_packing && inode->fragment_size && !ictx->fix_dedupedfrag) {
+			ctx->pclustersize = roundup(len, blksz);
+			goto fix_dedupedfrag;
 		}
-		if (!may_inline && len <= blksz) {
-			e->length = len;
+		e->length = len;
+		if (may_packing)
+			goto frag_packing;
+		if (!may_inline && len <= blksz)
 			goto nocompression;
-		}
 	}
 
 	e->length = min(len, cfg.c_max_decompressed_extent_bytes);
@@ -629,7 +626,7 @@ retry_aligned:
 		} else {
 			may_inline = false;
 			may_packing = false;
-			e->length = min_t(u32, e->length, ret);
+			e->length = min_t(u32, e->length, ctx->pclustersize);
 nocompression:
 			if (cfg.c_dedupe)
 				ret = write_uncompressed_block(ctx, len, dst);
Signature · 1 line
2.43.5