From nobody Thu Nov 6 06:17:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 153971368020941.113764096274394; Tue, 16 Oct 2018 11:14:40 -0700 (PDT) Received: from localhost ([::1]:59520 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCTrb-0001u3-1Z for importer@patchew.org; Tue, 16 Oct 2018 14:14:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32868) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCTWV-0006pY-FP for qemu-devel@nongnu.org; Tue, 16 Oct 2018 13:52:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCTWR-0006ck-H3 for qemu-devel@nongnu.org; Tue, 16 Oct 2018 13:52:49 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:51928) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gCTWM-0006OW-Q4 for qemu-devel@nongnu.org; Tue, 16 Oct 2018 13:52:43 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1gCTWJ-0003xt-36; Tue, 16 Oct 2018 18:52:39 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Tue, 16 Oct 2018 18:52:36 +0100 Message-Id: <20181016175236.5840-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.19.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH] hw/acpi/nvdimm: Don't take address of fields in packed structs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Igor Mammedov , "Michael S. Tsirkin" , Xiao Guangrong , patches@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 not using the "modify in place" byte swapping functions. Patch produced with scripts/coccinelle/inplace-byteswaps.cocci. Signed-off-by: Peter Maydell Reviewed-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi --- Automatically generated patch, tested with "make check" only. hw/acpi/nvdimm.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c index 27eeb6609f5..e53b2cb6819 100644 --- a/hw/acpi/nvdimm.c +++ b/hw/acpi/nvdimm.c @@ -581,7 +581,7 @@ static void nvdimm_dsm_func_read_fit(AcpiNVDIMMState *s= tate, NvdimmDsmIn *in, int size; =20 read_fit =3D (NvdimmFuncReadFITIn *)in->arg3; - le32_to_cpus(&read_fit->offset); + read_fit->offset =3D le32_to_cpu(read_fit->offset); =20 fit =3D fit_buf->fit; =20 @@ -742,8 +742,8 @@ static void nvdimm_dsm_get_label_data(NVDIMMDevice *nvd= imm, NvdimmDsmIn *in, int size; =20 get_label_data =3D (NvdimmFuncGetLabelDataIn *)in->arg3; - le32_to_cpus(&get_label_data->offset); - le32_to_cpus(&get_label_data->length); + get_label_data->offset =3D le32_to_cpu(get_label_data->offset); + get_label_data->length =3D le32_to_cpu(get_label_data->length); =20 nvdimm_debug("Read Label Data: offset %#x length %#x.\n", get_label_data->offset, get_label_data->length); @@ -781,8 +781,8 @@ static void nvdimm_dsm_set_label_data(NVDIMMDevice *nvd= imm, NvdimmDsmIn *in, =20 set_label_data =3D (NvdimmFuncSetLabelDataIn *)in->arg3; =20 - le32_to_cpus(&set_label_data->offset); - le32_to_cpus(&set_label_data->length); + set_label_data->offset =3D le32_to_cpu(set_label_data->offset); + set_label_data->length =3D le32_to_cpu(set_label_data->length); =20 nvdimm_debug("Write Label Data: offset %#x length %#x.\n", set_label_data->offset, set_label_data->length); @@ -877,9 +877,9 @@ nvdimm_dsm_write(void *opaque, hwaddr addr, uint64_t va= l, unsigned size) in =3D g_new(NvdimmDsmIn, 1); cpu_physical_memory_read(dsm_mem_addr, in, sizeof(*in)); =20 - le32_to_cpus(&in->revision); - le32_to_cpus(&in->function); - le32_to_cpus(&in->handle); + in->revision =3D le32_to_cpu(in->revision); + in->function =3D le32_to_cpu(in->function); + in->handle =3D le32_to_cpu(in->handle); =20 nvdimm_debug("Revision %#x Handler %#x Function %#x.\n", in->revision, in->handle, in->function); --=20 2.19.0