]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: send: avoid extra calls to strlen() in gen_unique_name()
authorDmitry Antipov <dmantipov@yandex.ru>
Fri, 27 Jun 2025 08:51:17 +0000 (11:51 +0300)
committerDavid Sterba <dsterba@suse.com>
Mon, 21 Jul 2025 21:58:05 +0000 (23:58 +0200)
Since 'snprintf()' returns the number of characters which would
be emitted and output truncation is handled by 'ASSERT()', it
should be safe to use that return value instead of the subsequent
calls to 'strlen()' in 'gen_unique_name()'.

This also reduces the module's text size.

Before:

  $ size fs/btrfs/btrfs.ko
     text    data     bss     dec     hex filename
  1897006  161571   16136 2074713  1fa859 fs/btrfs/btrfs.ko

After:

  $ size fs/btrfs/btrfs.ko
     text    data     bss     dec     hex filename
  1896848  161571   16136 2074555  1fa7bb fs/btrfs/btrfs.ko

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/send.c

index 2891ec4056c65b55a393c85058c8e0654305f6c7..a045c1be49baf9e5e960c712c9a24cde773e9522 100644 (file)
@@ -1804,7 +1804,7 @@ static int gen_unique_name(struct send_ctx *sctx,
                                ino, gen, idx);
                ASSERT(len < sizeof(tmp));
                tmp_name.name = tmp;
-               tmp_name.len = strlen(tmp);
+               tmp_name.len = len;
 
                di = btrfs_lookup_dir_item(NULL, sctx->send_root,
                                path, BTRFS_FIRST_FREE_OBJECTID,
@@ -1843,7 +1843,7 @@ static int gen_unique_name(struct send_ctx *sctx,
                break;
        }
 
-       ret = fs_path_add(dest, tmp, strlen(tmp));
+       ret = fs_path_add(dest, tmp, len);
 
 out:
        btrfs_free_path(path);