Skip to contentSkip to conversation

btrfs: fix missing endianess conversion in sb_write_pointer

PATCH Superseded Christoph Hellwig 3 participants 3 messages Nov 14, 2022 Btrfs file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: fix missing endianess conversion in sb_write_pointer

generation is an on-disk __le64 value, so use le64_to_cpu to convert it to host endian before comparing it.

Fixes 12659251ca5d ("btrfs: implement log-structured superblock for ZONED mode")
---
 fs/btrfs/zoned.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/zoned.c +2 -1
index 57aae7694f12c..a055b10c6c884 100644
@@ -136,7 +136,8 @@ static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,
 			super[i] = page_address(page[i]);
 		}
 
-		if (super[0]->generation > super[1]->generation)
+		if (le64_to_cpu(super[0]->generation) >
+		    le64_to_cpu(super[1]->generation))
 			sector = zones[1].start;
 		else
 			sector = zones[0].start;
Signature · 1 line
2.30.2
#1 lore raw
Quoted 5 lines · Christoph Hellwig

generation is an on-disk __le64 value, so use le64_to_cpu to convert it to host endian before comparing it.

Fixes 12659251ca5d ("btrfs: implement log-structured superblock for ZONED mode")

Shouldn't we use btrfs_super_generation() helper? Just need a type conversion to btrfs_super_block pointer.

Thanks,
Qu

Quoted 18 lines
---
  fs/btrfs/zoned.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/zoned.c +2 -1
index 57aae7694f12c..a055b10c6c884 100644
@@ -136,7 +136,8 @@ static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,
  			super[i] = page_address(page[i]);
  		}
 
-		if (super[0]->generation > super[1]->generation)
+		if (le64_to_cpu(super[0]->generation) >
+		    le64_to_cpu(super[1]->generation))
  			sector = zones[1].start;
  		else
  			sector = zones[0].start;
#2 lore raw
Quoted 11 lines · Qu Wenruo
Quoted 5 lines · Christoph Hellwig

generation is an on-disk __le64 value, so use le64_to_cpu to convert it to host endian before comparing it.

Fixes 12659251ca5d ("btrfs: implement log-structured superblock for ZONED mode")

Shouldn't we use btrfs_super_generation() helper? Just need a type conversion to btrfs_super_block pointer.

'super' is already a btrfs_super_block pointer (or better an array of) so btrfs_super_generation() will work without any problems here.

But agreed, this should use the helper.