From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08285C48BE5 for ; Thu, 17 Jun 2021 23:44:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D87FA61185 for ; Thu, 17 Jun 2021 23:44:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232627AbhFQXqb (ORCPT ); Thu, 17 Jun 2021 19:46:31 -0400 Received: from netrider.rowland.org ([192.131.102.5]:45077 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S230447AbhFQXqa (ORCPT ); Thu, 17 Jun 2021 19:46:30 -0400 Received: (qmail 296032 invoked by uid 1000); 17 Jun 2021 19:44:21 -0400 Date: Thu, 17 Jun 2021 19:44:21 -0400 From: Alan Stern To: Greg Kroah-Hartman Cc: Ruslan Bilovol , Felipe Balbi , Fabien Chouteau , Segiy Stetsyuk , 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 Message-ID: <20210617234421.GA295854@rowland.harvard.edu> References: <20210617162755.29676-1-ruslan.bilovol@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > > Cc: Segiy Stetsyuk > > Cc: stable@kernel.org > > Signed-off-by: Ruslan Bilovol > > --- > > 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