mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 10:37:35 +03:00
Replace P2ALIGN with P2ALIGN_TYPED and delete P2ALIGN.
In P2ALIGN, the result would be incorrect when align is unsigned integer and x is larger than max value of the type of align. In that case, -(align) would be a positive integer, which means high bits would be zero and finally stay zero after '&' when align is converted to a larger integer type. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Youzhong Yang <yyang@mathworks.com> Signed-off-by: Qiuhao Chen <chenqiuhao1997@gmail.com> Closes #15940
This commit is contained in:
committed by
Brian Behlendorf
parent
2566592045
commit
9edf6af4ae
@@ -1175,8 +1175,8 @@ efi_use_whole_disk(int fd)
|
||||
* (for performance reasons). The alignment should match the
|
||||
* alignment used by the "zpool_label_disk" function.
|
||||
*/
|
||||
limit = P2ALIGN(efi_label->efi_last_lba - nblocks - EFI_MIN_RESV_SIZE,
|
||||
PARTITION_END_ALIGNMENT);
|
||||
limit = P2ALIGN_TYPED(efi_label->efi_last_lba - nblocks -
|
||||
EFI_MIN_RESV_SIZE, PARTITION_END_ALIGNMENT, diskaddr_t);
|
||||
if (data_start + data_size != limit || resv_start != limit)
|
||||
sync_needed = B_TRUE;
|
||||
|
||||
|
||||
@@ -52,7 +52,8 @@
|
||||
/*
|
||||
* Compatibility macros/typedefs needed for Solaris -> Linux port
|
||||
*/
|
||||
#define P2ALIGN(x, align) ((x) & -(align))
|
||||
// Deprecated. Use P2ALIGN_TYPED instead.
|
||||
// #define P2ALIGN(x, align) ((x) & -(align))
|
||||
#define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1)
|
||||
#define P2ROUNDUP(x, align) ((((x) - 1) | ((align) - 1)) + 1)
|
||||
#define P2BOUNDARY(off, len, align) \
|
||||
|
||||
@@ -268,7 +268,8 @@ zpool_label_disk(libzfs_handle_t *hdl, zpool_handle_t *zhp, const char *name)
|
||||
if (start_block == MAXOFFSET_T)
|
||||
start_block = NEW_START_BLOCK;
|
||||
slice_size -= start_block;
|
||||
slice_size = P2ALIGN(slice_size, PARTITION_END_ALIGNMENT);
|
||||
slice_size = P2ALIGN_TYPED(slice_size, PARTITION_END_ALIGNMENT,
|
||||
uint64_t);
|
||||
|
||||
vtoc->efi_parts[0].p_start = start_block;
|
||||
vtoc->efi_parts[0].p_size = slice_size;
|
||||
|
||||
Reference in New Issue
Block a user