mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daeho Jeong <daeho43@gmail.com>
To: linux-kernel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com
Cc: Daeho Jeong <daehojeong@google.com>
Subject: [PATCH] f2fs-tools: fix calloc() calls with transposed arguments
Date: Tue, 17 Nov 2026 12:40:10 -0800	[thread overview]
Message-ID: <20261117204010.1742691-1-daeho43@gmail.com> (raw)

From: Daeho Jeong <daehojeong@google.com>

GCC 14 and later warn about a calloc() call that has sizeof() in the
first argument and not in the second one, and the CI builds with
-Wextra -Werror:

  libf2fs.c: In function 'utf8_to_utf16':
  libf2fs.c:127:47: error: 'calloc' sizes specified with 'sizeof' in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
    127 |         uint16_t *volume_name = calloc(sizeof(uint16_t), MAX_VOLUME_NAME);
        |                                               ^~~~~~~~
  libf2fs.c:127:47: note: earlier argument should specify number of elements, later size of each element

Pass the number of elements first and the size of an element second in
all the calls that the compiler reports. No functional change.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
---
 fsck/fsck.c        | 8 ++++----
 fsck/mount.c       | 6 +++---
 lib/libf2fs.c      | 4 ++--
 mkfs/f2fs_format.c | 4 ++--
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/fsck/fsck.c b/fsck/fsck.c
index a56c16b..56d4744 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -95,7 +95,7 @@ static int add_into_hard_link_list(struct f2fs_sb_info *sbi,
 	struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
 	struct hard_link_node *node = NULL, *tmp = NULL, *prev = NULL;
 
-	node = calloc(sizeof(struct hard_link_node), 1);
+	node = calloc(1, sizeof(struct hard_link_node));
 	ASSERT(node != NULL);
 
 	node->nid = nid;
@@ -2119,7 +2119,7 @@ int fsck_chk_inline_dentries(struct f2fs_sb_info *sbi,
 	make_dentry_ptr(&d, node_blk, inline_dentry, 2);
 
 	fsck->dentry_depth++;
-	new_dentry = calloc(sizeof(struct f2fs_dentry), 1);
+	new_dentry = calloc(1, sizeof(struct f2fs_dentry));
 	ASSERT(new_dentry != NULL);
 
 	new_dentry->depth = fsck->dentry_depth;
@@ -2164,7 +2164,7 @@ int fsck_chk_dentry_blk(struct f2fs_sb_info *sbi, int casefolded, u32 blk_addr,
 	ASSERT(ret >= 0);
 
 	fsck->dentry_depth++;
-	new_dentry = calloc(sizeof(struct f2fs_dentry), 1);
+	new_dentry = calloc(1, sizeof(struct f2fs_dentry));
 	ASSERT(new_dentry != NULL);
 	new_dentry->depth = fsck->dentry_depth;
 	memcpy(new_dentry->name, child->p_name, F2FS_NAME_LEN);
@@ -2637,7 +2637,7 @@ void fsck_init(struct f2fs_sb_info *sbi)
 	ASSERT(tree_mark_size != 0);
 	tree_mark = calloc(tree_mark_size, 1);
 	ASSERT(tree_mark != NULL);
-	fsck->dentry = calloc(sizeof(struct f2fs_dentry), 1);
+	fsck->dentry = calloc(1, sizeof(struct f2fs_dentry));
 	ASSERT(fsck->dentry != NULL);
 	memcpy(fsck->dentry->name, "/", 1);
 	fsck->dentry_end = fsck->dentry;
diff --git a/fsck/mount.c b/fsck/mount.c
index 98d797e..f4d1363 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -3587,8 +3587,8 @@ void build_nat_area_bitmap(struct f2fs_sb_info *sbi)
 	fsck->nat_area_bitmap = calloc(fsck->nat_area_bitmap_sz, 1);
 	ASSERT(fsck->nat_area_bitmap);
 
-	fsck->entries = calloc(sizeof(struct f2fs_nat_entry),
-					fsck->nr_nat_entries);
+	fsck->entries = calloc(fsck->nr_nat_entries,
+					sizeof(struct f2fs_nat_entry));
 	ASSERT(fsck->entries);
 
 	for (block_off = 0; block_off < nr_nat_blks; block_off++) {
@@ -3763,7 +3763,7 @@ static struct fsync_inode_entry *add_fsync_inode(struct list_head *head,
 {
 	struct fsync_inode_entry *entry;
 
-	entry = calloc(sizeof(struct fsync_inode_entry), 1);
+	entry = calloc(1, sizeof(struct fsync_inode_entry));
 	if (!entry)
 		return NULL;
 	entry->ino = ino;
diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index b23d9c7..307cfcb 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -124,7 +124,7 @@ int utf8_to_utf16(char *output, const char *input, size_t outsize,
 	const char *inp = input;
 	uint16_t *outp;
 	wchar_t wc;
-	uint16_t *volume_name = calloc(sizeof(uint16_t), MAX_VOLUME_NAME);
+	uint16_t *volume_name = calloc(MAX_VOLUME_NAME, sizeof(uint16_t));
 
 	if (!volume_name)
 		return -ENOMEM;
@@ -219,7 +219,7 @@ int utf16_to_utf8(char *output, const char *input, size_t outsize,
 	char *outp = output;
 	wchar_t wc;
 	uint16_t *inp;
-	uint16_t *volume_name = calloc(sizeof(uint16_t), MAX_VOLUME_NAME);
+	uint16_t *volume_name = calloc(MAX_VOLUME_NAME, sizeof(uint16_t));
 
 	if (!volume_name)
 		return -ENOMEM;
diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index 33d3da9..d4a02ee 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -757,7 +757,7 @@ static int f2fs_init_sit_area(void)
 	blk_size = 1 << get_sb(log_blocksize);
 	seg_size = (1 << get_sb(log_blocks_per_seg)) * blk_size;
 
-	zero_buf = calloc(sizeof(uint8_t), seg_size);
+	zero_buf = calloc(seg_size, sizeof(uint8_t));
 	if(zero_buf == NULL) {
 		MSG(1, "\tError: Calloc Failed for sit_zero_buf!!!\n");
 		return -1;
@@ -791,7 +791,7 @@ static int f2fs_init_nat_area(void)
 	blk_size = 1 << get_sb(log_blocksize);
 	seg_size = (1 << get_sb(log_blocks_per_seg)) * blk_size;
 
-	nat_buf = calloc(sizeof(uint8_t), seg_size);
+	nat_buf = calloc(seg_size, sizeof(uint8_t));
 	if (nat_buf == NULL) {
 		MSG(1, "\tError: Calloc Failed for nat_zero_blk!!!\n");
 		return -1;
-- 
2.56.1.703.gf848ed807c-goog


                 reply	other threads:[~2026-11-17 20:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261117204010.1742691-1-daeho43@gmail.com \
    --to=daeho43@gmail.com \
    --cc=daehojeong@google.com \
    --cc=kernel-team@android.com \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®