qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2] acpi-build: don't access unaligned addresses


From: Michael S. Tsirkin
Subject: Re: [Qemu-devel] [PATCH v2] acpi-build: don't access unaligned addresses
Date: Tue, 11 Mar 2014 14:31:39 +0200

On Tue, Mar 11, 2014 at 12:29:05PM +0000, Peter Maydell wrote:
> On 10 March 2014 19:56, Michael S. Tsirkin <address@hidden> wrote:
> > casting an unaligned address to e.g.
> > uint32_t can trigger undefined behaviour in C.
> > Replace cast + assignment with memcpy.
> >
> > Reported-by: Peter Maydell <address@hidden>
> > Signed-off-by: Michael S. Tsirkin <address@hidden>
> 
> This does fix the clang warnings.
> 
> > -/* Get pointer within table in a safe manner */
> > -#define ACPI_BUILD_PTR(table, size, off, type) \
> > -    ((type *)(acpi_data_get_ptr(table, size, off, sizeof(type))))
> > +/* Set a value within table in a safe manner */
> > +#define ACPI_BUILD_SET_LE(table, size, off, bits, val) \
> > +    do { \
> > +        uint64_t ACPI_BUILD_SET_LE_val = cpu_to_le64(val); \
> > +        memcpy(acpi_data_get_ptr(table, size, off, \
> > +                                 (bits) / BITS_PER_BYTE), \
> > +               &ACPI_BUILD_SET_LE_val, \
> > +               (bits) / BITS_PER_BYTE); \
> > +    } while (0)
> 
> Personally I would have done:
> 
> #define acpi_stb(table, size, off, val) \
>     stb_le_p(acpi_data_get_ptr(table, size, off, 1), val)
> #define acpi_stw(table, size, off, val) \
>     stw_le_p(acpi_data_get_ptr(table, size, off, 2), val)
> #define acpi_stl(table, size, off, val) \
>     stl_le_p(acpi_data_get_ptr(table, size, off, 4), val)
> #define acpi_stq(table, size, off, val) \
>     stq_le_p(acpi_data_get_ptr(table, size, off, 8), val)
> 
> which keeps the grubby details of memcpy and byteswapping
> in bswap.h. However since it's purely inside this file and
> not specifying an API to the rest of QEMU I don't object
> if you prefer the approach you've taken.
> 
> thanks
> -- PMM

I'll think about it some more - this can be
a patch on top. Let's fix the bug for now.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]