efi/libstub: Cast away type warning in use of max()
PATCH 1/1 efi/libstub: Cast away type warning in use of max()
From: Ard Biesheuvel <[email protected]>
Add a missing (u64) cast to alloc_min, which is passed into efi_random_alloc() as unsigned long, while efi_physical_addr_t is u64.
--- drivers/firmware/efi/libstub/randomalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/libstub/randomalloc.c +1 -1
@@ -120,7 +120,7 @@ efi_status_t efi_random_alloc(unsigned long size,continue ; } - target =round_up (max (md->phys_addr, alloc_min), align) + target_slot * align; + target =round_up (max (md->phys_addr, (u64 )alloc_min), align) + target_slot * align; pages = size /EFI_PAGE_SIZE ; status = efi_bs_call(allocate_pages, EFI_ALLOCATE_ADDRESS,
Signature · 1 line
2.44.0.396.g6e790dbe36-goog
Quoted 2 lines · Ard Biesheuvel
Add a missing (u64) cast to
alloc_min, which is passed intoefi_random_alloc()as unsigned long, whileefi_physical_addr_tis u64.
[...]
drivers/firmware/efi/libstub/randomalloc.c efi_status_t efi_random_alloc(unsigned long size, · line 123
Quoted 8 lines
drivers/firmware/efi/libstub/randomalloc.c +1
-1@@ -120,7 +120,7 @@ efi_status_t efi_random_alloc(unsigned long size,continue ; } - target =round_up (max (md->phys_addr, alloc_min), align) + target_slot * align; + target =round_up (max (md->phys_addr, (u64 )alloc_min), align) + target_slot * align;
Why not
max_t(u64, md->phys_addr, alloc_min)
?
Ard Biesheuvel
maintainerQuoted 11 lines · Lukas Wunner
Quoted 2 lines · Ard Biesheuvel
Add a missing (u64) cast to
alloc_min, which is passed intoefi_random_alloc()as unsigned long, whileefi_physical_addr_tis u64.[...]
Quoted 6 lines
drivers/firmware/efi/libstub/randomalloc.c +0
-0@@ -120,7 +120,7 @@ efi_status_t efi_random_alloc(unsigned long size,continue ; }
Quoted 7 lines
drivers/firmware/efi/libstub/randomalloc.c efi_status_t efi_random_alloc(unsigned long size, · line 123
Quoted 2 lines
drivers/firmware/efi/libstub/randomalloc.c +1
-1- target =round_up (max (md->phys_addr, alloc_min), align) + target_slot * align; + target =round_up (max (md->phys_addr, (u64 )alloc_min), align) + target_slot * align;Why not
max_t(u64, md->phys_addr, alloc_min)
Why is that better?
Quoted 11 lines · Ard Biesheuvel
Quoted 10 lines · Lukas Wunner
Quoted 2 lines · Ard Biesheuvel
Add a missing (u64) cast to
alloc_min, which is passed intoefi_random_alloc()as unsigned long, whileefi_physical_addr_tis u64.[...]
Quoted 6 lines
drivers/firmware/efi/libstub/randomalloc.c +0
-0@@ -120,7 +120,7 @@ efi_status_t efi_random_alloc(unsigned long size,continue ; }
Quoted 8 lines
Quoted 6 lines
drivers/firmware/efi/libstub/randomalloc.c efi_status_t efi_random_alloc(unsigned long size, · line 123
Quoted 2 lines
drivers/firmware/efi/libstub/randomalloc.c +1
-1- target =round_up (max (md->phys_addr, alloc_min), align) + target_slot * align; + target =round_up (max (md->phys_addr, (u64 )alloc_min), align) + target_slot * align;Why not
max_t(u64, md->phys_addr, alloc_min)Why is that better?
It just seems to be the idiomatic way to handle these casts in the kernel.
It's also what checkpatch suggests, so by not using it you risk getting "helpful" fixup patches from the usual suspects.
It's your call buddy. :)
Ard Biesheuvel
maintainerQuoted 18 lines · Lukas Wunner
Quoted 16 lines · Ard Biesheuvel
Quoted 15 lines · Lukas Wunner
Quoted 2 lines · Ard Biesheuvel
Add a missing (u64) cast to
alloc_min, which is passed intoefi_random_alloc()as unsigned long, whileefi_physical_addr_tis u64.[...]
drivers/firmware/efi/libstub/randomalloc.c efi_status_t efi_random_alloc(unsigned long size, · line 123
Quoted 8 lines
drivers/firmware/efi/libstub/randomalloc.c +1
-1@@ -120,7 +120,7 @@ efi_status_t efi_random_alloc(unsigned long size,continue ; } - target =round_up (max (md->phys_addr, alloc_min), align) + target_slot * align; + target =round_up (max (md->phys_addr, (u64 )alloc_min), align) + target_slot * align;Why not
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
max_t(u64, md->phys_addr, alloc_min)Why is that better?
It just seems to be the idiomatic way to handle these casts in the kernel.
In this particular case, I prefer max() with the cast, because it matches the other occurrence, where alloc_min is also used but there it is u64 not unsigned long.
Quoted 3 lines
It's also what checkpatch suggests, so by not using it you risk getting "helpful" fixup patches from the usual suspects.
Ugh yeah good point.
Quoted 1 line
It's your call buddy. :)
Thanks for the head's up