Remove some BUG_ONs
David Sterba
maintainercover Remove some BUG_ONs
Minor cleanup in the BUG_ONs, where could be either removed or replaced by proper error handling where the call chain is ready for that. For 4.11.
David Sterba (3):
btrfs: remove BUG_ON from __tree_mod_log_insert
btrfs: handle allocation error in update_dev_stat_item
btrfs: do proper error handling in btrfs_insert_xattr_item
fs/btrfs/ctree.c | 2 -- fs/btrfs/dir-item.c | 3 ++- fs/btrfs/volumes.c | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-)
David Sterba
maintainerPATCH 1/3 btrfs: remove BUG_ON from __tree_mod_log_insert
All callers dereference the 'tm' parameter before it gets to this function, the NULL check does not make much sense here.
--- fs/btrfs/ctree.c | 2 -- 1 file changed, 2 deletions(-)
fs/btrfs/ctree.c +0 -2
@@ -453,8 +453,6 @@ __tree_mod_log_insert(struct btrfs_fs_info *fs_info, struct tree_mod_elem *tm)struct rb_node *parent =NULL ;struct tree_mod_elem *cur; -BUG_ON (!tm); - tm->seq =btrfs_inc_tree_mod_seq (fs_info); tm_root = &fs_info->tree_mod_log;
Signature · 1 line
2.10.1
David Sterba
maintainerPATCH 2/3 btrfs: handle allocation error in update_dev_stat_item
In reply to David Sterba--- fs/btrfs/volumes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/volumes.c +2 -1
@@ -6954,7 +6954,8 @@ static int update_dev_stat_item(struct btrfs_trans_handle *trans, key.offset = device->devid; path =btrfs_alloc_path (); -BUG_ON (!path); +if (!path) +return -ENOMEM ; ret =btrfs_search_slot (trans, dev_root, &key, path,-1 ,1 );if (ret <0 ) { btrfs_warn_in_rcu(fs_info,
Signature · 1 line
2.10.1
David Sterba
maintainerPATCH 3/3 btrfs: do proper error handling in btrfs_insert_xattr_item
In reply to David SterbaThe space check in btrfs_insert_xattr_item is duplicated in it's caller (do_setxattr) so we won't hit the BUG_ON. Continuing without any check could be disasterous so turn it to a proper error handling.
--- fs/btrfs/dir-item.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/dir-item.c +2 -1
@@ -80,7 +80,8 @@ int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,struct extent_buffer *leaf;u32 data_size; -BUG_ON (name_len + data_len >BTRFS_MAX_XATTR_SIZE (root->fs_info)); +if (name_len + data_len >BTRFS_MAX_XATTR_SIZE (root->fs_info)) +return -ENOSPC ; key.objectid = objectid; key.type =BTRFS_XATTR_ITEM_KEY ;
Signature · 1 line
2.10.1
Re: [PATCH 1/3] btrfs: remove BUG_ON from __tree_mod_log_insert
In reply to David SterbaQuoted 2 lines · David Sterba
All callers dereference the 'tm' parameter before it gets to this function, the NULL check does not make much sense here.
Thanks,
-liubo
Quoted 26 lines
Signed-off-by David Sterba <[email protected]>--- fs/btrfs/ctree.c | 2 -- 1 file changed, 2 deletions(-)fs/btrfs/ctree.c +0
-2@@ -453,8 +453,6 @@ __tree_mod_log_insert(struct btrfs_fs_info *fs_info, struct tree_mod_elem *tm)struct rb_node *parent =NULL ;struct tree_mod_elem *cur; -BUG_ON (!tm); - tm->seq =btrfs_inc_tree_mod_seq (fs_info); tm_root = &fs_info->tree_mod_log;Signature · 6 lines
2.10.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/3] btrfs: handle allocation error in update_dev_stat_item
In reply to David SterbaQuoted 10 lines · David Sterba
Signed-off-by David Sterba <[email protected]>--- fs/btrfs/volumes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/btrfs/volumes.c +0
-0
fs/btrfs/volumes.c static int update_dev_stat_item(struct btrfs_trans_handle *trans, · line 6961
Quoted 9 lines
fs/btrfs/volumes.c +2
-1@@ -6954,7 +6954,8 @@ static int update_dev_stat_item(struct btrfs_trans_handle *trans, key.offset = device->devid; path =btrfs_alloc_path (); -BUG_ON (!path); +if (!path) +return -ENOMEM ; ret =btrfs_search_slot (trans, dev_root, &key, path,-1 ,1 );if (ret <0 ) { btrfs_warn_in_rcu(fs_info,
Thanks,
-liubo
Quoted 7 lines
Signature · 6 lines
2.10.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] btrfs: do proper error handling in btrfs_insert_xattr_item
In reply to David SterbaQuoted 14 lines · David Sterba
The space check in
btrfs_insert_xattr_itemis duplicated in it's caller (do_setxattr) so we won't hit theBUG_ON. Continuing without any check could be disasterous so turn it to a proper error handling.Signed-off-by David Sterba <[email protected]>--- fs/btrfs/dir-item.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/btrfs/dir-item.c +0
-0
fs/btrfs/dir-item.c int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans, · line 85
Quoted 7 lines
fs/btrfs/dir-item.c +2
-1@@ -80,7 +80,8 @@ int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,struct extent_buffer *leaf;u32 data_size; -BUG_ON (name_len + data_len >BTRFS_MAX_XATTR_SIZE (root->fs_info)); +if (name_len + data_len >BTRFS_MAX_XATTR_SIZE (root->fs_info)) +return -ENOSPC ;
Besides making it silent, how about adding a ASSERT to cry out? (Although currently we'd never come into this case.)
Thanks,
-liubo
Quoted 9 lines
fs/btrfs/dir-item.c +0
-0key.objectid = objectid; key.type =BTRFS_XATTR_ITEM_KEY ;Signature · 6 lines
2.10.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] btrfs: do proper error handling in btrfs_insert_xattr_item
Quoted 18 lines · Liu Bo
Quoted 17 lines · David Sterba
The space check in
btrfs_insert_xattr_itemis duplicated in it's caller (do_setxattr) so we won't hit theBUG_ON. Continuing without any check could be disasterous so turn it to a proper error handling.Signed-off-by David Sterba <[email protected]>--- fs/btrfs/dir-item.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/btrfs/dir-item.c +0
-0@@ -80,7 +80,8 @@ int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,struct extent_buffer *leaf;u32 data_size;
Quoted 7 lines
fs/btrfs/dir-item.c int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans, · line 85
Quoted 4 lines
fs/btrfs/dir-item.c +2
-1-BUG_ON (name_len + data_len >BTRFS_MAX_XATTR_SIZE (root->fs_info)); +if (name_len + data_len >BTRFS_MAX_XATTR_SIZE (root->fs_info)) +return -ENOSPC ;Besides making it silent, how about adding a ASSERT to cry out? (Although currently we'd never come into this case.)
I don't think we need the assert, the caller is supposed to handle the error. In this case it's validation of input parameters, that could possibly happen as the function is not static.