On 19.03.2025 04:03, Stefano Stabellini wrote: > --- a/xen/common/bitmap.c > +++ b/xen/common/bitmap.c > @@ -384,21 +384,26 @@ 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 *bytemap = (uint8_t *)bitmap;
Not only Misra dislikes casting away of const-ness. > 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) ) > + { > + bytemap = xmalloc_array(uint8_t, xen_bytes); > + if ( !bytemap ) > + return -ENOMEM; > + > + bitmap_long_to_byte(bytemap, bitmap, nbits); > + } Where did the clamp_last_byte() go in the little-endian case? > if ( copy_bytes && > copy_to_guest(xenctl_bitmap->bitmap, bytemap, copy_bytes) ) > err = -EFAULT; > > - xfree(bytemap); > + if ( IS_ENABLED(__BIG_ENDIAN) ) > + xfree(bytemap); > > for ( i = copy_bytes; !err && i < guest_bytes; i++ ) > if ( copy_to_guest_offset(xenctl_bitmap->bitmap, i, &zero, 1) ) What about xenctl_bitmap_to_bitmap()? Jan