btrfs: zoned: fix zone number to sector/physical calculation
authorNaohiro Aota <naohiro.aota@wdc.com>
Thu, 27 May 2021 06:27:32 +0000 (15:27 +0900)
committerDavid Sterba <dsterba@suse.com>
Fri, 4 Jun 2021 11:11:50 +0000 (13:11 +0200)
commit5b434df8778771d181bc19fb4593bca114d1c4eb
tree7624ad69ad0208990c115a9794e72341f5347758
parent165ea85f14831f27fc6fe3b02b35e42e50b9ed94
btrfs: zoned: fix zone number to sector/physical calculation

In btrfs_get_dev_zone_info(), we have "u32 sb_zone" and calculate "sector_t
sector" by shifting it. But, this "sector" is calculated in 32bit, leading
it to be 0 for the 2nd superblock copy.

Since zone number is u32, shifting it to sector (sector_t) or physical
address (u64) can easily trigger a missing cast bug like this.

This commit introduces helpers to convert zone number to sector/LBA, so we
won't fall into the same pitfall again.

Reported-by: Dmitry Fomichev <Dmitry.Fomichev@wdc.com>
Fixes: 12659251ca5d ("btrfs: implement log-structured superblock for ZONED mode")
CC: stable@vger.kernel.org # 5.11+
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/zoned.c