All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Ruslan Bilovol <ruslan.bilovol@gmail.com>,
	Felipe Balbi <balbi@kernel.org>,
	Fabien Chouteau <fabien.chouteau@barco.com>,
	Segiy Stetsyuk <serg_stetsuk@ukr.net>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@kernel.org
Subject: Re: [PATCH] usb: gadget: f_hid: fix endianness issue with descriptors
Date: Mon, 21 Jun 2021 11:22:36 +0200	[thread overview]
Message-ID: <YNBaXLAOq+/UO9sN@kroah.com> (raw)
In-Reply-To: <20210617234421.GA295854@rowland.harvard.edu>

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

      reply	other threads:[~2021-06-21  9:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YNBaXLAOq+/UO9sN@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=balbi@kernel.org \
    --cc=fabien.chouteau@barco.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=ruslan.bilovol@gmail.com \
    --cc=serg_stetsuk@ukr.net \
    --cc=stable@kernel.org \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.