linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: f_hid: fix endianness issue with descriptors
@ 2021-06-17 16:27 Ruslan Bilovol
  2021-06-17 16:52 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 4+ messages in thread
From: Ruslan Bilovol @ 2021-06-17 16:27 UTC (permalink / raw)
  To: Felipe Balbi, Greg Kroah-Hartman
  Cc: Fabien Chouteau, Segiy Stetsyuk, linux-usb, linux-kernel, stable

Running sparse checker it shows warning message about
incorrect endianness used for descriptor initialization:

| f_hid.c:91:43: warning: incorrect type in initializer (different base types)
| f_hid.c:91:43:    expected restricted __le16 [usertype] bcdHID
| f_hid.c:91:43:    got int

Fixing issue with cpu_to_le16() macro

Fixes: 71adf1189469 ("USB: gadget: add HID gadget driver")
Cc: Fabien Chouteau <fabien.chouteau@barco.com>
Cc: Segiy Stetsyuk <serg_stetsuk@ukr.net>
Cc: stable@kernel.org
Signed-off-by: Ruslan Bilovol <ruslan.bilovol@gmail.com>
---
 drivers/usb/gadget/function/f_hid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index 70774d8cb14e..02683ac0719d 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -88,7 +88,7 @@ static struct usb_interface_descriptor hidg_interface_desc = {
 static struct hid_descriptor hidg_desc = {
 	.bLength			= sizeof hidg_desc,
 	.bDescriptorType		= HID_DT_HID,
-	.bcdHID				= 0x0101,
+	.bcdHID				= cpu_to_le16(0x0101),
 	.bCountryCode			= 0x00,
 	.bNumDescriptors		= 0x1,
 	/*.desc[0].bDescriptorType	= DYNAMIC */
-- 
2.17.1


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

* Re: [PATCH] usb: gadget: f_hid: fix endianness issue with descriptors
  2021-06-17 16:27 [PATCH] usb: gadget: f_hid: fix endianness issue with descriptors Ruslan Bilovol
@ 2021-06-17 16:52 ` Greg Kroah-Hartman
  2021-06-17 23:44   ` Alan Stern
  0 siblings, 1 reply; 4+ messages in thread
From: Greg Kroah-Hartman @ 2021-06-17 16:52 UTC (permalink / raw)
  To: Ruslan Bilovol
  Cc: Felipe Balbi, Fabien Chouteau, Segiy Stetsyuk, linux-usb,
	linux-kernel, stable

On Thu, Jun 17, 2021 at 07:27:55PM +0300, Ruslan Bilovol wrote:
> Running sparse checker it shows warning message about
> incorrect endianness used for descriptor initialization:
> 
> | f_hid.c:91:43: warning: incorrect type in initializer (different base types)
> | f_hid.c:91:43:    expected restricted __le16 [usertype] bcdHID
> | f_hid.c:91:43:    got int
> 
> Fixing issue with cpu_to_le16() macro
> 
> Fixes: 71adf1189469 ("USB: gadget: add HID gadget driver")
> Cc: Fabien Chouteau <fabien.chouteau@barco.com>
> Cc: Segiy Stetsyuk <serg_stetsuk@ukr.net>
> Cc: stable@kernel.org
> Signed-off-by: Ruslan Bilovol <ruslan.bilovol@gmail.com>
> ---
>  drivers/usb/gadget/function/f_hid.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
> index 70774d8cb14e..02683ac0719d 100644
> --- a/drivers/usb/gadget/function/f_hid.c
> +++ b/drivers/usb/gadget/function/f_hid.c
> @@ -88,7 +88,7 @@ static struct usb_interface_descriptor hidg_interface_desc = {
>  static struct hid_descriptor hidg_desc = {
>  	.bLength			= sizeof hidg_desc,
>  	.bDescriptorType		= HID_DT_HID,
> -	.bcdHID				= 0x0101,
> +	.bcdHID				= cpu_to_le16(0x0101),

This is a BCD value, not a little-endian value, are you sure this
conversion is correct?

thanks,

greg k-h

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

* Re: [PATCH] usb: gadget: f_hid: fix endianness issue with descriptors
  2021-06-17 16:52 ` Greg Kroah-Hartman
@ 2021-06-17 23:44   ` Alan Stern
  2021-06-21  9:22     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Stern @ 2021-06-17 23:44 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Ruslan Bilovol, Felipe Balbi, Fabien Chouteau, Segiy Stetsyuk,
	linux-usb, linux-kernel, stable

On Thu, Jun 17, 2021 at 06:52:54PM +0200, Greg Kroah-Hartman wrote:
> On Thu, Jun 17, 2021 at 07:27:55PM +0300, Ruslan Bilovol wrote:
> > Running sparse checker it shows warning message about
> > incorrect endianness used for descriptor initialization:
> > 
> > | f_hid.c:91:43: warning: incorrect type in initializer (different base types)
> > | f_hid.c:91:43:    expected restricted __le16 [usertype] bcdHID
> > | f_hid.c:91:43:    got int
> > 
> > Fixing issue with cpu_to_le16() macro
> > 
> > Fixes: 71adf1189469 ("USB: gadget: add HID gadget driver")
> > Cc: Fabien Chouteau <fabien.chouteau@barco.com>
> > Cc: Segiy Stetsyuk <serg_stetsuk@ukr.net>
> > Cc: stable@kernel.org
> > Signed-off-by: Ruslan Bilovol <ruslan.bilovol@gmail.com>
> > ---
> >  drivers/usb/gadget/function/f_hid.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
> > index 70774d8cb14e..02683ac0719d 100644
> > --- a/drivers/usb/gadget/function/f_hid.c
> > +++ b/drivers/usb/gadget/function/f_hid.c
> > @@ -88,7 +88,7 @@ static struct usb_interface_descriptor hidg_interface_desc = {
> >  static struct hid_descriptor hidg_desc = {
> >  	.bLength			= sizeof hidg_desc,
> >  	.bDescriptorType		= HID_DT_HID,
> > -	.bcdHID				= 0x0101,
> > +	.bcdHID				= cpu_to_le16(0x0101),
> 
> This is a BCD value, not a little-endian value, are you sure this
> conversion is correct?

It's a BCD value, but the storage format is little endian.  So yes, the 
conversion is correct.

But even more, the conversion is correct because 0x0101 yields exactly 
the same sequence of bytes in little-endian and big-endian orders!  
Either way, it is two bytes each containing 0x01.

Alan Stern

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

* Re: [PATCH] usb: gadget: f_hid: fix endianness issue with descriptors
  2021-06-17 23:44   ` Alan Stern
@ 2021-06-21  9:22     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2021-06-21  9:22 UTC (permalink / raw)
  To: Alan Stern
  Cc: Ruslan Bilovol, Felipe Balbi, Fabien Chouteau, Segiy Stetsyuk,
	linux-usb, linux-kernel, stable

On Thu, Jun 17, 2021 at 07:44:21PM -0400, Alan Stern wrote:
> On Thu, Jun 17, 2021 at 06:52:54PM +0200, Greg Kroah-Hartman wrote:
> > On Thu, Jun 17, 2021 at 07:27:55PM +0300, Ruslan Bilovol wrote:
> > > Running sparse checker it shows warning message about
> > > incorrect endianness used for descriptor initialization:
> > > 
> > > | f_hid.c:91:43: warning: incorrect type in initializer (different base types)
> > > | f_hid.c:91:43:    expected restricted __le16 [usertype] bcdHID
> > > | f_hid.c:91:43:    got int
> > > 
> > > Fixing issue with cpu_to_le16() macro
> > > 
> > > Fixes: 71adf1189469 ("USB: gadget: add HID gadget driver")
> > > Cc: Fabien Chouteau <fabien.chouteau@barco.com>
> > > Cc: Segiy Stetsyuk <serg_stetsuk@ukr.net>
> > > Cc: stable@kernel.org
> > > Signed-off-by: Ruslan Bilovol <ruslan.bilovol@gmail.com>
> > > ---
> > >  drivers/usb/gadget/function/f_hid.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
> > > index 70774d8cb14e..02683ac0719d 100644
> > > --- a/drivers/usb/gadget/function/f_hid.c
> > > +++ b/drivers/usb/gadget/function/f_hid.c
> > > @@ -88,7 +88,7 @@ static struct usb_interface_descriptor hidg_interface_desc = {
> > >  static struct hid_descriptor hidg_desc = {
> > >  	.bLength			= sizeof hidg_desc,
> > >  	.bDescriptorType		= HID_DT_HID,
> > > -	.bcdHID				= 0x0101,
> > > +	.bcdHID				= cpu_to_le16(0x0101),
> > 
> > This is a BCD value, not a little-endian value, are you sure this
> > conversion is correct?
> 
> It's a BCD value, but the storage format is little endian.  So yes, the 
> conversion is correct.
> 
> But even more, the conversion is correct because 0x0101 yields exactly 
> the same sequence of bytes in little-endian and big-endian orders!  
> Either way, it is two bytes each containing 0x01.

Ah, which is why no one has noticed this yet :)

I'll go apply this just to be "correct".

thanks,

greg k-h

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

end of thread, other threads:[~2021-06-21  9:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-17 16:27 [PATCH] usb: gadget: f_hid: fix endianness issue with descriptors Ruslan Bilovol
2021-06-17 16:52 ` Greg Kroah-Hartman
2021-06-17 23:44   ` Alan Stern
2021-06-21  9:22     ` Greg Kroah-Hartman

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