diff mbox series

[5.10] btrfs: fix region size in count_bitmap_extents

Message ID 20230914094555.25657-1-abelova@astralinux.ru (mailing list archive)
State New, archived
Headers show
Series [5.10] btrfs: fix region size in count_bitmap_extents | expand

Commit Message

Anastasia Belova Sept. 14, 2023, 9:45 a.m. UTC
count_bitmap_extents was deleted in version 5.11, but
there is possible mistake in versions 5.6-5.10.

Region size should be calculated by subtracting
the end from the beginning.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: dfb79ddb130e ("btrfs: track discardable extents for async discard")
Signed-off-by: Anastasia Belova <abelova@astralinux.ru>
---
 fs/btrfs/free-space-cache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Anastasia Belova Oct. 3, 2023, 12:48 p.m. UTC | #1
03/10/23 15:39, Anastasia Belova пишет:
>
> 14/09/23 12:45, Anastasia Belova пишет:
>> count_bitmap_extents was deleted in version 5.11, but
>> there is possible mistake in versions 5.6-5.10.
>>
>> Region size should be calculated by subtracting
>> the end from the beginning.
> Do I understand correctly that bytes should decrease and
> (rs - re) is always negative and should be replaced by (re - rs)?
>> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>>
>> Fixes: dfb79ddb130e ("btrfs: track discardable extents for async discard")
>> Signed-off-by: Anastasia Belova<abelova@astralinux.ru>
>> ---
>>   fs/btrfs/free-space-cache.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
>> index 4989c60b1df9..a34e266a0969 100644
>> --- a/fs/btrfs/free-space-cache.c
>> +++ b/fs/btrfs/free-space-cache.c
>> @@ -1930,7 +1930,7 @@ static int count_bitmap_extents(struct btrfs_free_space_ctl *ctl,
>>   
>>   	bitmap_for_each_set_region(bitmap_info->bitmap, rs, re, 0,
>>   				   BITS_PER_BITMAP) {
>> -		bytes -= (rs - re) * ctl->unit;
>> +		bytes -= (re - rs) * ctl->unit;
>>   		count++;
>>   
>>   		if (!bytes)
> Anastasia
Sorry for sending html accidentally
diff mbox series

Patch

diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 4989c60b1df9..a34e266a0969 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -1930,7 +1930,7 @@  static int count_bitmap_extents(struct btrfs_free_space_ctl *ctl,
 
 	bitmap_for_each_set_region(bitmap_info->bitmap, rs, re, 0,
 				   BITS_PER_BITMAP) {
-		bytes -= (rs - re) * ctl->unit;
+		bytes -= (re - rs) * ctl->unit;
 		count++;
 
 		if (!bytes)