Skip to content

Commit

Permalink
asm-generic/io.h: Silence -Wnull-pointer-arithmetic warning on PCI_IO…
Browse files Browse the repository at this point in the history
…BASE

When PCI_IOBASE is not defined, it is set to 0 such that it is ignored
in calls to the readX/writeX primitives. This triggers clang's
-Wnull-pointer-arithmetic warning and will result in illegal accesses on
platforms that do not support I/O ports if drivers do still attempt to
access them.

Make things explicit and silence the warning by letting inb() and
friends fail with WARN_ONCE() and a 0xff... return in case PCI_IOBASE is
not defined.

Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
  • Loading branch information
niklas88 authored and intel-lab-lkp committed Apr 15, 2021
1 parent cbdb7b3 commit f039411
Showing 1 changed file with 51 additions and 4 deletions.
55 changes: 51 additions & 4 deletions include/asm-generic/io.h
Expand Up @@ -440,10 +440,6 @@ static inline void writesq(volatile void __iomem *addr, const void *buffer,
#endif
#endif /* CONFIG_64BIT */

#ifndef PCI_IOBASE
#define PCI_IOBASE ((void __iomem *)0)
#endif

#ifndef IO_SPACE_LIMIT
#define IO_SPACE_LIMIT 0xffff
#endif
Expand All @@ -458,68 +454,95 @@ static inline void writesq(volatile void __iomem *addr, const void *buffer,
#define _inb _inb
static inline u8 _inb(unsigned long addr)
{
#ifdef PCI_IOBASE
u8 val;

__io_pbr();
val = __raw_readb(PCI_IOBASE + addr);
__io_par(val);
return val;
#else
WARN_ONCE(1, "No I/O port support\n");
return ~0;
#endif
}
#endif

#if !defined(inw) && !defined(_inw)
#define _inw _inw
static inline u16 _inw(unsigned long addr)
{
#ifdef PCI_IOBASE
u16 val;

__io_pbr();
val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
__io_par(val);
return val;
#else
WARN_ONCE(1, "No I/O port support\n");
return ~0;
#endif
}
#endif

#if !defined(inl) && !defined(_inl)
#define _inl _inl
static inline u32 _inl(unsigned long addr)
{
#ifdef PCI_IOBASE
u32 val;

__io_pbr();
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
__io_par(val);
return val;
#else
WARN_ONCE(1, "No I/O port support\n");
return ~0;
#endif
}
#endif

#if !defined(outb) && !defined(_outb)
#define _outb _outb
static inline void _outb(u8 value, unsigned long addr)
{
#ifdef PCI_IOBASE
__io_pbw();
__raw_writeb(value, PCI_IOBASE + addr);
__io_paw();
#else
WARN_ONCE(1, "No I/O port support\n");
#endif
}
#endif

#if !defined(outw) && !defined(_outw)
#define _outw _outw
static inline void _outw(u16 value, unsigned long addr)
{
#ifdef PCI_IOBASE
__io_pbw();
__raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
__io_paw();
#else
WARN_ONCE(1, "No I/O port support\n");
#endif
}
#endif

#if !defined(outl) && !defined(_outl)
#define _outl _outl
static inline void _outl(u32 value, unsigned long addr)
{
#ifdef PCI_IOBASE
__io_pbw();
__raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
__io_paw();
#else
WARN_ONCE(1, "No I/O port support\n");
#endif
}
#endif

Expand Down Expand Up @@ -606,23 +629,35 @@ static inline void outl_p(u32 value, unsigned long addr)
#define insb insb
static inline void insb(unsigned long addr, void *buffer, unsigned int count)
{
#ifdef PCI_IOBASE
readsb(PCI_IOBASE + addr, buffer, count);
#else
WARN_ONCE(1, "No I/O port support\n");
#endif
}
#endif

#ifndef insw
#define insw insw
static inline void insw(unsigned long addr, void *buffer, unsigned int count)
{
#ifdef PCI_IOBASE
readsw(PCI_IOBASE + addr, buffer, count);
#else
WARN_ONCE(1, "No I/O port support\n");
#endif
}
#endif

#ifndef insl
#define insl insl
static inline void insl(unsigned long addr, void *buffer, unsigned int count)
{
#ifdef PCI_IOBASE
readsl(PCI_IOBASE + addr, buffer, count);
#else
WARN_ONCE(1, "No I/O port support\n");
#endif
}
#endif

Expand All @@ -631,7 +666,11 @@ static inline void insl(unsigned long addr, void *buffer, unsigned int count)
static inline void outsb(unsigned long addr, const void *buffer,
unsigned int count)
{
#ifdef PCI_IOBASE
writesb(PCI_IOBASE + addr, buffer, count);
#else
WARN_ONCE(1, "No I/O port support\n");
#endif
}
#endif

Expand All @@ -640,7 +679,11 @@ static inline void outsb(unsigned long addr, const void *buffer,
static inline void outsw(unsigned long addr, const void *buffer,
unsigned int count)
{
#ifdef PCI_IOBASE
writesw(PCI_IOBASE + addr, buffer, count);
#else
WARN_ONCE(1, "No I/O port support\n");
#endif
}
#endif

Expand All @@ -649,7 +692,11 @@ static inline void outsw(unsigned long addr, const void *buffer,
static inline void outsl(unsigned long addr, const void *buffer,
unsigned int count)
{
#ifdef PCI_IOBASE
writesl(PCI_IOBASE + addr, buffer, count);
#else
WARN_ONCE(1, "No I/O port support\n");
#endif
}
#endif

Expand Down

0 comments on commit f039411

Please sign in to comment.