* [PATCH] asm-generic/io.h: Fix sparse warnings on big-endian architectures
@ 2020-08-03 15:11 Stafford Horne
2020-08-03 19:50 ` Arnd Bergmann
0 siblings, 1 reply; 3+ messages in thread
From: Stafford Horne @ 2020-08-03 15:11 UTC (permalink / raw)
To: LKML; +Cc: Stafford Horne, Arnd Bergmann, linux-arch
On big-endian architectures like OpenRISC, sparse outputs below warnings on
asm-generic/io.h. This is due to io statements like:
__raw_writel(cpu_to_le32(value), PCI_IOBASE + addr);
The __raw_writel() function expects native endianness, however
cpu_to_le32() returns __le32. On little-endian machines these match up
and there is no issue. However, on big-endian we get warnings, for IO
that is defined as little-endian the mismatch is expected.
The fix I propose is to __force to native endian.
Warnings:
./include/asm-generic/io.h:166:15: warning: cast to restricted __le16
./include/asm-generic/io.h:166:15: warning: cast to restricted __le16
./include/asm-generic/io.h:166:15: warning: cast to restricted __le16
./include/asm-generic/io.h:166:15: warning: cast to restricted __le16
./include/asm-generic/io.h:179:15: warning: cast to restricted __le32
./include/asm-generic/io.h:179:15: warning: cast to restricted __le32
./include/asm-generic/io.h:179:15: warning: cast to restricted __le32
./include/asm-generic/io.h:179:15: warning: cast to restricted __le32
./include/asm-generic/io.h:179:15: warning: cast to restricted __le32
./include/asm-generic/io.h:179:15: warning: cast to restricted __le32
./include/asm-generic/io.h:215:22: warning: incorrect type in argument 1 (different base types)
./include/asm-generic/io.h:215:22: expected unsigned short [usertype] value
./include/asm-generic/io.h:215:22: got restricted __le16 [usertype]
./include/asm-generic/io.h:225:22: warning: incorrect type in argument 1 (different base types)
./include/asm-generic/io.h:225:22: expected unsigned int [usertype] value
./include/asm-generic/io.h:225:22: got restricted __le32 [usertype]
Signed-off-by: Stafford Horne <shorne@gmail.com>
---
include/asm-generic/io.h | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
index 30a3aab312e6..c88b73934ab7 100644
--- a/include/asm-generic/io.h
+++ b/include/asm-generic/io.h
@@ -163,7 +163,7 @@ static inline u16 readw(const volatile void __iomem *addr)
u16 val;
__io_br();
- val = __le16_to_cpu(__raw_readw(addr));
+ val = __le16_to_cpu((__le16 __force) __raw_readw(addr));
__io_ar(val);
return val;
}
@@ -176,7 +176,7 @@ static inline u32 readl(const volatile void __iomem *addr)
u32 val;
__io_br();
- val = __le32_to_cpu(__raw_readl(addr));
+ val = __le32_to_cpu((__le32 __force) __raw_readl(addr));
__io_ar(val);
return val;
}
@@ -212,7 +212,7 @@ static inline void writeb(u8 value, volatile void __iomem *addr)
static inline void writew(u16 value, volatile void __iomem *addr)
{
__io_bw();
- __raw_writew(cpu_to_le16(value), addr);
+ __raw_writew((u16 __force) cpu_to_le16(value), addr);
__io_aw();
}
#endif
@@ -222,7 +222,7 @@ static inline void writew(u16 value, volatile void __iomem *addr)
static inline void writel(u32 value, volatile void __iomem *addr)
{
__io_bw();
- __raw_writel(__cpu_to_le32(value), addr);
+ __raw_writel((u32 __force) __cpu_to_le32(value), addr);
__io_aw();
}
#endif
@@ -474,7 +474,7 @@ static inline u16 _inw(unsigned long addr)
u16 val;
__io_pbr();
- val = __le16_to_cpu(__raw_readw(PCI_IOBASE + addr));
+ val = __le16_to_cpu((__le16 __force) __raw_readw(PCI_IOBASE + addr));
__io_par(val);
return val;
}
@@ -487,7 +487,7 @@ static inline u32 _inl(unsigned long addr)
u32 val;
__io_pbr();
- val = __le32_to_cpu(__raw_readl(PCI_IOBASE + addr));
+ val = __le32_to_cpu((__le32 __force) __raw_readl(PCI_IOBASE + addr));
__io_par(val);
return val;
}
@@ -508,7 +508,7 @@ static inline void _outb(u8 value, unsigned long addr)
static inline void _outw(u16 value, unsigned long addr)
{
__io_pbw();
- __raw_writew(cpu_to_le16(value), PCI_IOBASE + addr);
+ __raw_writew((u16 __force) cpu_to_le16(value), PCI_IOBASE + addr);
__io_paw();
}
#endif
@@ -518,7 +518,7 @@ static inline void _outw(u16 value, unsigned long addr)
static inline void _outl(u32 value, unsigned long addr)
{
__io_pbw();
- __raw_writel(cpu_to_le32(value), PCI_IOBASE + addr);
+ __raw_writel((u32 __force) cpu_to_le32(value), PCI_IOBASE + addr);
__io_paw();
}
#endif
--
2.26.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] asm-generic/io.h: Fix sparse warnings on big-endian architectures
2020-08-03 15:11 [PATCH] asm-generic/io.h: Fix sparse warnings on big-endian architectures Stafford Horne
@ 2020-08-03 19:50 ` Arnd Bergmann
2020-08-03 23:47 ` Stafford Horne
0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2020-08-03 19:50 UTC (permalink / raw)
To: Stafford Horne; +Cc: LKML, linux-arch
On Mon, Aug 3, 2020 at 5:11 PM Stafford Horne <shorne@gmail.com> wrote:
>
> On big-endian architectures like OpenRISC, sparse outputs below warnings on
> asm-generic/io.h. This is due to io statements like:
>
> __raw_writel(cpu_to_le32(value), PCI_IOBASE + addr);
>
> The __raw_writel() function expects native endianness, however
> cpu_to_le32() returns __le32. On little-endian machines these match up
> and there is no issue. However, on big-endian we get warnings, for IO
> that is defined as little-endian the mismatch is expected.
>
> The fix I propose is to __force to native endian.
>
> Warnings:
>
> ./include/asm-generic/io.h:166:15: warning: cast to restricted __le16
> ./include/asm-generic/io.h:166:15: warning: cast to restricted __le16
> ./include/asm-generic/io.h:166:15: warning: cast to restricted __le16
> ./include/asm-generic/io.h:166:15: warning: cast to restricted __le16
> ./include/asm-generic/io.h:179:15: warning: cast to restricted __le32
> ./include/asm-generic/io.h:179:15: warning: cast to restricted __le32
> ./include/asm-generic/io.h:179:15: warning: cast to restricted __le32
> ./include/asm-generic/io.h:179:15: warning: cast to restricted __le32
> ./include/asm-generic/io.h:179:15: warning: cast to restricted __le32
> ./include/asm-generic/io.h:179:15: warning: cast to restricted __le32
> ./include/asm-generic/io.h:215:22: warning: incorrect type in argument 1 (different base types)
> ./include/asm-generic/io.h:215:22: expected unsigned short [usertype] value
> ./include/asm-generic/io.h:215:22: got restricted __le16 [usertype]
> ./include/asm-generic/io.h:225:22: warning: incorrect type in argument 1 (different base types)
> ./include/asm-generic/io.h:225:22: expected unsigned int [usertype] value
> ./include/asm-generic/io.h:225:22: got restricted __le32 [usertype]
>
> Signed-off-by: Stafford Horne <shorne@gmail.com>
Looks good to me.
Acked-by: Arnd Bergmann <arnd@arndb.de>
Can you just merge that through your openrisc tree? I don't have
any other asm-generic changes for this merge window.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] asm-generic/io.h: Fix sparse warnings on big-endian architectures
2020-08-03 19:50 ` Arnd Bergmann
@ 2020-08-03 23:47 ` Stafford Horne
0 siblings, 0 replies; 3+ messages in thread
From: Stafford Horne @ 2020-08-03 23:47 UTC (permalink / raw)
To: Arnd Bergmann; +Cc: LKML, linux-arch
On Mon, Aug 03, 2020 at 09:50:59PM +0200, Arnd Bergmann wrote:
> On Mon, Aug 3, 2020 at 5:11 PM Stafford Horne <shorne@gmail.com> wrote:
> >
> > On big-endian architectures like OpenRISC, sparse outputs below warnings on
> > asm-generic/io.h. This is due to io statements like:
> >
> > __raw_writel(cpu_to_le32(value), PCI_IOBASE + addr);
> >
> > The __raw_writel() function expects native endianness, however
> > cpu_to_le32() returns __le32. On little-endian machines these match up
> > and there is no issue. However, on big-endian we get warnings, for IO
> > that is defined as little-endian the mismatch is expected.
> >
> > The fix I propose is to __force to native endian.
> >
> > Warnings:
> >
> > ./include/asm-generic/io.h:166:15: warning: cast to restricted __le16
> > ./include/asm-generic/io.h:166:15: warning: cast to restricted __le16
> > ./include/asm-generic/io.h:166:15: warning: cast to restricted __le16
> > ./include/asm-generic/io.h:166:15: warning: cast to restricted __le16
> > ./include/asm-generic/io.h:179:15: warning: cast to restricted __le32
> > ./include/asm-generic/io.h:179:15: warning: cast to restricted __le32
> > ./include/asm-generic/io.h:179:15: warning: cast to restricted __le32
> > ./include/asm-generic/io.h:179:15: warning: cast to restricted __le32
> > ./include/asm-generic/io.h:179:15: warning: cast to restricted __le32
> > ./include/asm-generic/io.h:179:15: warning: cast to restricted __le32
> > ./include/asm-generic/io.h:215:22: warning: incorrect type in argument 1 (different base types)
> > ./include/asm-generic/io.h:215:22: expected unsigned short [usertype] value
> > ./include/asm-generic/io.h:215:22: got restricted __le16 [usertype]
> > ./include/asm-generic/io.h:225:22: warning: incorrect type in argument 1 (different base types)
> > ./include/asm-generic/io.h:225:22: expected unsigned int [usertype] value
> > ./include/asm-generic/io.h:225:22: got restricted __le32 [usertype]
> >
> > Signed-off-by: Stafford Horne <shorne@gmail.com>
>
> Looks good to me.
>
> Acked-by: Arnd Bergmann <arnd@arndb.de>
>
> Can you just merge that through your openrisc tree? I don't have
> any other asm-generic changes for this merge window.
That's fine with me. Thank you.
-Stafford
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-08-03 23:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-03 15:11 [PATCH] asm-generic/io.h: Fix sparse warnings on big-endian architectures Stafford Horne
2020-08-03 19:50 ` Arnd Bergmann
2020-08-03 23:47 ` Stafford Horne
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).