From patchwork Mon Dec 10 11:26:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 153258 Delivered-To: patches@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3447098ljp; Mon, 10 Dec 2018 03:26:56 -0800 (PST) X-Google-Smtp-Source: AFSGD/XgLldK0qylV+Fcfanj4EhUZvomlqdSuuF9jSVjUXcae4j8IbRutfhjXpxbO2+QLeI2tngZ X-Received: by 2002:a62:8d4f:: with SMTP id z76mr12410363pfd.2.1544441216285; Mon, 10 Dec 2018 03:26:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544441216; cv=none; d=google.com; s=arc-20160816; b=IgjHE8a3D6zQR0hh7RHHan7tmaAG4iAIMFjIP4I5zp29wK6z8XaD48rShpG59JBami gxinNlBGLASFH6t8rv2UXyQrZ9XHo1pFxkGjyIJX3KhjOQYqQOiUK+qz7BL00bDtHIEL vwElkPmLDnhll2Ca4q+wS3JxcBra5GKr6x/vUMFxHBdxTi81oreVk08AFDBt6PVuDDhJ pOzz+8+OdXXMMattQTfATPbHDD5eQSYwL5i9yk5iRvGDNvh8NL3exOSK/jPuYiSNw4KH /Q9XvYNIvNNsu2v8WsoliIi3149TqX9E6EdW4i6BZno3VKSs+bVOxVQ32EpqBlQ/53an j8Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=fwjf29Q1ACvnsQ4zL95SZ8aHAA9F0FgOfChGG3Tl6V4=; b=wviXiZqDK9uZrOvMm0sQLFek3agYG6sAcE1qxHY4tUevgGVoFv/eHxwP16XG7T6EHj BSAPpvVftFfoFkI2eh5lit0THh0D5bUuoX52u3mzKK51YUl/EYFgN1TUR8O6y9fUML+j 0cFPu6NunpB7GF1cYIkVh7AAJuWn8KqOw/12SExyUo7vR95+zT1IeggA0Dg7/VSLM6tQ LUlwxgMm/SG14jUtANvSUq6OH4pEJ+AhoFerE0PugHsem8NPjgF4SbRb21O1evbEuH+W e0S0+WkvA+OzdiLgSn0DnkDoGbJ1Dlizet89DlxhfapR/5DpMR7hBVYvs/5RlwWKvhGA nG0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id o11si9568113pgd.234.2018.12.10.03.26.55 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Dec 2018 03:26:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1gWJi7-0008CU-1J; Mon, 10 Dec 2018 11:26:51 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, qemu-block@nongnu.org, Fam Zheng , Igor Mammedov , "Michael S. Tsirkin" , Ben Warren , Max Reitz , Kevin Wolf , Stefan Weil Subject: [PATCH 1/3] block/vpc: Don't take address of fields in packed structs Date: Mon, 10 Dec 2018 11:26:47 +0000 Message-Id: <20181210112649.11581-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181210112649.11581-1-peter.maydell@linaro.org> References: <20181210112649.11581-1-peter.maydell@linaro.org> MIME-Version: 1.0 Taking the address of a field in a packed struct is a bad idea, because it might not be actually aligned enough for that pointer type (and thus cause a crash on dereference on some host architectures). Newer versions of clang warn about this. Avoid the bug by generating the UUID into a local variable which is definitely safely aligned and then copying it into place. Signed-off-by: Peter Maydell --- block/vpc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.19.2 diff --git a/block/vpc.c b/block/vpc.c index 80c5b2b197e..968d80ae461 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -979,6 +979,7 @@ static int coroutine_fn vpc_co_create(BlockdevCreateOptions *opts, int64_t total_size; int disk_type; int ret = -EIO; + QemuUUID uuid; assert(opts->driver == BLOCKDEV_DRIVER_VPC); vpc_opts = &opts->u.vpc; @@ -1062,7 +1063,8 @@ static int coroutine_fn vpc_co_create(BlockdevCreateOptions *opts, footer->type = cpu_to_be32(disk_type); - qemu_uuid_generate(&footer->uuid); + qemu_uuid_generate(&uuid); + footer->uuid = uuid; footer->checksum = cpu_to_be32(vpc_checksum(buf, HEADER_SIZE)); From patchwork Mon Dec 10 11:26:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 153255 Delivered-To: patches@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3447039ljp; Mon, 10 Dec 2018 03:26:52 -0800 (PST) X-Google-Smtp-Source: AFSGD/WhRSTf5OmJkmHDt7j3F4lCXffKpQ/dVKEFUi6FHT6XUUC5gJq2NQtYSZosxbNvTe+MaJ3R X-Received: by 2002:adf:e5c4:: with SMTP id a4mr8925229wrn.157.1544441212462; Mon, 10 Dec 2018 03:26:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544441212; cv=none; d=google.com; s=arc-20160816; b=C2/2Krstm64wUfG/ZilUlN8wGD5PHamOTIyyvsBppIeDEBGKux6SJj7wqbUSCXxe+y uw3g6F35kxlB51VfuKcTNsFTBJ0N9XPCVIxY/0ux9HHTtgUTyBgEVfshENomJC6OTUw9 6y598adrQmU14eYTKL7e2h4W/n9yAfJ8o4gHQMMgEaC1ShSRztyFxd8Ow3ysrm2iueXF YaRXQ5na3pqMi9QH83qKrLdxXyjJsTWEY8kmEdTG5FmWiWGE5OEhAGCPivU2rkhbs8OT +tCMmNKmm1rWuulwwyPWbFI6ZvvKDVhKDxjbLi2BFrobt704gjNF0k08DSwD66YZEZab sU6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=CFT0+KtVmpJyBNFC5APck/reLWVSwQnk19htgu64LQk=; b=RTtP0VdyN9kP0pUOcq+wFhdEKdx+ZBExZD/2G/QI/UrKdWWJ916p7eYYpaajvB/Cy0 d1GT4pLbUHy5olCuO8Q8cVUuRpu+oZeEuD9u7sjiIdG3OqJal3Cd0aQny1PB8Gk2ZkCp nJQVMKG5CXsyXRPqwPSjzCmSyNqQv8G2NZZGzkWM2BP8JYlx0bXjaBRPXe6ApAyaPmMF 5xljUN46yfZqfr257uR6J/mRmLJxw7rb+2nZo6KfmKBQ1DY49Y3ODtvO9K6sOJa0tocT yXI5C4hfrJuueZSbo0kRk/bTBVBu9T96ki5QGGpK1PIvrqB9/l6IEn+GbY8g08dRUcsF SV1Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id t201si8166169wme.40.2018.12.10.03.26.52 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Dec 2018 03:26:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1gWJi7-0008Ch-IE; Mon, 10 Dec 2018 11:26:51 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, qemu-block@nongnu.org, Fam Zheng , Igor Mammedov , "Michael S. Tsirkin" , Ben Warren , Max Reitz , Kevin Wolf , Stefan Weil Subject: [PATCH 2/3] block/vdi: Don't take address of fields in packed structs Date: Mon, 10 Dec 2018 11:26:48 +0000 Message-Id: <20181210112649.11581-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181210112649.11581-1-peter.maydell@linaro.org> References: <20181210112649.11581-1-peter.maydell@linaro.org> MIME-Version: 1.0 Taking the address of a field in a packed struct is a bad idea, because it might not be actually aligned enough for that pointer type (and thus cause a crash on dereference on some host architectures). Newer versions of clang warn about this. Instead of passing UUID related functions the address of a possibly unaligned QemuUUID struct, use local variables and then copy to/from the struct field as appropriate. Signed-off-by: Peter Maydell --- block/vdi.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) -- 2.19.2 diff --git a/block/vdi.c b/block/vdi.c index 2380daa583e..4cc726047c3 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -235,7 +235,8 @@ static void vdi_header_to_le(VdiHeader *header) static void vdi_header_print(VdiHeader *header) { - char uuid[37]; + char uuidstr[37]; + QemuUUID uuid; logout("text %s", header->text); logout("signature 0x%08x\n", header->signature); logout("header size 0x%04x\n", header->header_size); @@ -254,14 +255,18 @@ static void vdi_header_print(VdiHeader *header) logout("block extra 0x%04x\n", header->block_extra); logout("blocks tot. 0x%04x\n", header->blocks_in_image); logout("blocks all. 0x%04x\n", header->blocks_allocated); - qemu_uuid_unparse(&header->uuid_image, uuid); - logout("uuid image %s\n", uuid); - qemu_uuid_unparse(&header->uuid_last_snap, uuid); - logout("uuid snap %s\n", uuid); - qemu_uuid_unparse(&header->uuid_link, uuid); - logout("uuid link %s\n", uuid); - qemu_uuid_unparse(&header->uuid_parent, uuid); - logout("uuid parent %s\n", uuid); + uuid = header->uuid_image; + qemu_uuid_unparse(&uuid, uuidstr); + logout("uuid image %s\n", uuidstr); + uuid = header->uuid_last_snap; + qemu_uuid_unparse(&uuid, uuidstr); + logout("uuid snap %s\n", uuidstr); + uuid = header->uuid_link; + qemu_uuid_unparse(&uuid, uuidstr); + logout("uuid link %s\n", uuidstr); + uuid = header->uuid_parent; + qemu_uuid_unparse(&uuid, uuidstr); + logout("uuid parent %s\n", uuidstr); } static int coroutine_fn vdi_co_check(BlockDriverState *bs, BdrvCheckResult *res, @@ -368,6 +373,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, size_t bmap_size; int ret; Error *local_err = NULL; + QemuUUID uuid_link, uuid_parent; bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, false, errp); @@ -395,6 +401,9 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, goto fail; } + uuid_link = header.uuid_link; + uuid_parent = header.uuid_parent; + if (header.disk_size % SECTOR_SIZE != 0) { /* 'VBoxManage convertfromraw' can create images with odd disk sizes. We accept them but round the disk size to the next multiple of @@ -444,11 +453,11 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, (uint64_t)header.blocks_in_image * header.block_size); ret = -ENOTSUP; goto fail; - } else if (!qemu_uuid_is_null(&header.uuid_link)) { + } else if (!qemu_uuid_is_null(&uuid_link)) { error_setg(errp, "unsupported VDI image (non-NULL link UUID)"); ret = -ENOTSUP; goto fail; - } else if (!qemu_uuid_is_null(&header.uuid_parent)) { + } else if (!qemu_uuid_is_null(&uuid_parent)) { error_setg(errp, "unsupported VDI image (non-NULL parent UUID)"); ret = -ENOTSUP; goto fail; @@ -733,6 +742,7 @@ static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_options, BlockDriverState *bs_file = NULL; BlockBackend *blk = NULL; uint32_t *bmap = NULL; + QemuUUID uuid; assert(create_options->driver == BLOCKDEV_DRIVER_VDI); vdi_opts = &create_options->u.vdi; @@ -819,8 +829,10 @@ static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_options, if (image_type == VDI_TYPE_STATIC) { header.blocks_allocated = blocks; } - qemu_uuid_generate(&header.uuid_image); - qemu_uuid_generate(&header.uuid_last_snap); + qemu_uuid_generate(&uuid); + header.uuid_image = uuid; + qemu_uuid_generate(&uuid); + header.uuid_last_snap = uuid; /* There is no need to set header.uuid_link or header.uuid_parent here. */ if (VDI_DEBUG) { vdi_header_print(&header); From patchwork Mon Dec 10 11:26:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 153257 Delivered-To: patches@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3447075ljp; Mon, 10 Dec 2018 03:26:55 -0800 (PST) X-Google-Smtp-Source: AFSGD/XF0JLcvWFvCjOFIRk56VGtwdCcA+GJcVid6KJ1Km8QX3ID2gjD9CmDn80iZqo4YQzXJPi+ X-Received: by 2002:a62:4b4d:: with SMTP id y74mr11893313pfa.186.1544441214932; Mon, 10 Dec 2018 03:26:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544441214; cv=none; d=google.com; s=arc-20160816; b=wZ7hIWqX9Cij4aWUNjp/0E3cTJ1zlmDcQcHvUu3vjZHA0DoUbZwppQqEWouh1xSytY 7BLA43xN2wQETuyKTkUrXpWhn6sYez0+CI6NfjMKQYRThMP6U0oWIshbdIQ+MTQrw9D4 8815nCOzz2ptLY23S/WWeXla89xZr2vPfwiBNrmIcSpEOzOwNv5uBICZbKAU6BFZsdbv fbuqZWDLIdRknU7tyQfy3xkP93xn/6279HHmPMoepVXo3oOalfzaIc+7Vr4zfhwW/YQA HdhhKvMkOfXPA0BqKTf1YVJHkIIA/VyHAesEZIyGL9TWHTCHvnGswW/OZ5N5XgD+jQ2T YlMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=DLM5JPSElEAUPMAVXOpVdYJOU3U5BXPwlF09QqthE1w=; b=kZCDTE4RkzDBAtfAfwCwzGcvEId7fR8ywtsP8YKlscLsAckiX/NimknD3aDulp6sAG ApLQOKbCS1/fSX/melHEzhyKwUcLYmTkw+3KUN3VCAO/s2AzSBkzCvbSU9EvNYDZr6iu 0CPLN24HXYmNrERfCD7vCkd7UkbrQ3zKlamhDg3W63aYJJUHZSLsCSF/pTlUCbGjMce5 aSykFszrYCOS+qpxq6ntSyAhzDtxJpG+G32RW05E4qDpPcEDSpqK4yKYGPrT5IB3RQ16 /QXM0MLnzsPeI3b8rJ1vCNat9sDbi1AbpnRQjXgeigSJjcYQKXXbse+fPMObuVcXZob4 YTKw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id f65si10767400pfb.194.2018.12.10.03.26.54 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Dec 2018 03:26:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1gWJi8-0008D0-5Y; Mon, 10 Dec 2018 11:26:52 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, qemu-block@nongnu.org, Fam Zheng , Igor Mammedov , "Michael S. Tsirkin" , Ben Warren , Max Reitz , Kevin Wolf , Stefan Weil Subject: [PATCH 3/3] uuid: Make qemu_uuid_bswap() take and return a QemuUUID Date: Mon, 10 Dec 2018 11:26:49 +0000 Message-Id: <20181210112649.11581-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181210112649.11581-1-peter.maydell@linaro.org> References: <20181210112649.11581-1-peter.maydell@linaro.org> MIME-Version: 1.0 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 --- 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(-) -- 2.19.2 Reviewed-by: Marc-André Lureau Reviewed-by: Michael S. Tsirkin 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; }