Re: [PATCH v3 3/3] asm-generic/io.h: Silence -Wnull-pointer-arithmetic warning on PCI_IOBASE

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2021-04-21 at 11:24 +0000, David Laight wrote:
> From: Niklas Schnelle
> > Sent: 21 April 2021 12:18
> > 
> > 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.
> ...
> > diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
> > index c6af40ce03be..aabb0a8186ee 100644
> > --- a/include/asm-generic/io.h
> > +++ b/include/asm-generic/io.h
> ...
> > @@ -458,12 +454,17 @@ 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
> 
> I suspect that this might be better not inlined
> when PCI_IOBASE is undefined.
> 
> Otherwise you get quite a lot of bloat from all the
> WARN_ONCE() calls.
> 
> 	David

Hmm, I was wondering if we should rather have a large ifdef block of
all these functions stubbed to WARN_ONCE rather than in each function.
As I understand it this would be necessary if we want the inline gone.
They would still be static though so we still get a copy per
compilation unit that uses it or am I misunderstanding?

> 
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
> 




[Index of Archives]     [Kernel Development]     [DCCP]     [Linux ARM Development]     [Linux]     [Photo]     [Yosemite Help]     [Linux ARM Kernel]     [Linux SCSI]     [Linux x86_64]     [Linux Hams]

  Powered by Linux