From patchwork Tue Oct 16 15:23:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 148957 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp5242181lji; Tue, 16 Oct 2018 08:32:31 -0700 (PDT) X-Google-Smtp-Source: ACcGV607WlqsxSqG+iyvJC/LMBW141+lUYdaZ2tWkwPc2r+r8nOjt09dNi95Sw2HYIoW8UzmTErv X-Received: by 2002:ac8:ec3:: with SMTP id w3-v6mr21030893qti.138.1539703951274; Tue, 16 Oct 2018 08:32:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539703951; cv=none; d=google.com; s=arc-20160816; b=D77s/VKWA/Zl6SSX26bFh40DujtBZhDME3ambMkbuObyJ5S4QnkVOTTyu5BCKxPoQD OWFTIjO8wTgSxXzTz/s9HriAqkhgnY6xvX8ZD1ZUDmd4KmGA9hGqdg5w+NqevKxkk/Sf Kaa0CubEACgC+Wsj00z78afL8XCKDduGx2tl3br1yKR2s+xnz81ZICH57qD4qIXJSVcv jZFZUuEOKFFV4stXXYcn/DWCWPkfyHbAWS07SUnC08brfr8HrXEtPO37zfObvtlGe8VK 2T4mjNw7TQygeUAVRMhdWK4dNwMYDG+vJW2i1TINWPTNwGdxie32DmMTKlsJzSVLHrEO z+Ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from; bh=mbIl6lDkoKyFjqYGHrp/Gw/f47A+dx2JsZfkxaewum4=; b=YMb7n8ALmwmmIYjRonwFd/5KGVNTLtxVz7zLFr/OI2zTDivaBubFJy0bo8wUQU+Ima Ghj00I91vj52rJowMTr0uYUeNJ8eRVua60PiYIeM+LQSyyUOjCbi9SFQq8+nyooHQ3d/ TTKCteVO5cHXvBaA3gKh6gb6fHHsLFww5+kYGQLvN+prfX4F3noQ/Zb+6T/aaJYUyHlR XWlpRXHzn7RRrWKvUloB9SLtevad/alUnuHMhGGBO1q878+4w6LT/fGX5kGc88IfPyk5 ExgSflpa1uNH2aaQBXU9nY+WXTvlDqPGKRwjuTj+T9LsHUUcIs7x37m23wdeHJLE5kG7 6JpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id b1-v6si295386qke.230.2018.10.16.08.32.31 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 16 Oct 2018 08:32:31 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:58706 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCRKg-0000GB-Nv for patch@linaro.org; Tue, 16 Oct 2018 11:32:30 -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 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 -- 2.19.0 diff --git a/scripts/coccinelle/inplace-byteswaps.cocci b/scripts/coccinelle/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 = be16_to_cpu(E); +@@ +expression E; +@@ +-be32_to_cpus(&E); ++E = be32_to_cpu(E); +@@ +expression E; +@@ +-be64_to_cpus(&E); ++E = be64_to_cpu(E); +@@ +expression E; +@@ +-cpu_to_be16s(&E); ++E = cpu_to_be16(E); +@@ +expression E; +@@ +-cpu_to_be32s(&E); ++E = cpu_to_be32(E); +@@ +expression E; +@@ +-cpu_to_be64s(&E); ++E = cpu_to_be64(E); +@@ +expression E; +@@ +-le16_to_cpus(&E); ++E = le16_to_cpu(E); +@@ +expression E; +@@ +-le32_to_cpus(&E); ++E = le32_to_cpu(E); +@@ +expression E; +@@ +-le64_to_cpus(&E); ++E = le64_to_cpu(E); +@@ +expression E; +@@ +-cpu_to_le16s(&E); ++E = cpu_to_le16(E); +@@ +expression E; +@@ +-cpu_to_le32s(&E); ++E = cpu_to_le32(E); +@@ +expression E; +@@ +-cpu_to_le64s(&E); ++E = cpu_to_le64(E);