qemu/scripts/coccinelle/inplace-byteswaps.cocci
<<
>>
Prefs
   1// Replace uses of in-place byteswapping functions with calls to the
   2// equivalent not-in-place functions.  This is necessary to avoid
   3// undefined behaviour if the expression being swapped is a field in a
   4// packed struct.
   5
   6@@
   7expression E;
   8@@
   9-be16_to_cpus(&E);
  10+E = be16_to_cpu(E);
  11@@
  12expression E;
  13@@
  14-be32_to_cpus(&E);
  15+E = be32_to_cpu(E);
  16@@
  17expression E;
  18@@
  19-be64_to_cpus(&E);
  20+E = be64_to_cpu(E);
  21@@
  22expression E;
  23@@
  24-cpu_to_be16s(&E);
  25+E = cpu_to_be16(E);
  26@@
  27expression E;
  28@@
  29-cpu_to_be32s(&E);
  30+E = cpu_to_be32(E);
  31@@
  32expression E;
  33@@
  34-cpu_to_be64s(&E);
  35+E = cpu_to_be64(E);
  36@@
  37expression E;
  38@@
  39-le16_to_cpus(&E);
  40+E = le16_to_cpu(E);
  41@@
  42expression E;
  43@@
  44-le32_to_cpus(&E);
  45+E = le32_to_cpu(E);
  46@@
  47expression E;
  48@@
  49-le64_to_cpus(&E);
  50+E = le64_to_cpu(E);
  51@@
  52expression E;
  53@@
  54-cpu_to_le16s(&E);
  55+E = cpu_to_le16(E);
  56@@
  57expression E;
  58@@
  59-cpu_to_le32s(&E);
  60+E = cpu_to_le32(E);
  61@@
  62expression E;
  63@@
  64-cpu_to_le64s(&E);
  65+E = cpu_to_le64(E);
  66