diff mbox series

riscv: Avoid io read/write cause wrong result

Message ID 20211018035005.16842-1-nick.hu@sifive.com
State Accepted
Commit ddf4972834fdf33f0a3360ff4a68fde333995113
Delegated to: Andes
Headers show
Series riscv: Avoid io read/write cause wrong result | expand

Commit Message

Nick Hu Oct. 18, 2021, 3:50 a.m. UTC
io read/write may cause wrong result because they may read/write data
from/to register instead of memory. Add 'volatile' to avoid it.

Signed-off-by: Nick Hu <nick.hu@sifive.com>
---
 arch/riscv/include/asm/io.h | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

Comments

Leo Liang Oct. 19, 2021, 8:30 a.m. UTC | #1
On Mon, Oct 18, 2021 at 11:50:05AM +0800, Nick Hu wrote:
> io read/write may cause wrong result because they may read/write data
> from/to register instead of memory. Add 'volatile' to avoid it.
> 
> Signed-off-by: Nick Hu <nick.hu@sifive.com>
> ---
>  arch/riscv/include/asm/io.h | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
>
Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>
Bin Meng Oct. 19, 2021, 8:59 a.m. UTC | #2
On Mon, Oct 18, 2021 at 7:31 PM Nick Hu <nick.hu@sifive.com> wrote:
>
> io read/write may cause wrong result because they may read/write data
> from/to register instead of memory. Add 'volatile' to avoid it.
>
> Signed-off-by: Nick Hu <nick.hu@sifive.com>
> ---
>  arch/riscv/include/asm/io.h | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
diff mbox series

Patch

diff --git a/arch/riscv/include/asm/io.h b/arch/riscv/include/asm/io.h
index acf5a96449..3540773c4f 100644
--- a/arch/riscv/include/asm/io.h
+++ b/arch/riscv/include/asm/io.h
@@ -44,15 +44,15 @@  static inline phys_addr_t map_to_sysmem(const void *ptr)
  * read/writes.  We define __arch_*[bl] here, and leave __arch_*w
  * to the architecture specific code.
  */
-#define __arch_getb(a)			(*(unsigned char *)(a))
-#define __arch_getw(a)			(*(unsigned short *)(a))
-#define __arch_getl(a)			(*(unsigned int *)(a))
-#define __arch_getq(a)			(*(unsigned long long *)(a))
-
-#define __arch_putb(v, a)		(*(unsigned char *)(a) = (v))
-#define __arch_putw(v, a)		(*(unsigned short *)(a) = (v))
-#define __arch_putl(v, a)		(*(unsigned int *)(a) = (v))
-#define __arch_putq(v, a)		(*(unsigned long long *)(a) = (v))
+#define __arch_getb(a)			(*(volatile unsigned char *)(a))
+#define __arch_getw(a)			(*(volatile unsigned short *)(a))
+#define __arch_getl(a)			(*(volatile unsigned int *)(a))
+#define __arch_getq(a)			(*(volatile unsigned long long *)(a))
+
+#define __arch_putb(v, a)		(*(volatile unsigned char *)(a) = (v))
+#define __arch_putw(v, a)		(*(volatile unsigned short *)(a) = (v))
+#define __arch_putl(v, a)		(*(volatile unsigned int *)(a) = (v))
+#define __arch_putq(v, a)		(*(volatile unsigned long long *)(a) = (v))
 
 #define __raw_writeb(v, a)		__arch_putb(v, a)
 #define __raw_writew(v, a)		__arch_putw(v, a)