btrfs: Use NAME_MAX to replace intermediate number of BTRFS_NAME_LEN
PATCH 1/2 btrfs: Use NAME_MAX to replace intermediate number of BTRFS_NAME_LEN
Since we're following the name size limit of linux, just use NAME_MAX.
--- fs/btrfs/ctree.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/ctree.h +1 -1
@@ -65,7 +65,7 @@ struct btrfs_ordered_sum;* we can actually store much bigger names, but lets not confuse the rest * of linux */ -#define BTRFS_NAME_LEN 255 +#define BTRFS_NAME_LEN NAME_MAX/* * Theoretical limit is larger, but we keep this down to a sane
Signature · 1 line
2.19.0
PATCH 2/2 btrfs: tree-checker: Avoid using max() for stack array allocation
Although BTRFS_NAME_LEN and XATTR_NAME_MAX is the same value (255), max(BTRFS_NAME_LEN, XATTR_NAME_MAX) should be optimized as const at runtime.
However S390x' arch dependent option "-mwarn-dynamicstack" could still report it as dyanamic stack allocation.
Just use BTRFS_NAME_LEN directly to avoid such false alert.
--- fs/btrfs/tree-checker.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/tree-checker.c +1 -1
@@ -336,7 +336,7 @@ static int check_dir_item(struct btrfs_fs_info *fs_info,*/ if (key->type ==BTRFS_DIR_ITEM_KEY || key->type ==BTRFS_XATTR_ITEM_KEY ) { -char namebuf[max (BTRFS_NAME_LEN ,XATTR_NAME_MAX )]; +char namebuf[BTRFS_NAME_LEN ];read_extent_buffer (leaf, namebuf, (unsigned long )(di +1 ), name_len);
Signature · 1 line
2.19.0
Re: [PATCH 2/2] btrfs: tree-checker: Avoid using max() for stack array allocation
Quoted 8 lines · Qu Wenruo
Although
BTRFS_NAME_LENandXATTR_NAME_MAXis the same value (255),max(BTRFS_NAME_LEN, XATTR_NAME_MAX)should be optimized as const at runtime.However S390x' arch dependent option "-mwarn-dynamicstack" could still report it as dyanamic stack allocation.
Just use
BTRFS_NAME_LENdirectly to avoid such false alert.
Same reasoning as for the NAME_MAX, these are different things.
Quoted 10 lines
Signed-off-by Qu Wenruo <[email protected]>--- fs/btrfs/tree-checker.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/btrfs/tree-checker.c +0
-0
fs/btrfs/tree-checker.c static int check_dir_item(struct btrfs_fs_info *fs_info, · line 339
Quoted 5 lines
fs/btrfs/tree-checker.c +1
-1@@ -336,7 +336,7 @@ static int check_dir_item(struct btrfs_fs_info *fs_info,*/ if (key->type ==BTRFS_DIR_ITEM_KEY || key->type ==BTRFS_XATTR_ITEM_KEY ) { -char namebuf[max (BTRFS_NAME_LEN ,XATTR_NAME_MAX )]; +char namebuf[BTRFS_NAME_LEN ];
The updated implementation of max() can now handle the expression without a warning, with sufficiently new compiler so I don't think we need to fix that.
Alternatively, you could use BTRFS_NAME_LEN and add a BUILD_BUG_ON(BTRFS_NAME_LEN < XATTR_NAME_MAX) with a comment why.
Quoted 5 lines
fs/btrfs/tree-checker.c +0
-0read_extent_buffer (leaf, namebuf, (unsigned long )(di +1 ), name_len);Signature · 1 line
2.19.0
Re: [PATCH 2/2] btrfs: tree-checker: Avoid using max() for stack array allocation
Quoted 17 lines · David Sterba
Quoted 8 lines · Qu Wenruo
Although
BTRFS_NAME_LENandXATTR_NAME_MAXis the same value (255),max(BTRFS_NAME_LEN, XATTR_NAME_MAX)should be optimized as const at runtime.However S390x' arch dependent option "-mwarn-dynamicstack" could still report it as dyanamic stack allocation.
Just use
BTRFS_NAME_LENdirectly to avoid such false alert.Same reasoning as for the
NAME_MAX, these are different things.Quoted 5 lines
Signed-off-by Qu Wenruo <[email protected]>--- fs/btrfs/tree-checker.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines
fs/btrfs/tree-checker.c static int check_dir_item(struct btrfs_fs_info *fs_info, · line 339
Quoted 10 lines
fs/btrfs/tree-checker.c +1
-1@@ -336,7 +336,7 @@ static int check_dir_item(struct btrfs_fs_info *fs_info,*/ if (key->type ==BTRFS_DIR_ITEM_KEY || key->type ==BTRFS_XATTR_ITEM_KEY ) { -char namebuf[max (BTRFS_NAME_LEN ,XATTR_NAME_MAX )]; +char namebuf[BTRFS_NAME_LEN ];The updated implementation of
max()can now handle the expression without a warning, with sufficiently new compiler so I don't think we need to fix that.
Yes, it's mostly a workaround to make S390 happy.
And if it can be fixed by kernel config/compiler, it doesn't make much sense to fix it here.
So please discard these 2 patches.
Thanks,
Qu
Quoted 9 lines
Alternatively, you could use
BTRFS_NAME_LENand add aBUILD_BUG_ON(BTRFS_NAME_LEN < XATTR_NAME_MAX)with a comment why.Quoted 5 lines
fs/btrfs/tree-checker.c +0
-0read_extent_buffer (leaf, namebuf, (unsigned long )(di +1 ), name_len);Signature · 1 line
2.19.0
Quoted 3 lines · Qu Wenruo
Since we're following the name size limit of linux, just use
NAME_MAX.Signed-off-by Qu Wenruo <[email protected]>
Quoted 18 lines
--- fs/btrfs/ctree.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/btrfs/ctree.h +1
-1@@ -65,7 +65,7 @@ struct btrfs_ordered_sum;* we can actually store much bigger names, but lets not confuse the rest * of linux */ -#define BTRFS_NAME_LEN 255 +#define BTRFS_NAME_LEN NAME_MAX/* * Theoretical limit is larger, but we keep this down to a sane
Quoted 12 lines · Qu Wenruo
Since we're following the name size limit of linux, just use
NAME_MAX.Signed-off-by Qu Wenruo <[email protected]>--- fs/btrfs/ctree.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/btrfs/ctree.h +0
-0
fs/btrfs/ctree.h struct btrfs_ordered_sum; · line 68
Quoted 5 lines
fs/btrfs/ctree.h +1
-1@@ -65,7 +65,7 @@ struct btrfs_ordered_sum;* we can actually store much bigger names, but lets not confuse the rest * of linux */ -#define BTRFS_NAME_LEN 255 +#define BTRFS_NAME_LEN NAME_MAX
While the values are the same, the symbolic names have a slightly different meaning. NAME_MAX is from the public API, BTRFS_NAME_LEN is defined as btrfs limit, and de facto part of the on-disk format. These are independent, although compatible for all practical purposes. I would not conflate the two in the define, the comment could be updated to document that better though.