From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([209.51.188.92]:39416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpboG-0007wW-IZ for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpboB-0000Cy-St for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:36:56 -0500 From: Kevin Wolf Date: Fri, 1 Feb 2019 17:35:06 +0100 Message-Id: <20190201163518.31157-16-kwolf@redhat.com> In-Reply-To: <20190201163518.31157-1-kwolf@redhat.com> References: <20190201163518.31157-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 15/27] uuid: Make qemu_uuid_bswap() take and return a QemuUUID List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org From: Peter Maydell 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 Reviewed-by: Michael S. Tsirkin Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Kevin Wolf --- 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 09489ce5c5..037357d990 100644 --- a/include/qemu/uuid.h +++ b/include/qemu/uuid.h @@ -56,6 +56,6 @@ char *qemu_uuid_unparse_strdup(const QemuUUID *uuid); =20 int qemu_uuid_parse(const char *str, QemuUUID *uuid); =20 -void qemu_uuid_bswap(QemuUUID *uuid); +QemuUUID qemu_uuid_bswap(QemuUUID uuid); =20 #endif diff --git a/block/vdi.c b/block/vdi.c index 4cc726047c..0c34f6bae4 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -203,10 +203,10 @@ static void vdi_header_to_cpu(VdiHeader *header) header->block_extra =3D le32_to_cpu(header->block_extra); header->blocks_in_image =3D le32_to_cpu(header->blocks_in_image); header->blocks_allocated =3D 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 =3D qemu_uuid_bswap(header->uuid_image); + header->uuid_last_snap =3D qemu_uuid_bswap(header->uuid_last_snap); + header->uuid_link =3D qemu_uuid_bswap(header->uuid_link); + header->uuid_parent =3D qemu_uuid_bswap(header->uuid_parent); } =20 static void vdi_header_to_le(VdiHeader *header) @@ -227,10 +227,10 @@ static void vdi_header_to_le(VdiHeader *header) header->block_extra =3D cpu_to_le32(header->block_extra); header->blocks_in_image =3D cpu_to_le32(header->blocks_in_image); header->blocks_allocated =3D 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 =3D qemu_uuid_bswap(header->uuid_image); + header->uuid_last_snap =3D qemu_uuid_bswap(header->uuid_last_snap); + header->uuid_link =3D qemu_uuid_bswap(header->uuid_link); + header->uuid_parent =3D qemu_uuid_bswap(header->uuid_parent); } =20 static void vdi_header_print(VdiHeader *header) diff --git a/hw/acpi/vmgenid.c b/hw/acpi/vmgenid.c index d78b579a20..02717a8b0d 100644 --- a/hw/acpi/vmgenid.c +++ b/hw/acpi/vmgenid.c @@ -30,8 +30,7 @@ void vmgenid_build_acpi(VmGenIdState *vms, GArray *tabl= e_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 =3D vms->guid; - qemu_uuid_bswap(&guid_le); + guid_le =3D 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 =3D vms->guid; - qemu_uuid_bswap(&guid_le); + guid_le =3D qemu_uuid_bswap(vms->guid); /* The GUID is written at a fixed offset into the fw_cfg fil= e * in order to implement the "OVMF SDT Header probe suppress= or" * see docs/specs/vmgenid.txt for more details. diff --git a/tests/vmgenid-test.c b/tests/vmgenid-test.c index 52cdd83ec0..ae38ee5ac0 100644 --- a/tests/vmgenid-test.c +++ b/tests/vmgenid-test.c @@ -88,7 +88,7 @@ static void read_guid_from_memory(QTestState *qts, Qemu= UUID *guid) /* The GUID is in little-endian format in the guest, while QEMU * uses big-endian. Swap after reading. */ - qemu_uuid_bswap(guid); + *guid =3D qemu_uuid_bswap(*guid); } =20 static void read_guid_from_monitor(QTestState *qts, QemuUUID *guid) diff --git a/util/uuid.c b/util/uuid.c index ebf06c049a..5787f0978c 100644 --- a/util/uuid.c +++ b/util/uuid.c @@ -110,10 +110,10 @@ int qemu_uuid_parse(const char *str, QemuUUID *uuid= ) =20 /* 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; } --=20 2.20.1