Skip to contentSkip to conversation

CodeSamples/formal: Add pointer cast in WRITE_ONCE() for Linux v5.8 compat

PATCH In review Akira Yokosawa 2 participants 2 messages Sep 26, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 CodeSamples/formal: Add pointer cast in WRITE_ONCE() for Linux v5.8 compat

From 456d16d1450416bbd4eeea175a4bc0c2f819062d Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <[email protected]>
Date: Sat, 26 Sep 2020 12:11:37 +0900
Subject: [PATCH] CodeSamples/formal: Add pointer cast in WRITE_ONCE() for Linux v5.8 compat

On Linux v5.8, "make" under klitmus/ after "make cross-klitmus" at CodeSamples/formal/herd/ doesn't complete with the following error:

    In file included from ./include/linux/export.h:43,
                     from ./include/linux/linkage.h:7,
                     from ./include/linux/kernel.h:8,
                     from ./include/linux/list.h:9,
                     from ./include/linux/module.h:12,
                     from [...]/CodeSamples/fromal/herd/klitmus/litmus030.c:11:
    [...]/CodeSamples/formal/herd/klitmus/litmus030.c: In function 'code0':
    ./include/linux/compiler.h:297:30: error: assignment to 'int * volatile'
    from incomatible pointer type 'int **' [-Werror=incompatible-pointer-types]
      297 |  *(volatile typeof(x) *)&(x) = (val);   \
          |                              ^

    ./include/linux/compiler.h:303:2: note: in expansion of macro '__WRITE_ONCE'
      303 |  __WRITE_ONCE(x, val);    \
          |  ^~~~~~~~~~~~

    [...]/CodeSamples/formal/herd/klitmus/litmus030.c:363:2: note: in expansion
    of macro 'WRITE_ONCE'
      363 |  WRITE_ONCE(*x, x);
          |  ^~~~~~~~~~

    cc1: some warnings being treated as errors

This is due to the simplification of WRITE_ONCE() [1]. Now WRITE_ONCE() catches type mismatch of its arguments.

Adding a pointer cast to the WRITE_ONCE() argumant:

    WRITE_ONCE(*x, (int*)x);

makes the compiler happy.

[1]: https://git.kernel.org/linus/a5460b5e5fb8
("READ_ONCE: Simplify implementations of {READ,WRITE}_ONCE()")

NOTE1: These litmus tests are converted from those under
CodeSamples/formal/litmus/.
NOTE2: They were once presented as code snippets in perfbook.

---
 CodeSamples/formal/litmus/C-WWC+o+o-data-o+o-addr-o.litmus | 2 +-
 CodeSamples/formal/litmus/C-WWC+o+o-r+o-addr-o.litmus      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
CodeSamples/formal/litmus/C-WWC+o+o-data-o+o-addr-o.litmus +1 -1
index cd9df060..3525e033 100644
@@ -13,7 +13,7 @@ int *y = &b;
 
 P0(int **x)
 {
-	WRITE_ONCE(*x, x);
+	WRITE_ONCE(*x, (int*)x);
 }
 
 P1(int **x, int **y)
CodeSamples/formal/litmus/C-WWC+o+o-r+o-addr-o.litmus +1 -1
index 6a65d674..0d16b2f7 100644
@@ -13,7 +13,7 @@ int *y = &b;
 
 P0(int **x)
 {
-	WRITE_ONCE(*x, x);
+	WRITE_ONCE(*x, (int*)x);
 }
 
 P1(int **x, int **y)
Signature · 1 line
2.17.1
#1 lore raw
Quoted 40 lines · Akira Yokosawa
Quoted 1 line

From 456d16d1450416bbd4eeea175a4bc0c2f819062d Mon Sep 17 00:00:00 2001

From: Akira Yokosawa <[email protected]>
Date: Sat, 26 Sep 2020 12:11:37 +0900
Subject: [PATCH] CodeSamples/formal: Add pointer cast in WRITE_ONCE() for Linux v5.8 compat

On Linux v5.8, "make" under klitmus/ after "make cross-klitmus" at CodeSamples/formal/herd/ doesn't complete with the following error:

    In file included from ./include/linux/export.h:43,
                     from ./include/linux/linkage.h:7,
                     from ./include/linux/kernel.h:8,
                     from ./include/linux/list.h:9,
                     from ./include/linux/module.h:12,
                     from [...]/CodeSamples/fromal/herd/klitmus/litmus030.c:11:
    [...]/CodeSamples/formal/herd/klitmus/litmus030.c: In function 'code0':
    ./include/linux/compiler.h:297:30: error: assignment to 'int * volatile'
    from incomatible pointer type 'int **' [-Werror=incompatible-pointer-types]
      297 |  *(volatile typeof(x) *)&(x) = (val);   \
          |                              ^

    ./include/linux/compiler.h:303:2: note: in expansion of macro '__WRITE_ONCE'
      303 |  __WRITE_ONCE(x, val);    \
          |  ^~~~~~~~~~~~

    [...]/CodeSamples/formal/herd/klitmus/litmus030.c:363:2: note: in expansion
    of macro 'WRITE_ONCE'
      363 |  WRITE_ONCE(*x, x);
          |  ^~~~~~~~~~

    cc1: some warnings being treated as errors

This is due to the simplification of WRITE_ONCE() [1]. Now WRITE_ONCE() catches type mismatch of its arguments.

Adding a pointer cast to the WRITE_ONCE() argumant:

    WRITE_ONCE(*x, (int*)x);

makes the compiler happy.

Quoted 8 lines

[1]: https://git.kernel.org/linus/a5460b5e5fb8
("READ_ONCE: Simplify implementations of {READ,WRITE}_ONCE()")

NOTE1: These litmus tests are converted from those under
CodeSamples/formal/litmus/.
NOTE2: They were once presented as code snippets in perfbook.

Good catch, queued and pushed, thank you!!!

Thanx, Paul

Quoted 34 lines
---
 CodeSamples/formal/litmus/C-WWC+o+o-data-o+o-addr-o.litmus | 2 +-
 CodeSamples/formal/litmus/C-WWC+o+o-r+o-addr-o.litmus      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
CodeSamples/formal/litmus/C-WWC+o+o-data-o+o-addr-o.litmus +1 -1
index cd9df060..3525e033 100644
@@ -13,7 +13,7 @@ int *y = &b;
 
 P0(int **x)
 {
-	WRITE_ONCE(*x, x);
+	WRITE_ONCE(*x, (int*)x);
 }
 
 P1(int **x, int **y)
CodeSamples/formal/litmus/C-WWC+o+o-r+o-addr-o.litmus +1 -1
index 6a65d674..0d16b2f7 100644
@@ -13,7 +13,7 @@ int *y = &b;
 
 P0(int **x)
 {
-	WRITE_ONCE(*x, x);
+	WRITE_ONCE(*x, (int*)x);
 }
 
 P1(int **x, int **y)
Signature · 1 line
2.17.1