From: "Michael S. Tsirkin" <mst@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, patches@linaro.org, qemu-block@nongnu.org,
Fam Zheng <famz@redhat.com>, Igor Mammedov <imammedo@redhat.com>,
Ben Warren <ben@skyportsystems.com>,
Max Reitz <mreitz@redhat.com>, Kevin Wolf <kwolf@redhat.com>,
Stefan Weil <sw@weilnetz.de>
Subject: Re: [Qemu-devel] [PATCH 3/3] uuid: Make qemu_uuid_bswap() take and return a QemuUUID
Date: Mon, 10 Dec 2018 12:57:41 -0500 [thread overview]
Message-ID: <20181210125731-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20181210112649.11581-4-peter.maydell@linaro.org>
On Mon, Dec 10, 2018 at 11:26:49AM +0000, Peter Maydell wrote:
> Currently qemu_uuid_bswap() takes a pointer to the QemuUUID to
> be byte-swapped. This means it can't be used when the UUID
> to be swapped is in a packed member of a struct. It's also
> out of line with the general bswap*() functions we provide
> in bswap.h, which take the value to be swapped and return it.
>
> Make qemu_uuid_bswap() take a QemuUUID and return the swapped version.
>
> This fixes some clang warnings about taking the address of
> a packed struct member in block/vdi.c.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
For acpi:
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> include/qemu/uuid.h | 2 +-
> block/vdi.c | 16 ++++++++--------
> hw/acpi/vmgenid.c | 6 ++----
> tests/vmgenid-test.c | 2 +-
> util/uuid.c | 10 +++++-----
> 5 files changed, 17 insertions(+), 19 deletions(-)
>
> diff --git a/include/qemu/uuid.h b/include/qemu/uuid.h
> index 09489ce5c5e..037357d990b 100644
> --- a/include/qemu/uuid.h
> +++ b/include/qemu/uuid.h
> @@ -56,6 +56,6 @@ char *qemu_uuid_unparse_strdup(const QemuUUID *uuid);
>
> int qemu_uuid_parse(const char *str, QemuUUID *uuid);
>
> -void qemu_uuid_bswap(QemuUUID *uuid);
> +QemuUUID qemu_uuid_bswap(QemuUUID uuid);
>
> #endif
> diff --git a/block/vdi.c b/block/vdi.c
> index 4cc726047c3..0c34f6bae46 100644
> --- a/block/vdi.c
> +++ b/block/vdi.c
> @@ -203,10 +203,10 @@ static void vdi_header_to_cpu(VdiHeader *header)
> header->block_extra = le32_to_cpu(header->block_extra);
> header->blocks_in_image = le32_to_cpu(header->blocks_in_image);
> header->blocks_allocated = le32_to_cpu(header->blocks_allocated);
> - qemu_uuid_bswap(&header->uuid_image);
> - qemu_uuid_bswap(&header->uuid_last_snap);
> - qemu_uuid_bswap(&header->uuid_link);
> - qemu_uuid_bswap(&header->uuid_parent);
> + header->uuid_image = qemu_uuid_bswap(header->uuid_image);
> + header->uuid_last_snap = qemu_uuid_bswap(header->uuid_last_snap);
> + header->uuid_link = qemu_uuid_bswap(header->uuid_link);
> + header->uuid_parent = qemu_uuid_bswap(header->uuid_parent);
> }
>
> static void vdi_header_to_le(VdiHeader *header)
> @@ -227,10 +227,10 @@ static void vdi_header_to_le(VdiHeader *header)
> header->block_extra = cpu_to_le32(header->block_extra);
> header->blocks_in_image = cpu_to_le32(header->blocks_in_image);
> header->blocks_allocated = cpu_to_le32(header->blocks_allocated);
> - qemu_uuid_bswap(&header->uuid_image);
> - qemu_uuid_bswap(&header->uuid_last_snap);
> - qemu_uuid_bswap(&header->uuid_link);
> - qemu_uuid_bswap(&header->uuid_parent);
> + header->uuid_image = qemu_uuid_bswap(header->uuid_image);
> + header->uuid_last_snap = qemu_uuid_bswap(header->uuid_last_snap);
> + header->uuid_link = qemu_uuid_bswap(header->uuid_link);
> + header->uuid_parent = qemu_uuid_bswap(header->uuid_parent);
> }
>
> static void vdi_header_print(VdiHeader *header)
> diff --git a/hw/acpi/vmgenid.c b/hw/acpi/vmgenid.c
> index d78b579a201..02717a8b0dc 100644
> --- a/hw/acpi/vmgenid.c
> +++ b/hw/acpi/vmgenid.c
> @@ -30,8 +30,7 @@ void vmgenid_build_acpi(VmGenIdState *vms, GArray *table_data, GArray *guid,
> * first, since that's what the guest expects
> */
> g_array_set_size(guid, VMGENID_FW_CFG_SIZE - ARRAY_SIZE(guid_le.data));
> - guid_le = vms->guid;
> - qemu_uuid_bswap(&guid_le);
> + guid_le = qemu_uuid_bswap(vms->guid);
> /* The GUID is written at a fixed offset into the fw_cfg file
> * in order to implement the "OVMF SDT Header probe suppressor"
> * see docs/specs/vmgenid.txt for more details
> @@ -149,8 +148,7 @@ static void vmgenid_update_guest(VmGenIdState *vms)
> * however, will expect the fields to be little-endian.
> * Perform a byte swap immediately before writing.
> */
> - guid_le = vms->guid;
> - qemu_uuid_bswap(&guid_le);
> + guid_le = qemu_uuid_bswap(vms->guid);
> /* The GUID is written at a fixed offset into the fw_cfg file
> * in order to implement the "OVMF SDT Header probe suppressor"
> * see docs/specs/vmgenid.txt for more details.
> diff --git a/tests/vmgenid-test.c b/tests/vmgenid-test.c
> index 0a6fb55f2eb..98db43f5a65 100644
> --- a/tests/vmgenid-test.c
> +++ b/tests/vmgenid-test.c
> @@ -110,7 +110,7 @@ static void read_guid_from_memory(QemuUUID *guid)
> /* The GUID is in little-endian format in the guest, while QEMU
> * uses big-endian. Swap after reading.
> */
> - qemu_uuid_bswap(guid);
> + *guid = qemu_uuid_bswap(*guid);
> }
>
> static void read_guid_from_monitor(QemuUUID *guid)
> diff --git a/util/uuid.c b/util/uuid.c
> index ebf06c049ad..5787f0978c1 100644
> --- a/util/uuid.c
> +++ b/util/uuid.c
> @@ -110,10 +110,10 @@ int qemu_uuid_parse(const char *str, QemuUUID *uuid)
>
> /* Swap from UUID format endian (BE) to the opposite or vice versa.
> */
> -void qemu_uuid_bswap(QemuUUID *uuid)
> +QemuUUID qemu_uuid_bswap(QemuUUID uuid)
> {
> - assert(QEMU_PTR_IS_ALIGNED(uuid, sizeof(uint32_t)));
> - bswap32s(&uuid->fields.time_low);
> - bswap16s(&uuid->fields.time_mid);
> - bswap16s(&uuid->fields.time_high_and_version);
> + bswap32s(&uuid.fields.time_low);
> + bswap16s(&uuid.fields.time_mid);
> + bswap16s(&uuid.fields.time_high_and_version);
> + return uuid;
> }
> --
> 2.19.2
next prev parent reply other threads:[~2018-12-10 17:57 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-10 11:26 [Qemu-devel] [PATCH 0/3] block: fix last address-of-packed-member warnings Peter Maydell
2018-12-10 11:26 ` [Qemu-devel] [PATCH 1/3] block/vpc: Don't take address of fields in packed structs Peter Maydell
2018-12-10 11:26 ` [Qemu-devel] [PATCH 2/3] block/vdi: " Peter Maydell
2018-12-10 11:26 ` [Qemu-devel] [PATCH 3/3] uuid: Make qemu_uuid_bswap() take and return a QemuUUID Peter Maydell
2018-12-10 11:37 ` Marc-André Lureau
2018-12-10 17:57 ` Michael S. Tsirkin [this message]
2019-01-18 13:59 ` [Qemu-devel] [PATCH 0/3] block: fix last address-of-packed-member warnings Peter Maydell
2019-01-18 16:17 ` Kevin Wolf
2019-02-01 10:30 ` Peter Maydell
2019-02-01 10:57 ` Kevin Wolf
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=20181210125731-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=ben@skyportsystems.com \
--cc=famz@redhat.com \
--cc=imammedo@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=patches@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=sw@weilnetz.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.