[PATCH] RISC-V: io: Don't have a void* PCI_IOBASE

Nam Cao namcao at linutronix.de
Mon May 27 00:55:09 PDT 2024


On Mon, May 27, 2024 at 09:44:13AM +0200, Andreas Schwab wrote:
> On Mai 26 2024, Palmer Dabbelt wrote:
> 
> > I recently started noticing warnings along the lines of
> >
> >     include/asm-generic/io.h:752:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
> >             insw(addr, buffer, count);
> >             ^~~~~~~~~~~~~~~~~~~~~~~~~
> >     arch/riscv/include/asm/io.h:105:53: note: expanded from macro 'insw'
> >     #define insw(addr, buffer, count) __insw(PCI_IOBASE + (addr), buffer, count)
> >
> > which are triggered by having PCI_IOBASE be a "void __iomem *".  I'm not
> > quite sure what the right thing to do is here: having it as u8 to make
> > the pointer arithmetic work seems reasonable to me,
> 
> A u8 null pointer is still a null pointer.  Are you sure you are quoting
> the right warning?  AFAICS, PCI_IOBASE is not a null pointer.

Null pointer has nothing to do with this. The warning is about arithmetic
operation on void*, which is undefined behavior.

Compilers usually do arithmetic on void* the same way as for u8*, but that
is not defined by C.

Best regards,
Nam



More information about the linux-riscv mailing list