diff mbox series

btrfs: fix kvcalloc() arguments order

Message ID 20231221084748.10094-1-dmantipov@yandex.ru (mailing list archive)
State New, archived
Headers show
Series btrfs: fix kvcalloc() arguments order | expand

Commit Message

Dmitry Antipov Dec. 21, 2023, 8:47 a.m. UTC
When compiling with gcc version 14.0.0 20231220 (experimental)
and W=1, I've noticed the following warning:

fs/btrfs/send.c: In function 'btrfs_ioctl_send':
fs/btrfs/send.c:8208:44: warning: 'kvcalloc' sizes specified with 'sizeof'
in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
 8208 |         sctx->clone_roots = kvcalloc(sizeof(*sctx->clone_roots),
      |                                            ^

Since 'n' and 'size' arguments of 'kvcalloc()' are multiplied to
calculate the final size, their actual order doesn't affect the
result and so this is not a bug. But it's still worth to fix it.

Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
 fs/btrfs/send.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

David Sterba Jan. 4, 2024, 3:47 p.m. UTC | #1
On Thu, Dec 21, 2023 at 11:47:45AM +0300, Dmitry Antipov wrote:
> When compiling with gcc version 14.0.0 20231220 (experimental)
> and W=1, I've noticed the following warning:
> 
> fs/btrfs/send.c: In function 'btrfs_ioctl_send':
> fs/btrfs/send.c:8208:44: warning: 'kvcalloc' sizes specified with 'sizeof'
> in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
>  8208 |         sctx->clone_roots = kvcalloc(sizeof(*sctx->clone_roots),
>       |                                            ^
> 
> Since 'n' and 'size' arguments of 'kvcalloc()' are multiplied to
> calculate the final size, their actual order doesn't affect the
> result and so this is not a bug. But it's still worth to fix it.
> 
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>

Added to misc-next, thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index 4e36550618e5..2d7519a6ce72 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -8205,8 +8205,8 @@  long btrfs_ioctl_send(struct inode *inode, struct btrfs_ioctl_send_args *arg)
 		goto out;
 	}
 
-	sctx->clone_roots = kvcalloc(sizeof(*sctx->clone_roots),
-				     arg->clone_sources_count + 1,
+	sctx->clone_roots = kvcalloc(arg->clone_sources_count + 1,
+				     sizeof(*sctx->clone_roots),
 				     GFP_KERNEL);
 	if (!sctx->clone_roots) {
 		ret = -ENOMEM;