[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH] xen: simplify bitmap_to_xenctl_bitmap for little endian
On 28.03.2025 00:33, Stefano Stabellini wrote: > On Mon, 24 Mar 2025, Jan Beulich wrote: >> On 22.03.2025 00:09, Stefano Stabellini wrote: >>> @@ -384,21 +382,40 @@ int bitmap_to_xenctl_bitmap(struct xenctl_bitmap >>> *xenctl_bitmap, >>> uint8_t zero = 0; >>> int err = 0; >>> unsigned int xen_bytes = DIV_ROUND_UP(nbits, BITS_PER_BYTE); >>> - uint8_t *bytemap = xmalloc_array(uint8_t, xen_bytes); >>> - >>> - if ( !bytemap ) >>> - return -ENOMEM; >>> + uint8_t last; >>> >>> guest_bytes = DIV_ROUND_UP(xenctl_bitmap->nr_bits, BITS_PER_BYTE); >>> copy_bytes = min(guest_bytes, xen_bytes); >>> >>> - bitmap_long_to_byte(bytemap, bitmap, nbits); >>> + if ( IS_ENABLED(__BIG_ENDIAN) ) >>> + { >>> + uint8_t *bytemap = xmalloc_array(uint8_t, xen_bytes); >>> >>> - if ( copy_bytes && >>> - copy_to_guest(xenctl_bitmap->bitmap, bytemap, copy_bytes) ) >>> - err = -EFAULT; >>> + if ( !bytemap ) >>> + return -ENOMEM; >>> >>> - xfree(bytemap); >>> + bitmap_long_to_byte(bytemap, bitmap, nbits); >>> + last = bytemap[nbits/8]; >> >> Same style nit as before. >> >>> + if ( copy_bytes && >> >> copy_bytes > 1 >> >>> + copy_to_guest(xenctl_bitmap->bitmap, bytemap, copy_bytes - 1) >>> ) >>> + err = -EFAULT; >>> + >>> + xfree(bytemap); >>> + } >>> + else >>> + { >>> + const uint8_t *bytemap = (const uint8_t *)bitmap; >>> + last = bytemap[nbits/8]; >>> + >>> + if ( copy_bytes && >>> + copy_to_guest(xenctl_bitmap->bitmap, bytemap, copy_bytes - 1) >>> ) >>> + err = -EFAULT; >> >> The two identical instances would imo better stay common, even if this may >> require another function-scope variable (to invoke xfree() on after the >> copy-out). > > That's not possible because bytemap is defined differently in the two > cases so it has to be defined within the if block. Hence why I said "even if this may require another function-scope variable". Jan
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |