From: Peter Maydell <peter.maydell@linaro.org>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: QEMU Developers <qemu-devel@nongnu.org>,
Anthony Liguori <aliguori@amazon.com>
Subject: Re: [Qemu-devel] [PATCH v2] acpi-build: don't access unaligned addresses
Date: Tue, 11 Mar 2014 12:29:05 +0000 [thread overview]
Message-ID: <CAFEAcA9q-d-qyXh8=Az6RcnPLSnZdsPfVEnJ+e7ccQunn8YZ7w@mail.gmail.com> (raw)
In-Reply-To: <1394481363-5333-1-git-send-email-mst@redhat.com>
On 10 March 2014 19:56, Michael S. Tsirkin <mst@redhat.com> 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 <peter.maydell@linaro.org>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
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
next prev parent reply other threads:[~2014-03-11 12:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-10 19:56 [Qemu-devel] [PATCH v2] acpi-build: don't access unaligned addresses Michael S. Tsirkin
2014-03-11 12:29 ` Peter Maydell [this message]
2014-03-11 12:31 ` Michael S. Tsirkin
2014-03-12 13:37 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAFEAcA9q-d-qyXh8=Az6RcnPLSnZdsPfVEnJ+e7ccQunn8YZ7w@mail.gmail.com' \
--to=peter.maydell@linaro.org \
--cc=aliguori@amazon.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).