diff mbox series

[v2,-next] btrfs: Remove unnecessary casts in btrfs_read_root_item

Message ID 20190220123202.43256-1-yuehaibing@huawei.com (mailing list archive)
State New, archived
Headers show
Series [v2,-next] btrfs: Remove unnecessary casts in btrfs_read_root_item | expand

Commit Message

Yue Haibing Feb. 20, 2019, 12:32 p.m. UTC
There is a messy cast here:
	min_t(int, len, (int)sizeof(*item)));

min_t() should normally cast to unsigned.  It's not possible for
"len" to be negative, but if it were then we definitely
wouldn't want to pass negatives to read_extent_buffer().  Also there
is an extra cast.

This patch shouldn't affect runtime, it's just a clean up.

Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
v2: modify commit message as Dan suggested 
---
 fs/btrfs/root-tree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Dan Carpenter Feb. 20, 2019, 12:33 p.m. UTC | #1
On Wed, Feb 20, 2019 at 12:32:02PM +0000, YueHaibing wrote:
> There is a messy cast here:
> 	min_t(int, len, (int)sizeof(*item)));
> 
> min_t() should normally cast to unsigned.  It's not possible for
> "len" to be negative, but if it were then we definitely
> wouldn't want to pass negatives to read_extent_buffer().  Also there
> is an extra cast.
> 
> This patch shouldn't affect runtime, it's just a clean up.
> 
> Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>

It wasn't really suggested by me...  But I do think it's the right
thing.

Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>

regards,
dan carpenter
Qu Wenruo Feb. 20, 2019, 12:36 p.m. UTC | #2
On 2019/2/20 下午8:32, YueHaibing wrote:
> There is a messy cast here:
> 	min_t(int, len, (int)sizeof(*item)));
> 
> min_t() should normally cast to unsigned.  It's not possible for
> "len" to be negative, but if it were then we definitely
> wouldn't want to pass negatives to read_extent_buffer().  Also there
> is an extra cast.
> 
> This patch shouldn't affect runtime, it's just a clean up.
> 
> Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

The commit message is much better.

Thanks,
Qu

> ---
> v2: modify commit message as Dan suggested 
> ---
>  fs/btrfs/root-tree.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
> index 02d1a57af78b..893d12fbfda0 100644
> --- a/fs/btrfs/root-tree.c
> +++ b/fs/btrfs/root-tree.c
> @@ -21,12 +21,12 @@ static void btrfs_read_root_item(struct extent_buffer *eb, int slot,
>  				struct btrfs_root_item *item)
>  {
>  	uuid_le uuid;
> -	int len;
> +	u32 len;
>  	int need_reset = 0;
>  
>  	len = btrfs_item_size_nr(eb, slot);
>  	read_extent_buffer(eb, item, btrfs_item_ptr_offset(eb, slot),
> -			min_t(int, len, (int)sizeof(*item)));
> +			   min_t(u32, len, sizeof(*item)));
>  	if (len < sizeof(*item))
>  		need_reset = 1;
>  	if (!need_reset && btrfs_root_generation(item)
> 
> 
>
David Sterba Feb. 22, 2019, 2:39 p.m. UTC | #3
On Wed, Feb 20, 2019 at 12:32:02PM +0000, YueHaibing wrote:
> There is a messy cast here:
> 	min_t(int, len, (int)sizeof(*item)));
> 
> min_t() should normally cast to unsigned.  It's not possible for
> "len" to be negative, but if it were then we definitely
> wouldn't want to pass negatives to read_extent_buffer().  Also there
> is an extra cast.
> 
> This patch shouldn't affect runtime, it's just a clean up.
> 
> Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>

Applied, thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
index 02d1a57af78b..893d12fbfda0 100644
--- a/fs/btrfs/root-tree.c
+++ b/fs/btrfs/root-tree.c
@@ -21,12 +21,12 @@  static void btrfs_read_root_item(struct extent_buffer *eb, int slot,
 				struct btrfs_root_item *item)
 {
 	uuid_le uuid;
-	int len;
+	u32 len;
 	int need_reset = 0;
 
 	len = btrfs_item_size_nr(eb, slot);
 	read_extent_buffer(eb, item, btrfs_item_ptr_offset(eb, slot),
-			min_t(int, len, (int)sizeof(*item)));
+			   min_t(u32, len, sizeof(*item)));
 	if (len < sizeof(*item))
 		need_reset = 1;
 	if (!need_reset && btrfs_root_generation(item)