mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-27 05:20:50 +00:00
coccinelle: new inplace-byteswaps.cocci to remove inplace-byteswapping calls
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 <peter.maydell@linaro.org> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20181009181612.10633-1-peter.maydell@linaro.org
This commit is contained in:
parent
ab44c7b71f
commit
2ef297af07
65
scripts/coccinelle/inplace-byteswaps.cocci
Normal file
65
scripts/coccinelle/inplace-byteswaps.cocci
Normal file
@ -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);
|
Loading…
Reference in New Issue
Block a user