Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ocfs2: avoid extra calls to strlen() after ocfs2_sprintf_system_inode_name()

Since 'ocfs2_sprintf_system_inode_name()' uses 'snprintf()' and returns
the number of characters emitted, callers of the former are better to use
that return value instead of an explicit calls to 'strlen()'.

Link: https://lkml.kernel.org/r/20250917060229.1854335-1-dmantipov@yandex.ru
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Reviewed-by: Joel Becker <jlbec@evilplan.org>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Jun Piao <piaojun@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Dmitry Antipov and committed by
Andrew Morton
3437819c a15f37a4

+17 -21
+7 -11
fs/ocfs2/ioctl.c
··· 358 358 goto bail; 359 359 } 360 360 } else { 361 - ocfs2_sprintf_system_inode_name(namebuf, 362 - sizeof(namebuf), 363 - type, i); 361 + int len = ocfs2_sprintf_system_inode_name(namebuf, 362 + sizeof(namebuf), 363 + type, i); 364 364 status = ocfs2_lookup_ino_from_name(osb->sys_root_inode, 365 - namebuf, 366 - strlen(namebuf), 367 - &blkno); 365 + namebuf, len, &blkno); 368 366 if (status < 0) { 369 367 status = -ENOENT; 370 368 goto bail; ··· 649 651 goto bail; 650 652 } 651 653 } else { 652 - ocfs2_sprintf_system_inode_name(namebuf, sizeof(namebuf), type, 653 - OCFS2_INVALID_SLOT); 654 + int len = ocfs2_sprintf_system_inode_name(namebuf, sizeof(namebuf), 655 + type, OCFS2_INVALID_SLOT); 654 656 status = ocfs2_lookup_ino_from_name(osb->sys_root_inode, 655 - namebuf, 656 - strlen(namebuf), 657 - &blkno); 657 + namebuf, len, &blkno); 658 658 if (status < 0) { 659 659 status = -ENOENT; 660 660 goto bail;
+4 -4
fs/ocfs2/move_extents.c
··· 364 364 int *vict_bit, 365 365 struct buffer_head **ret_bh) 366 366 { 367 - int ret, i, bits_per_unit = 0; 367 + int ret, i, len, bits_per_unit = 0; 368 368 u64 blkno; 369 369 char namebuf[40]; 370 370 ··· 375 375 struct ocfs2_dinode *ac_dinode; 376 376 struct ocfs2_group_desc *bg; 377 377 378 - ocfs2_sprintf_system_inode_name(namebuf, sizeof(namebuf), type, slot); 379 - ret = ocfs2_lookup_ino_from_name(osb->sys_root_inode, namebuf, 380 - strlen(namebuf), &blkno); 378 + len = ocfs2_sprintf_system_inode_name(namebuf, sizeof(namebuf), type, slot); 379 + ret = ocfs2_lookup_ino_from_name(osb->sys_root_inode, namebuf, len, &blkno); 380 + 381 381 if (ret) { 382 382 ret = -ENOENT; 383 383 goto out;
+6 -6
fs/ocfs2/sysfile.c
··· 127 127 char namebuf[40]; 128 128 struct inode *inode = NULL; 129 129 u64 blkno; 130 - int status = 0; 130 + int len, status = 0; 131 131 132 - ocfs2_sprintf_system_inode_name(namebuf, 133 - sizeof(namebuf), 134 - type, slot); 132 + len = ocfs2_sprintf_system_inode_name(namebuf, 133 + sizeof(namebuf), 134 + type, slot); 135 135 136 - status = ocfs2_lookup_ino_from_name(osb->sys_root_inode, namebuf, 137 - strlen(namebuf), &blkno); 136 + status = ocfs2_lookup_ino_from_name(osb->sys_root_inode, 137 + namebuf, len, &blkno); 138 138 if (status < 0) { 139 139 goto bail; 140 140 }