From nobody Wed Apr 16 22:41:10 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 1539704062087964.6183006867765; Tue, 16 Oct 2018 08:34:22 -0700 (PDT) Received: from localhost ([::1]:58712 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCRMP-0001mt-ME for importer@patchew.org; Tue, 16 Oct 2018 11:34:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43168) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCRCW-0000yh-T6 for qemu-devel@nongnu.org; Tue, 16 Oct 2018 11:24:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCRCW-0000A4-4P for qemu-devel@nongnu.org; Tue, 16 Oct 2018 11:24:04 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:51904) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gCRCV-0007xg-Re for qemu-devel@nongnu.org; Tue, 16 Oct 2018 11:24:04 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1gCRCH-0003qj-0Q for qemu-devel@nongnu.org; Tue, 16 Oct 2018 16:23:49 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Tue, 16 Oct 2018 16:23:25 +0100 Message-Id: <20181016152325.31367-20-peter.maydell@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181016152325.31367-1-peter.maydell@linaro.org> References: <20181016152325.31367-1-peter.maydell@linaro.org> 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] [PULL 19/19] coccinelle: new inplace-byteswaps.cocci to remove inplace-byteswapping calls 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: , 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" Add a new Coccinelle script which replaces uses of the inplace byteswapping functions *_to_cpus() and cpu_to_*s() with their not-in-place equivalents. This is useful for where the swapping is done on members of a packed struct -- taking the address of the member to pass it to an inplace function is undefined behaviour in C. Signed-off-by: Peter Maydell Reviewed-by: Eric Blake Reviewed-by: Richard Henderson Message-id: 20181009181612.10633-1-peter.maydell@linaro.org --- scripts/coccinelle/inplace-byteswaps.cocci | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 scripts/coccinelle/inplace-byteswaps.cocci diff --git a/scripts/coccinelle/inplace-byteswaps.cocci b/scripts/coccinell= e/inplace-byteswaps.cocci new file mode 100644 index 00000000000..a869a90cbfd --- /dev/null +++ b/scripts/coccinelle/inplace-byteswaps.cocci @@ -0,0 +1,65 @@ +// Replace uses of in-place byteswapping functions with calls to the +// equivalent not-in-place functions. This is necessary to avoid +// undefined behaviour if the expression being swapped is a field in a +// packed struct. + +@@ +expression E; +@@ +-be16_to_cpus(&E); ++E =3D be16_to_cpu(E); +@@ +expression E; +@@ +-be32_to_cpus(&E); ++E =3D be32_to_cpu(E); +@@ +expression E; +@@ +-be64_to_cpus(&E); ++E =3D be64_to_cpu(E); +@@ +expression E; +@@ +-cpu_to_be16s(&E); ++E =3D cpu_to_be16(E); +@@ +expression E; +@@ +-cpu_to_be32s(&E); ++E =3D cpu_to_be32(E); +@@ +expression E; +@@ +-cpu_to_be64s(&E); ++E =3D cpu_to_be64(E); +@@ +expression E; +@@ +-le16_to_cpus(&E); ++E =3D le16_to_cpu(E); +@@ +expression E; +@@ +-le32_to_cpus(&E); ++E =3D le32_to_cpu(E); +@@ +expression E; +@@ +-le64_to_cpus(&E); ++E =3D le64_to_cpu(E); +@@ +expression E; +@@ +-cpu_to_le16s(&E); ++E =3D cpu_to_le16(E); +@@ +expression E; +@@ +-cpu_to_le32s(&E); ++E =3D cpu_to_le32(E); +@@ +expression E; +@@ +-cpu_to_le64s(&E); ++E =3D cpu_to_le64(E); --=20 2.19.0