Skip to contentSkip to conversation

erofs-utils: fix invalid argument type in erofs_err()

PATCH Superseded Hongzhen Luo 2 participants 3 messages Aug 14, 2024 Library code

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 erofs-utils: fix invalid argument type in erofs_err()

Coverity-id: 502374, 502367, 502362, 502348, 502342, 502341,

	     502340, 502358

Fix several issues found by Coverity regarding "Invalid type in argument for printf format specifier".

---
v2: Unified through %llu to output debugging information.
v1: https://lore.kernel.org/all/[email protected]/

---
 fsck/main.c     |  4 ++--
 lib/blobchunk.c |  3 ++-
 lib/compress.c  |  4 ++--
 lib/fragments.c | 10 +++++-----
 lib/super.c     |  3 ++-
 mkfs/main.c     |  2 +-
 6 files changed, 14 insertions(+), 12 deletions(-)
fsck/main.c +2 -2
index 28f1e7e..89d87fb 100644
@@ -807,8 +807,8 @@ static int erofsfsck_dirent_iter(struct erofs_dir_context *ctx)
 	curr_pos = prev_pos;
 
 	if (prev_pos + ctx->de_namelen >= PATH_MAX) {
-		erofs_err("unable to fsck since the path is too long (%u)",
-			  curr_pos + ctx->de_namelen);
+		erofs_err("unable to fsck since the path is too long (%llu)",
+			  (curr_pos + ctx->de_namelen) | 0ULL);
 		return -EOPNOTSUPP;
 	}
 
lib/blobchunk.c +2 -1
index 2835755..33b44e3 100644
@@ -95,7 +95,8 @@ static struct erofs_blobchunk *erofs_blob_getchunk(struct erofs_sb_info *sbi,
 		chunk->device_id = 0;
 	chunk->blkaddr = erofs_blknr(sbi, blkpos);
 
-	erofs_dbg("Writing chunk (%u bytes) to %u", chunksize, chunk->blkaddr);
+	erofs_dbg("Writing chunk (%llu bytes) to %llu", chunksize | 0ULL,
+							chunk->blkaddr | 0ULL);
 	ret = fwrite(buf, chunksize, 1, blobfile);
 	if (ret == 1) {
 		padding = erofs_blkoff(sbi, chunksize);
lib/compress.c +2 -2
index 8655e78..17e7112 100644
@@ -497,8 +497,8 @@ static bool z_erofs_fixup_deduped_fragment(struct z_erofs_compress_sctx *ctx,
 	inode->fragmentoff += inode->fragment_size - newsize;
 	inode->fragment_size = newsize;
 
-	erofs_dbg("Reducing fragment size to %u at %llu",
-		  inode->fragment_size, inode->fragmentoff | 0ULL);
+	erofs_dbg("Reducing fragment size to %llu at %llu",
+		  inode->fragment_size | 0ULL, inode->fragmentoff | 0ULL);
 
 	/* it's the end */
 	DBG_BUGON(ctx->tail - ctx->head + ctx->remaining != newsize);
lib/fragments.c +5 -5
index 7591718..e2d3343 100644
@@ -138,7 +138,7 @@ static int z_erofs_fragments_dedupe_find(struct erofs_inode *inode, int fd,
 	inode->fragment_size = deduped;
 	inode->fragmentoff = pos;
 
-	erofs_dbg("Dedupe %u tail data at %llu", inode->fragment_size,
+	erofs_dbg("Dedupe %llu tail data at %llu", inode->fragment_size | 0ULL,
 		  inode->fragmentoff | 0ULL);
 out:
 	free(data);
@@ -283,8 +283,8 @@ int z_erofs_pack_file_from_fd(struct erofs_inode *inode, int fd,
 		goto out;
 	}
 
-	erofs_dbg("Recording %u fragment data at %lu", inode->fragment_size,
-		  inode->fragmentoff);
+	erofs_dbg("Recording %llu fragment data at %llu",
+		  inode->fragment_size | 0ULL, inode->fragmentoff | 0ULL);
 
 	if (memblock)
 		rc = z_erofs_fragments_dedupe_insert(memblock,
@@ -316,8 +316,8 @@ int z_erofs_pack_fragments(struct erofs_inode *inode, void *data,
 	if (fwrite(data, len, 1, packedfile) != 1)
 		return -EIO;
 
-	erofs_dbg("Recording %u fragment data at %lu", inode->fragment_size,
-		  inode->fragmentoff);
+	erofs_dbg("Recording %llu fragment data at %llu",
+		  inode->fragment_size | 0ULL, inode->fragmentoff | 0ULL);
 
 	ret = z_erofs_fragments_dedupe_insert(data, len, inode->fragmentoff,
 					      tofcrc);
lib/super.c +2 -1
index 32e10cd..7c4d7f2 100644
@@ -213,7 +213,8 @@ struct erofs_buffer_head *erofs_reserve_sb(struct erofs_bufmgr *bmgr)
 
 	bh = erofs_balloc(bmgr, META, 0, 0, 0);
 	if (IS_ERR(bh)) {
-		erofs_err("failed to allocate super: %s", PTR_ERR(bh));
+		erofs_err("failed to allocate super: %s",
+					erofs_strerror(PTR_ERR(bh)));
 		return bh;
 	}
 	bh->op = &erofs_skip_write_bhops;
mkfs/main.c +1 -1
index b7129eb..1027fc6 100644
@@ -274,7 +274,7 @@ static int erofs_mkfs_feat_set_fragments(bool en, const char *val,
 		u64 i = strtoull(val, &endptr, 0);
 
 		if (endptr - val != vallen) {
-			erofs_err("invalid pcluster size %s for the packed file %s", val);
+			erofs_err("invalid pcluster size %s for the packed file", val);
 			return -EINVAL;
 		}
 		pclustersize_packed = i;
Signature · 1 line
2.43.5
#1 lore raw
Quoted 39 lines · Hongzhen Luo

Coverity-id: 502374, 502367, 502362, 502348, 502342, 502341,

	     502340, 502358

Fix several issues found by Coverity regarding "Invalid type in argument for printf format specifier".

---
v2: Unified through %llu to output debugging information.
v1: https://lore.kernel.org/all/[email protected]/

---
  fsck/main.c     |  4 ++--
  lib/blobchunk.c |  3 ++-
  lib/compress.c  |  4 ++--
  lib/fragments.c | 10 +++++-----
  lib/super.c     |  3 ++-
  mkfs/main.c     |  2 +-
  6 files changed, 14 insertions(+), 12 deletions(-)
fsck/main.c +2 -2
index 28f1e7e..89d87fb 100644
@@ -807,8 +807,8 @@ static int erofsfsck_dirent_iter(struct erofs_dir_context *ctx)
  	curr_pos = prev_pos;
 
  	if (prev_pos + ctx->de_namelen >= PATH_MAX) {
-		erofs_err("unable to fsck since the path is too long (%u)",
-			  curr_pos + ctx->de_namelen);
+		erofs_err("unable to fsck since the path is too long (%llu)",
+			  (curr_pos + ctx->de_namelen) | 0ULL);
  		return -EOPNOTSUPP;
  	}
 
lib/blobchunk.c +0 -0
index 2835755..33b44e3 100644

lib/blobchunk.c static struct erofs_blobchunk *erofs_blob_getchunk(struct erofs_sb_info *sbi, · line 99

Quoted 6 lines
lib/blobchunk.c +2 -1
@@ -95,7 +95,8 @@ static struct erofs_blobchunk *erofs_blob_getchunk(struct erofs_sb_info *sbi,
  		chunk->device_id = 0;
  	chunk->blkaddr = erofs_blknr(sbi, blkpos);
 
-	erofs_dbg("Writing chunk (%u bytes) to %u", chunksize, chunk->blkaddr);
+	erofs_dbg("Writing chunk (%llu bytes) to %llu", chunksize | 0ULL,
+							chunk->blkaddr | 0ULL);

Alignment issue?

Quoted 58 lines
lib/blobchunk.c +0 -0
  	ret = fwrite(buf, chunksize, 1, blobfile);
  	if (ret == 1) {
  		padding = erofs_blkoff(sbi, chunksize);
lib/compress.c +2 -2
index 8655e78..17e7112 100644
@@ -497,8 +497,8 @@ static bool z_erofs_fixup_deduped_fragment(struct z_erofs_compress_sctx *ctx,
  	inode->fragmentoff += inode->fragment_size - newsize;
  	inode->fragment_size = newsize;
 
-	erofs_dbg("Reducing fragment size to %u at %llu",
-		  inode->fragment_size, inode->fragmentoff | 0ULL);
+	erofs_dbg("Reducing fragment size to %llu at %llu",
+		  inode->fragment_size | 0ULL, inode->fragmentoff | 0ULL);
 
  	/* it's the end */
  	DBG_BUGON(ctx->tail - ctx->head + ctx->remaining != newsize);
lib/fragments.c +5 -5
index 7591718..e2d3343 100644
@@ -138,7 +138,7 @@ static int z_erofs_fragments_dedupe_find(struct erofs_inode *inode, int fd,
  	inode->fragment_size = deduped;
  	inode->fragmentoff = pos;
 
-	erofs_dbg("Dedupe %u tail data at %llu", inode->fragment_size,
+	erofs_dbg("Dedupe %llu tail data at %llu", inode->fragment_size | 0ULL,
  		  inode->fragmentoff | 0ULL);
  out:
  	free(data);
@@ -283,8 +283,8 @@ int z_erofs_pack_file_from_fd(struct erofs_inode *inode, int fd,
  		goto out;
  	}
 
-	erofs_dbg("Recording %u fragment data at %lu", inode->fragment_size,
-		  inode->fragmentoff);
+	erofs_dbg("Recording %llu fragment data at %llu",
+		  inode->fragment_size | 0ULL, inode->fragmentoff | 0ULL);
 
  	if (memblock)
  		rc = z_erofs_fragments_dedupe_insert(memblock,
@@ -316,8 +316,8 @@ int z_erofs_pack_fragments(struct erofs_inode *inode, void *data,
  	if (fwrite(data, len, 1, packedfile) != 1)
  		return -EIO;
 
-	erofs_dbg("Recording %u fragment data at %lu", inode->fragment_size,
-		  inode->fragmentoff);
+	erofs_dbg("Recording %llu fragment data at %llu",
+		  inode->fragment_size | 0ULL, inode->fragmentoff | 0ULL);
 
  	ret = z_erofs_fragments_dedupe_insert(data, len, inode->fragmentoff,
  					      tofcrc);
lib/super.c +0 -0
index 32e10cd..7c4d7f2 100644

lib/super.c struct erofs_buffer_head *erofs_reserve_sb(struct erofs_bufmgr *bmgr) · line 217

Quoted 6 lines
lib/super.c +2 -1
@@ -213,7 +213,8 @@ struct erofs_buffer_head *erofs_reserve_sb(struct erofs_bufmgr *bmgr)
 
  	bh = erofs_balloc(bmgr, META, 0, 0, 0);
  	if (IS_ERR(bh)) {
-		erofs_err("failed to allocate super: %s", PTR_ERR(bh));
+		erofs_err("failed to allocate super: %s",
+					erofs_strerror(PTR_ERR(bh)));

Alignment issue again?

Thanks,
Gao Xiang

Quoted 16 lines
lib/super.c +0 -0
  		return bh;
  	}
  	bh->op = &erofs_skip_write_bhops;
mkfs/main.c +1 -1
index b7129eb..1027fc6 100644
@@ -274,7 +274,7 @@ static int erofs_mkfs_feat_set_fragments(bool en, const char *val,
  		u64 i = strtoull(val, &endptr, 0);
 
  		if (endptr - val != vallen) {
-			erofs_err("invalid pcluster size %s for the packed file %s", val);
+			erofs_err("invalid pcluster size %s for the packed file", val);
  			return -EINVAL;
  		}
  		pclustersize_packed = i;
#2 lore raw
Quoted 41 lines · Gao Xiang
Quoted 38 lines · Hongzhen Luo

Coverity-id: 502374, 502367, 502362, 502348, 502342, 502341, 502340, 502358

Fix several issues found by Coverity regarding "Invalid type in argument for printf format specifier".

---
v2: Unified through %llu to output debugging information.
v1: https://lore.kernel.org/all/[email protected]/
---
  fsck/main.c     |  4 ++--
  lib/blobchunk.c |  3 ++-
  lib/compress.c  |  4 ++--
  lib/fragments.c | 10 +++++-----
  lib/super.c     |  3 ++-
  mkfs/main.c     |  2 +-

  6 files changed, 14 insertions(+), 12 deletions(-)
fsck/main.c +2 -2
index 28f1e7e..89d87fb 100644
@@ -807,8 +807,8 @@ static int erofsfsck_dirent_iter(struct 
 erofs_dir_context *ctx)
       curr_pos = prev_pos;
         if (prev_pos + ctx->de_namelen >= PATH_MAX) {
-        erofs_err("unable to fsck since the path is too long (%u)",
-              curr_pos + ctx->de_namelen);
+        erofs_err("unable to fsck since the path is too long (%llu)",
+              (curr_pos + ctx->de_namelen) | 0ULL);
           return -EOPNOTSUPP;
       }

  diff --git a/lib/blobchunk.c b/lib/blobchunk.c
index 2835755..33b44e3 100644

lib/blobchunk.c +0 -0
@@ -95,7 +95,8 @@ static struct erofs_blobchunk 
Quoted 8 lines

lib/blobchunk.c static struct erofs_blobchunk *erofs_blob_getchunk(struct erofs_sb_info *sbi, · line 99

Quoted 6 lines
lib/blobchunk.c +2 -0
 *erofs_blob_getchunk(struct erofs_sb_info *sbi,
           chunk->device_id = 0;
       chunk->blkaddr = erofs_blknr(sbi, blkpos);
   -    erofs_dbg("Writing chunk (%u bytes) to %u", chunksize, chunk->blkaddr);
+    erofs_dbg("Writing chunk (%llu bytes) to %llu", chunksize | 0ULL,
+                            chunk->blkaddr | 0ULL);

Alignment issue?

My negligence, I will fix the alignment issue soon.

Quoted 66 lines
Quoted 57 lines
lib/blobchunk.c +0 -0
       ret = fwrite(buf, chunksize, 1, blobfile);
       if (ret == 1) {

          padding = erofs_blkoff(sbi, chunksize);

lib/compress.c +2 -1
index 8655e78..17e7112 100644
@@ -497,8 +497,8 @@ static bool z_erofs_fixup_deduped_fragment(struct 
 z_erofs_compress_sctx *ctx,
       inode->fragmentoff += inode->fragment_size - newsize;
       inode->fragment_size = newsize;
   -    erofs_dbg("Reducing fragment size to %u at %llu",
-          inode->fragment_size, inode->fragmentoff | 0ULL);
+    erofs_dbg("Reducing fragment size to %llu at %llu",
+          inode->fragment_size | 0ULL, inode->fragmentoff | 0ULL);
         /* it's the end */
       DBG_BUGON(ctx->tail - ctx->head + ctx->remaining != newsize);
lib/fragments.c +1 -0
index 7591718..e2d3343 100644
@@ -138,7 +138,7 @@ static int z_erofs_fragments_dedupe_find(struct 
 erofs_inode *inode, int fd,
       inode->fragment_size = deduped;
       inode->fragmentoff = pos;
   -    erofs_dbg("Dedupe %u tail data at %llu", inode->fragment_size,
+    erofs_dbg("Dedupe %llu tail data at %llu", inode->fragment_size 
 | 0ULL,
             inode->fragmentoff | 0ULL);

  out:
      free(data);

lib/fragments.c +4 -2
@@ -283,8 +283,8 @@ int z_erofs_pack_file_from_fd(struct erofs_inode 
 *inode, int fd,
           goto out;
       }
   -    erofs_dbg("Recording %u fragment data at %lu", inode->fragment_size,
-          inode->fragmentoff);
+    erofs_dbg("Recording %llu fragment data at %llu",
+          inode->fragment_size | 0ULL, inode->fragmentoff | 0ULL);
         if (memblock)
           rc = z_erofs_fragments_dedupe_insert(memblock,
@@ -316,8 +316,8 @@ int z_erofs_pack_fragments(struct erofs_inode 
 *inode, void *data,
       if (fwrite(data, len, 1, packedfile) != 1)
           return -EIO;
   -    erofs_dbg("Recording %u fragment data at %lu", inode->fragment_size,
-          inode->fragmentoff);
+    erofs_dbg("Recording %llu fragment data at %llu",
+          inode->fragment_size | 0ULL, inode->fragmentoff | 0ULL);
         ret = z_erofs_fragments_dedupe_insert(data, len, inode->fragmentoff,
                             tofcrc);
lib/super.c +0 -0
index 32e10cd..7c4d7f2 100644

lib/super.c struct erofs_buffer_head *erofs_reserve_sb(struct · line 217

Quoted 6 lines
lib/super.c +2 -1
@@ -213,7 +213,8 @@ struct erofs_buffer_head *erofs_reserve_sb(struct 
 erofs_bufmgr *bmgr)
         bh = erofs_balloc(bmgr, META, 0, 0, 0);
       if (IS_ERR(bh)) {
-        erofs_err("failed to allocate super: %s", PTR_ERR(bh));
+        erofs_err("failed to allocate super: %s",
+                    erofs_strerror(PTR_ERR(bh)));

Alignment issue again?

Quoted 3 lines

Thanks,
Gao Xiang

Same.

---

Thanks,

Hongzhen Luo

Quoted 18 lines
Quoted 18 lines
lib/super.c +0 -0
           return bh;
       }
       bh->op = &erofs_skip_write_bhops;
mkfs/main.c +1 -1
index b7129eb..1027fc6 100644
@@ -274,7 +274,7 @@ static int erofs_mkfs_feat_set_fragments(bool en, 
 const char *val,
           u64 i = strtoull(val, &endptr, 0);
             if (endptr - val != vallen) {
-            erofs_err("invalid pcluster size %s for the packed file 
 %s", val);
+            erofs_err("invalid pcluster size %s for the packed 
 file", val);
               return -EINVAL;

          }
          pclustersize_packed = i;