fs/ocfs2/xattr.c:643:5-8: Unneeded variable: "ret". Return "0" on line 665
Subsystems (2)
kernel test robot
build bottree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: 8ab1afb2eb246ab15b301cd255b5943d208a93c1 commit: bd7c05fb4a4776dff5a87b19008d28458647d15d ocfs2: fix circular locking dependency in ocfs2_init_acl() date: 3 weeks ago config: riscv-randconfig-r052-20260903 (https://download.01.org/0day-ci/archive/20260904/[email protected]/config) compiler: riscv64-linux-gcc (GCC) 8.5.0
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Fixes: bd7c05fb4a47 ("ocfs2: fix circular locking dependency in ocfs2_init_acl()")
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/cocci warnings: (new ones prefixed by >>)
>> fs/ocfs2/xattr.c:643:5-8: Unneeded variable: "ret". Return "0" on line 665
vim +643 fs/ocfs2/xattr.c
534eadddc1de87 Tiger Yang 2008-11-14 637
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 638 int ocfs2_calc_xattr_init(struct inode *dir, umode_t mode,
89c38bd0ade3c5 Tiger Yang 2008-11-14 639 struct ocfs2_security_xattr_info *si,
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 640 int *want_clusters, int *xattr_credits,
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 641 int *want_meta, struct ocfs2_acl_state *acl_state)
89c38bd0ade3c5 Tiger Yang 2008-11-14 642 {
89c38bd0ade3c5 Tiger Yang 2008-11-14 @643 int ret = 0;
89c38bd0ade3c5 Tiger Yang 2008-11-14 644 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
0e445b6fe93c72 Tiger Yang 2008-12-09 645 int s_size = 0, a_size = 0, acl_len = 0, new_clusters;
89c38bd0ade3c5 Tiger Yang 2008-11-14 646
89c38bd0ade3c5 Tiger Yang 2008-11-14 647 if (si->enable)
89c38bd0ade3c5 Tiger Yang 2008-11-14 648 s_size = ocfs2_xattr_entry_real_size(strlen(si->name),
89c38bd0ade3c5 Tiger Yang 2008-11-14 649 si->value_len);
89c38bd0ade3c5 Tiger Yang 2008-11-14 650
89c38bd0ade3c5 Tiger Yang 2008-11-14 651 if (osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) {
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 652 if (acl_state->default_acl && S_ISDIR(mode)) {
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 653 acl_len = acl_state->default_acl->a_count *
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 654 sizeof(struct ocfs2_acl_entry);
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 655 a_size += ocfs2_xattr_entry_real_size(0, acl_len);
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 656 }
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 657 if (acl_state->acl) {
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 658 acl_len = acl_state->acl->a_count *
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 659 sizeof(struct ocfs2_acl_entry);
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 660 a_size += ocfs2_xattr_entry_real_size(0, acl_len);
89c38bd0ade3c5 Tiger Yang 2008-11-14 661 }
89c38bd0ade3c5 Tiger Yang 2008-11-14 662 }
89c38bd0ade3c5 Tiger Yang 2008-11-14 663
89c38bd0ade3c5 Tiger Yang 2008-11-14 664 if (!(s_size + a_size))
89c38bd0ade3c5 Tiger Yang 2008-11-14 @665 return ret;
89c38bd0ade3c5 Tiger Yang 2008-11-14 666
89c38bd0ade3c5 Tiger Yang 2008-11-14 667 /*
89c38bd0ade3c5 Tiger Yang 2008-11-14 668 * The max space of security xattr taken inline is
89c38bd0ade3c5 Tiger Yang 2008-11-14 669 * 256(name) + 80(value) + 16(entry) = 352 bytes,
89c38bd0ade3c5 Tiger Yang 2008-11-14 670 * The max space of acl xattr taken inline is
89c38bd0ade3c5 Tiger Yang 2008-11-14 671 * 80(value) + 16(entry) * 2(if directory) = 192 bytes,
a0f8a9a9636e19 Dmitry Antipov 2024-11-15 672 * when blocksize = 512, may reserve one more cluster for
89c38bd0ade3c5 Tiger Yang 2008-11-14 673 * xattr bucket, otherwise reserve one metadata block
89c38bd0ade3c5 Tiger Yang 2008-11-14 674 * for them is ok.
6c9fd1dc0a597e Tiger Yang 2009-03-06 675 * If this is a new directory with inline data,
6c9fd1dc0a597e Tiger Yang 2009-03-06 676 * we choose to reserve the entire inline area for
6c9fd1dc0a597e Tiger Yang 2009-03-06 677 * directory contents and force an external xattr block.
89c38bd0ade3c5 Tiger Yang 2008-11-14 678 */
89c38bd0ade3c5 Tiger Yang 2008-11-14 679 if (dir->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE ||
6c9fd1dc0a597e Tiger Yang 2009-03-06 680 (S_ISDIR(mode) && ocfs2_supports_inline_data(osb)) ||
89c38bd0ade3c5 Tiger Yang 2008-11-14 681 (s_size + a_size) > OCFS2_XATTR_FREE_IN_IBODY) {
9b7895efac906d Mark Fasheh 2008-11-12 682 *want_meta = *want_meta + 1;
89c38bd0ade3c5 Tiger Yang 2008-11-14 683 *xattr_credits += OCFS2_XATTR_BLOCK_CREATE_CREDITS;
89c38bd0ade3c5 Tiger Yang 2008-11-14 684 }
89c38bd0ade3c5 Tiger Yang 2008-11-14 685
89c38bd0ade3c5 Tiger Yang 2008-11-14 686 if (dir->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE &&
89c38bd0ade3c5 Tiger Yang 2008-11-14 687 (s_size + a_size) > OCFS2_XATTR_FREE_IN_BLOCK(dir)) {
89c38bd0ade3c5 Tiger Yang 2008-11-14 688 *want_clusters += 1;
89c38bd0ade3c5 Tiger Yang 2008-11-14 689 *xattr_credits += ocfs2_blocks_per_xattr_bucket(dir->i_sb);
89c38bd0ade3c5 Tiger Yang 2008-11-14 690 }
89c38bd0ade3c5 Tiger Yang 2008-11-14 691
0e445b6fe93c72 Tiger Yang 2008-12-09 692 /*
0e445b6fe93c72 Tiger Yang 2008-12-09 693 * reserve credits and clusters for xattrs which has large value
0e445b6fe93c72 Tiger Yang 2008-12-09 694 * and have to be set outside
0e445b6fe93c72 Tiger Yang 2008-12-09 695 */
0e445b6fe93c72 Tiger Yang 2008-12-09 696 if (si->enable && si->value_len > OCFS2_XATTR_INLINE_SIZE) {
0e445b6fe93c72 Tiger Yang 2008-12-09 697 new_clusters = ocfs2_clusters_for_bytes(dir->i_sb,
89c38bd0ade3c5 Tiger Yang 2008-11-14 698 si->value_len);
0e445b6fe93c72 Tiger Yang 2008-12-09 699 *xattr_credits += ocfs2_clusters_to_blocks(dir->i_sb,
0e445b6fe93c72 Tiger Yang 2008-12-09 700 new_clusters);
0e445b6fe93c72 Tiger Yang 2008-12-09 701 *want_clusters += new_clusters;
0e445b6fe93c72 Tiger Yang 2008-12-09 702 }
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 703 if (osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) {
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 704 if (acl_state->default_acl && S_ISDIR(mode)) {
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 705 acl_len = acl_state->default_acl->a_count *
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 706 sizeof(struct ocfs2_acl_entry);
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 707 if (acl_len > OCFS2_XATTR_INLINE_SIZE) {
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 708 new_clusters =
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 709 ocfs2_clusters_for_bytes(dir->i_sb,
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 710 acl_len);
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 711 *xattr_credits +=
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 712 ocfs2_clusters_to_blocks(dir->i_sb,
0e445b6fe93c72 Tiger Yang 2008-12-09 713 new_clusters);
0e445b6fe93c72 Tiger Yang 2008-12-09 714 *want_clusters += new_clusters;
89c38bd0ade3c5 Tiger Yang 2008-11-14 715 }
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 716 }
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 717 if (acl_state->acl) {
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 718 acl_len = acl_state->acl->a_count *
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 719 sizeof(struct ocfs2_acl_entry);
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 720 if (acl_len > OCFS2_XATTR_INLINE_SIZE) {
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 721 new_clusters =
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 722 ocfs2_clusters_for_bytes(dir->i_sb,
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 723 acl_len);
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 724 *xattr_credits +=
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 725 ocfs2_clusters_to_blocks(dir->i_sb,
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 726 new_clusters);
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 727 *want_clusters += new_clusters;
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 728 }
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 729 }
bd7c05fb4a4776 Krystian Kaniewski 2026-07-30 730 }
89c38bd0ade3c5 Tiger Yang 2008-11-14 731
89c38bd0ade3c5 Tiger Yang 2008-11-14 732 return ret;
89c38bd0ade3c5 Tiger Yang 2008-11-14 733 }
89c38bd0ade3c5 Tiger Yang 2008-11-14 734 :::::: The code at line 643 was first introduced by commit
:::::: 89c38bd0ade3c567707ed8fce088b253b0369c50 ocfs2: add ocfs2_init_acl in mknod
:::::: TO: Tiger Yang <[email protected]>
:::::: CC: Mark Fasheh <[email protected]>
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
PATCH 1/1 ocfs2: remove unnecessary ret variable in ocfs2_calc_xattr_init()
Commit bd7c05fb4a47 ("ocfs2: fix circular locking dependency in ocfs2_init_acl()") removed the only code that could change ret in ocfs2_calc_xattr_init(). The variable is now always zero, so remove it and return zero directly.
This fixes the reported Coccinelle warning without changing behavior.
--- fs/ocfs2/xattr.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fs/ocfs2/xattr.c +2 -3
@@ -640,7 +640,6 @@ int ocfs2_calc_xattr_init(struct inode *dir, umode_t mode, int *want_clusters, int *xattr_credits, int *want_meta, struct ocfs2_acl_state *acl_state) { - int ret = 0; struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);int s_size =0 , a_size =0 , acl_len =0 , new_clusters;
@@ -662,7 +661,7 @@ int ocfs2_calc_xattr_init(struct inode *dir, umode_t mode, }if (!(s_size + a_size)) -return ret; +return 0 ;/* * The max space of security xattr taken inline is
@@ -729,7 +728,7 @@ int ocfs2_calc_xattr_init(struct inode *dir, umode_t mode, } } -return ret; +return 0 ; } static int ocfs2_xattr_extend_allocation(struct inode *inode,
base-commit: bc35965f6940a9bf834d54187b6088b8eb09206d
Signature · 1 line
2.53.0
Joseph Qi
maintainerRe: [PATCH] ocfs2: remove unnecessary ret variable in ocfs2_calc_xattr_init()
Hi,
This has already been addressed by:ed57836ff300 ocfs2: make ocfs2_calc_xattr_init() return void
Thanks,
Joseph
Quoted 47 lines · Krystian Kaniewski
Commit
bd7c05fb4a47("ocfs2: fix circular locking dependency inocfs2_init_acl()") removed the only code that could change ret inocfs2_calc_xattr_init(). The variable is now always zero, so remove it and return zero directly.This fixes the reported Coccinelle warning without changing behavior.
Fixes bd7c05fb4a47 ("ocfs2: fix circular locking dependency in ocfs2_init_acl()")Reported-by kernel test robot <[email protected]>Signed-off-by Krystian Kaniewski <[email protected]>--- fs/ocfs2/xattr.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)fs/ocfs2/xattr.c +2
-3@@ -640,7 +640,6 @@ int ocfs2_calc_xattr_init(struct inode *dir, umode_t mode, int *want_clusters, int *xattr_credits, int *want_meta, struct ocfs2_acl_state *acl_state) { - int ret = 0; struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);int s_size =0 , a_size =0 , acl_len =0 , new_clusters;@@ -662,7 +661,7 @@ int ocfs2_calc_xattr_init(struct inode *dir, umode_t mode, }if (!(s_size + a_size)) -return ret; +return 0 ;/* * The max space of security xattr taken inline is @@ -729,7 +728,7 @@ int ocfs2_calc_xattr_init(struct inode *dir, umode_t mode, } } -return ret; +return 0 ; } static int ocfs2_xattr_extend_allocation(struct inode *inode,base-commit:
bc35965f6940a9bf834d54187b6088b8eb09206d
Re: [PATCH] ocfs2: remove unnecessary ret variable in ocfs2_calc_xattr_init()
Hey Joseph,
Thanks for letting me know and let's drop this patch then. I've just received an email a few days ago after my patch was applied to upstream Linux and there was this finding, however I didn't expect it's already addressed.
Quoted 55 lines · Joseph Qi
Hi,
This has already been addressed by:ed57836ff300ocfs2: makeocfs2_calc_xattr_init()return voidThanks,
JosephQuoted 47 lines · Krystian Kaniewski
Commit
bd7c05fb4a47("ocfs2: fix circular locking dependency inocfs2_init_acl()") removed the only code that could change ret inocfs2_calc_xattr_init(). The variable is now always zero, so remove it and return zero directly.This fixes the reported Coccinelle warning without changing behavior.
Fixes bd7c05fb4a47 ("ocfs2: fix circular locking dependency in ocfs2_init_acl()")Reported-by kernel test robot <[email protected]>Signed-off-by Krystian Kaniewski <[email protected]>--- fs/ocfs2/xattr.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)fs/ocfs2/xattr.c +2
-3@@ -640,7 +640,6 @@ int ocfs2_calc_xattr_init(struct inode *dir, umode_t mode, int *want_clusters, int *xattr_credits, int *want_meta, struct ocfs2_acl_state *acl_state) { - int ret = 0; struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);int s_size =0 , a_size =0 , acl_len =0 , new_clusters;@@ -662,7 +661,7 @@ int ocfs2_calc_xattr_init(struct inode *dir, umode_t mode, }if (!(s_size + a_size)) -return ret; +return 0 ;/* * The max space of security xattr taken inline is @@ -729,7 +728,7 @@ int ocfs2_calc_xattr_init(struct inode *dir, umode_t mode, } } -return ret; +return 0 ; } static int ocfs2_xattr_extend_allocation(struct inode *inode,base-commit:
bc35965f6940a9bf834d54187b6088b8eb09206d