Re: [PATCH 6/8] hw/i2c: fix VOUT_MODE representation on little-endian machines

Peter Maydell <[email protected]>
Newsgroups gmane.comp.emulators.qemu
Message-ID <CAFEAcA9X+jQu9DtPoszcoa=wdJSPuxZtvA0j1BFJ2bzNQkWWww@mail.gmail.com>
On Thu, 30 Jul 2026 at 00:13, Titus Rwantare <[email protected]> wrote:
>
> From: Jason Fan <[email protected]>
>
> Even though VOUT_MODE is only one byte, bitfields are allocated in the
> order specific to the host's endianness.
>
> Signed-off-by: Titus Rwantare <[email protected]>
> Signed-off-by: Jason Fan <[email protected]>
> ---
>  include/hw/i2c/pmbus_device.h | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/include/hw/i2c/pmbus_device.h b/include/hw/i2c/pmbus_device.h
> index 9f3569e997..03b2c21c19 100644
> --- a/include/hw/i2c/pmbus_device.h
> +++ b/include/hw/i2c/pmbus_device.h
> @@ -449,10 +449,17 @@ typedef struct PMBusCoefficients {
>  /**
>   * VOUT_Mode bit fields
>   */
> +#if HOST_BIG_ENDIAN
>  typedef struct PMBusVoutMode {
>      uint8_t  mode:3;
>      int8_t   exp:5;
>  } PMBusVoutMode;
> +# else
> +typedef struct PMBusVoutMode {
> +    int8_t   exp:5;
> +    uint8_t  mode:3;
> +} PMBusVoutMode;
> +#endif

This is why where possible we don't use C bitfields for guest
data structures. Better to use the FIELD macros from
include/hw/core/registerfields.h.

thanks
-- PMM
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.