linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] io: Fix return type of _inb and _inl
@ 2020-07-26  3:11 Stafford Horne
  2020-07-26  9:00 ` Andy Shevchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Stafford Horne @ 2020-07-26  3:11 UTC (permalink / raw)
  To: LKML; +Cc: Stafford Horne, Arnd Bergmann, Wei Xu, John Garry, linux-arch

The return type of functions _inb, _inw and _inl are all u16 which looks
wrong.  This patch makes them u8, u16 and u32 respectively.

The original commit text for these does not indicate that these should
be all forced to u16.

Fixes: f009c89df79a ("io: Provide _inX() and _outX()")
Signed-off-by: Stafford Horne <shorne@gmail.com>
---
 include/asm-generic/io.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
index 8b1e020e9a03..30a3aab312e6 100644
--- a/include/asm-generic/io.h
+++ b/include/asm-generic/io.h
@@ -456,7 +456,7 @@ static inline void writesq(volatile void __iomem *addr, const void *buffer,
 
 #if !defined(inb) && !defined(_inb)
 #define _inb _inb
-static inline u16 _inb(unsigned long addr)
+static inline u8 _inb(unsigned long addr)
 {
 	u8 val;
 
@@ -482,7 +482,7 @@ static inline u16 _inw(unsigned long addr)
 
 #if !defined(inl) && !defined(_inl)
 #define _inl _inl
-static inline u16 _inl(unsigned long addr)
+static inline u32 _inl(unsigned long addr)
 {
 	u32 val;
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] io: Fix return type of _inb and _inl
  2020-07-26  3:11 [PATCH] io: Fix return type of _inb and _inl Stafford Horne
@ 2020-07-26  9:00 ` Andy Shevchenko
  2020-07-26 12:53   ` Stafford Horne
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2020-07-26  9:00 UTC (permalink / raw)
  To: Stafford Horne; +Cc: LKML, Arnd Bergmann, Wei Xu, John Garry, Linux-Arch

On Sun, Jul 26, 2020 at 6:14 AM Stafford Horne <shorne@gmail.com> wrote:
>
> The return type of functions _inb, _inw and _inl are all u16 which looks
> wrong.  This patch makes them u8, u16 and u32 respectively.
>
> The original commit text for these does not indicate that these should
> be all forced to u16.

Is it in alight with all architectures? that support this interface natively?

(Return value is arch-dependent AFAIU, so it might actually return
16-bit for byte read, but I agree that this is weird for 32-bit value.
I think you have elaborate more in the commit message)

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] io: Fix return type of _inb and _inl
  2020-07-26  9:00 ` Andy Shevchenko
@ 2020-07-26 12:53   ` Stafford Horne
  2020-07-27  8:04     ` Arnd Bergmann
  0 siblings, 1 reply; 6+ messages in thread
From: Stafford Horne @ 2020-07-26 12:53 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: LKML, Arnd Bergmann, Wei Xu, John Garry, Linux-Arch

On Sun, Jul 26, 2020 at 12:00:37PM +0300, Andy Shevchenko wrote:
> On Sun, Jul 26, 2020 at 6:14 AM Stafford Horne <shorne@gmail.com> wrote:
> >
> > The return type of functions _inb, _inw and _inl are all u16 which looks
> > wrong.  This patch makes them u8, u16 and u32 respectively.
> >
> > The original commit text for these does not indicate that these should
> > be all forced to u16.
> 
> Is it in alight with all architectures? that support this interface natively?
> 
> (Return value is arch-dependent AFAIU, so it might actually return
> 16-bit for byte read, but I agree that this is weird for 32-bit value.
> I think you have elaborate more in the commit message)

Well, this is the generic io code,  at least these api's appear to not be different
for each architecture.  The output read by the architecture dependant code i.e.
__raw_readb() below is getting is placed into a u8.  So I think the output of
the function will be u8.

static inline u8 _inb(unsigned long addr)
{
	u8 val;

	__io_pbr();
	val = __raw_readb(PCI_IOBASE + addr);
	__io_par(val);
	return val;
}

I can expand the commit text, but I would like to get some comments from the
original author to confirm if this is an issue.

-Stafford

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] io: Fix return type of _inb and _inl
  2020-07-26 12:53   ` Stafford Horne
@ 2020-07-27  8:04     ` Arnd Bergmann
  2020-07-27  8:28       ` John Garry
  0 siblings, 1 reply; 6+ messages in thread
From: Arnd Bergmann @ 2020-07-27  8:04 UTC (permalink / raw)
  To: Stafford Horne; +Cc: Andy Shevchenko, LKML, Wei Xu, John Garry, Linux-Arch

On Sun, Jul 26, 2020 at 2:53 PM Stafford Horne <shorne@gmail.com> wrote:
>
> On Sun, Jul 26, 2020 at 12:00:37PM +0300, Andy Shevchenko wrote:
> > On Sun, Jul 26, 2020 at 6:14 AM Stafford Horne <shorne@gmail.com> wrote:
> > >
> > > The return type of functions _inb, _inw and _inl are all u16 which looks
> > > wrong.  This patch makes them u8, u16 and u32 respectively.
> > >
> > > The original commit text for these does not indicate that these should
> > > be all forced to u16.
> >
> > Is it in alight with all architectures? that support this interface natively?
> >
> > (Return value is arch-dependent AFAIU, so it might actually return
> > 16-bit for byte read, but I agree that this is weird for 32-bit value.
> > I think you have elaborate more in the commit message)
>
> Well, this is the generic io code,  at least these api's appear to not be different
> for each architecture.  The output read by the architecture dependant code i.e.
> __raw_readb() below is getting is placed into a u8.  So I think the output of
> the function will be u8.
>
> static inline u8 _inb(unsigned long addr)
> {
>         u8 val;
>
>         __io_pbr();
>         val = __raw_readb(PCI_IOBASE + addr);
>         __io_par(val);
>         return val;
> }
>
> I can expand the commit text, but I would like to get some comments from the
> original author to confirm if this is an issue.

I think your original version is fine, this was clearly just a typo and I've
applied your fix now and will forward it to Linus in the next few days,
giving John the chance to add his Ack or further comments.

Thanks a lot for spotting it and sending a fix.

      Arnd

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] io: Fix return type of _inb and _inl
  2020-07-27  8:04     ` Arnd Bergmann
@ 2020-07-27  8:28       ` John Garry
  2020-07-27  8:41         ` Arnd Bergmann
  0 siblings, 1 reply; 6+ messages in thread
From: John Garry @ 2020-07-27  8:28 UTC (permalink / raw)
  To: Arnd Bergmann, Stafford Horne; +Cc: Andy Shevchenko, LKML, Wei Xu, Linux-Arch

On 27/07/2020 09:04, Arnd Bergmann wrote:> On Sun, Jul 26, 2020 at 2:53 
PM Stafford Horne <shorne@gmail.com> wrote:
>>
>> On Sun, Jul 26, 2020 at 12:00:37PM +0300, Andy Shevchenko wrote:
>>> On Sun, Jul 26, 2020 at 6:14 AM Stafford Horne <shorne@gmail.com> wrote:
>>>>
>>>> The return type of functions _inb, _inw and _inl are all u16 which looks
>>>> wrong.  This patch makes them u8, u16 and u32 respectively.
>>>>
>>>> The original commit text for these does not indicate that these should
>>>> be all forced to u16.
>>>
>>> Is it in alight with all architectures? that support this interface natively?
>>>
>>> (Return value is arch-dependent AFAIU, so it might actually return
>>> 16-bit for byte read, but I agree that this is weird for 32-bit value.
>>> I think you have elaborate more in the commit message)
>>
>> Well, this is the generic io code,  at least these api's appear to not be different
>> for each architecture.  The output read by the architecture dependant code i.e.
>> __raw_readb() below is getting is placed into a u8.  So I think the output of
>> the function will be u8.
>>
>> static inline u8 _inb(unsigned long addr)
>> {
>>          u8 val;
>>
>>          __io_pbr();
>>          val = __raw_readb(PCI_IOBASE + addr);
>>          __io_par(val);
>>          return val;
>> }
>>
>> I can expand the commit text, but I would like to get some comments from the
>> original author to confirm if this is an issue.
> 
> I think your original version is fine, this was clearly just a typo and I've
> applied your fix now and will forward it to Linus in the next few days,
> giving John the chance to add his Ack or further comments.
> 
> Thanks a lot for spotting it and sending a fix.

Thanks Arnd.

Yeah, these looks like copy+paste errors on my part:

Reviewed-by: John Garry <john.garry@huawei.com>

I'll give this patch a spin, but not expecting any differences (since 
original seems ok).

Note that kbuild robot also reported this:
https://lore.kernel.org/lkml/202007140549.J7X9BVPT%25lkp@intel.com/

Extract:

include/asm-generic/io.h:521:22: sparse: sparse: incorrect type in 
argument 1 (different base types) @@     expected unsigned int 
[usertype] value @@     got restricted __le32 [usertype] @@
    include/asm-generic/io.h:521:22: sparse:     expected unsigned int 
[usertype] value
    include/asm-generic/io.h:521:22: sparse:     got restricted __le32 
[usertype]

But they look like issues which were in the existing code. I tried to 
recreate to verify any change, but trying to manually upgrade glibc 
busted my machine :(

Thanks,
John

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] io: Fix return type of _inb and _inl
  2020-07-27  8:28       ` John Garry
@ 2020-07-27  8:41         ` Arnd Bergmann
  0 siblings, 0 replies; 6+ messages in thread
From: Arnd Bergmann @ 2020-07-27  8:41 UTC (permalink / raw)
  To: John Garry; +Cc: Stafford Horne, Andy Shevchenko, LKML, Wei Xu, Linux-Arch

On Mon, Jul 27, 2020 at 10:30 AM John Garry <john.garry@huawei.com> wrote:
> On 27/07/2020 09:04, Arnd Bergmann wrote:> On Sun, Jul 26, 2020 at 2:53
> PM Stafford Horne <shorne@gmail.com> wrote:
> >>
> >> On Sun, Jul 26, 2020 at 12:00:37PM +0300, Andy Shevchenko wrote:
> >>> On Sun, Jul 26, 2020 at 6:14 AM Stafford Horne <shorne@gmail.com> wrote:
> >>>>
> >>>> The return type of functions _inb, _inw and _inl are all u16 which looks
> >>>> wrong.  This patch makes them u8, u16 and u32 respectively.
> >>>>
> >>>> The original commit text for these does not indicate that these should
> >>>> be all forced to u16.
> >>>
> >>> Is it in alight with all architectures? that support this interface natively?
> >>>
> >>> (Return value is arch-dependent AFAIU, so it might actually return
> >>> 16-bit for byte read, but I agree that this is weird for 32-bit value.
> >>> I think you have elaborate more in the commit message)
> >>
> >> Well, this is the generic io code,  at least these api's appear to not be different
> >> for each architecture.  The output read by the architecture dependant code i.e.
> >> __raw_readb() below is getting is placed into a u8.  So I think the output of
> >> the function will be u8.
> >>
> >> static inline u8 _inb(unsigned long addr)
> >> {
> >>          u8 val;
> >>
> >>          __io_pbr();
> >>          val = __raw_readb(PCI_IOBASE + addr);
> >>          __io_par(val);
> >>          return val;
> >> }
> >>
> >> I can expand the commit text, but I would like to get some comments from the
> >> original author to confirm if this is an issue.
> >
> > I think your original version is fine, this was clearly just a typo and I've
> > applied your fix now and will forward it to Linus in the next few days,
> > giving John the chance to add his Ack or further comments.
> >
> > Thanks a lot for spotting it and sending a fix.
>
> Thanks Arnd.
>
> Yeah, these looks like copy+paste errors on my part:
>
> Reviewed-by: John Garry <john.garry@huawei.com>

Thanks!

>
> I'll give this patch a spin, but not expecting any differences (since
> original seems ok).
>
> Note that kbuild robot also reported this:
> https://lore.kernel.org/lkml/202007140549.J7X9BVPT%25lkp@intel.com/
>
> Extract:
>
> include/asm-generic/io.h:521:22: sparse: sparse: incorrect type in
> argument 1 (different base types) @@     expected unsigned int
> [usertype] value @@     got restricted __le32 [usertype] @@
>     include/asm-generic/io.h:521:22: sparse:     expected unsigned int
> [usertype] value
>     include/asm-generic/io.h:521:22: sparse:     got restricted __le32
> [usertype]
>
> But they look like issues which were in the existing code.

Yes, this driver code (atm/ambassador.c) seems to have been broken that
way since it was merged in 1999.

      Arnd

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-07-27  8:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-26  3:11 [PATCH] io: Fix return type of _inb and _inl Stafford Horne
2020-07-26  9:00 ` Andy Shevchenko
2020-07-26 12:53   ` Stafford Horne
2020-07-27  8:04     ` Arnd Bergmann
2020-07-27  8:28       ` John Garry
2020-07-27  8:41         ` Arnd Bergmann

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).