Skip to content

Commit 6dc3934

Browse files
cuiyunhuiPaul Walmsley
authored andcommitted
riscv: io: avoid null-pointer arithmetic in PIO helpers
When port I/O is not supported, exposing the port-string helpers is both unnecessary and can make clang diagnose null-pointer arithmetic from the PCI_IOBASE based address expression. Keep the MMIO string helpers available as before, but only provide the port I/O variants when CONFIG_HAS_IOPORT is enabled. Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com> Reviewed-by: Arnd Bergmann <arnd@arndb.de> Link: https://patch.msgid.link/20260703122832.15984-2-cuiyunhui@bytedance.com Signed-off-by: Paul Walmsley <pjw@kernel.org>
1 parent 3a2694b commit 6dc3934

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

  • arch/riscv/include/asm

arch/riscv/include/asm/io.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,14 @@ __io_reads_ins(reads, u32, l, __io_br(), __io_ar(addr))
102102
#define readsw(addr, buffer, count) __readsw(addr, buffer, count)
103103
#define readsl(addr, buffer, count) __readsl(addr, buffer, count)
104104

105+
#ifdef CONFIG_HAS_IOPORT
105106
__io_reads_ins(ins, u8, b, __io_pbr(), __io_par(addr))
106107
__io_reads_ins(ins, u16, w, __io_pbr(), __io_par(addr))
107108
__io_reads_ins(ins, u32, l, __io_pbr(), __io_par(addr))
108109
#define insb(addr, buffer, count) __insb(PCI_IOBASE + (addr), buffer, count)
109110
#define insw(addr, buffer, count) __insw(PCI_IOBASE + (addr), buffer, count)
110111
#define insl(addr, buffer, count) __insl(PCI_IOBASE + (addr), buffer, count)
112+
#endif
111113

112114
__io_writes_outs(writes, u8, b, __io_bw(), __io_aw())
113115
__io_writes_outs(writes, u16, w, __io_bw(), __io_aw())
@@ -116,26 +118,32 @@ __io_writes_outs(writes, u32, l, __io_bw(), __io_aw())
116118
#define writesw(addr, buffer, count) __writesw(addr, buffer, count)
117119
#define writesl(addr, buffer, count) __writesl(addr, buffer, count)
118120

121+
#ifdef CONFIG_HAS_IOPORT
119122
__io_writes_outs(outs, u8, b, __io_pbw(), __io_paw())
120123
__io_writes_outs(outs, u16, w, __io_pbw(), __io_paw())
121124
__io_writes_outs(outs, u32, l, __io_pbw(), __io_paw())
122125
#define outsb(addr, buffer, count) __outsb(PCI_IOBASE + (addr), buffer, count)
123126
#define outsw(addr, buffer, count) __outsw(PCI_IOBASE + (addr), buffer, count)
124127
#define outsl(addr, buffer, count) __outsl(PCI_IOBASE + (addr), buffer, count)
128+
#endif
125129

126130
#ifdef CONFIG_64BIT
127131
__io_reads_ins(reads, u64, q, __io_br(), __io_ar(addr))
128132
#define readsq(addr, buffer, count) __readsq(addr, buffer, count)
129133

134+
#ifdef CONFIG_HAS_IOPORT
130135
__io_reads_ins(ins, u64, q, __io_pbr(), __io_par(addr))
131136
#define insq(addr, buffer, count) __insq(PCI_IOBASE + (addr), buffer, count)
137+
#endif
132138

133139
__io_writes_outs(writes, u64, q, __io_bw(), __io_aw())
134140
#define writesq(addr, buffer, count) __writesq(addr, buffer, count)
135141

142+
#ifdef CONFIG_HAS_IOPORT
136143
__io_writes_outs(outs, u64, q, __io_pbr(), __io_paw())
137144
#define outsq(addr, buffer, count) __outsq(PCI_IOBASE + (addr), buffer, count)
138145
#endif
146+
#endif
139147

140148
#include <asm-generic/io.h>
141149

0 commit comments

Comments
 (0)