Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp5687905rwi; Sun, 23 Oct 2022 10:06:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5u7wJ158bcUuSdskU3yulsNzkjU0WVHFhpTP0HXwx8iM/BApY8/KQv78j5kipBTNrPKCA5 X-Received: by 2002:a05:6402:847:b0:453:944a:ba8e with SMTP id b7-20020a056402084700b00453944aba8emr26671064edz.326.1666544775540; Sun, 23 Oct 2022 10:06:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666544775; cv=none; d=google.com; s=arc-20160816; b=BziIaPhAdNhGpPOEBdnhoa73eezHN1RqwioO+Jo3RvUvLbSEDbmiE/gtv2Iusyd5Z5 EmZNMKGIZSSdCacUJhSBA+hoCDHYcRrkmjVEYHFEePlG+zhLc+H+vjUMWVRC47Rll/iD rOjOGPvrH0D8YM8S0YKtCl2SexwbKvDZr3eN4P/hte2xvRAIC+UK8ypfVRuCWMwXmTjw oNCzOH0KD8KFOu1LUnPE++AjoPC/3wiZQ9492fynPGTcG61tDWkgBCD3i0fww2WUTO9z yA2Iboc03gF/NuOH6H0w7CtLRiVmNmGhETMxvPvvmdlMbMAjoT8g5gQnnmwwTRMhzSCf ql1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=yyi0/pP3Bbc1MRYUK4C83lx0CuIaaR3RC4D56F7jOho=; b=XdFi87VODiDGelHTpeMLvXDDzgm8o7e1U/G8ZhTv+GSu+ZEEt2AtVkqhuAk7LnjMyq boN1lUp/KN9g6XQ6QuZQXEiqbalgadpq3InejnmIdz3sLjQOlB4Lw+5STfnQL4B2z29k F0BWT17UOlR1DmccxZWzzHoMpXeYd02I/FJdFuwJYwaQsYqbfGAsa6y8H71tl/CCo9Qb IFXDWYtZsQe6K+GyNw6M6WnKMgGzI71chzSxuVpyPRPJAH3AzTQU2ltXDiNnoodKplGH avZRcb8S/zrh4kUtPMzc2H7qt53KpMSaqqor1N7/XBFaxx4HllqgY5zUQAmML/e0SKOf oVKw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c11-20020a0564021f8b00b00458ab55ccc9si26682464edc.168.2022.10.23.10.05.50; Sun, 23 Oct 2022 10:06:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230161AbiJWQqR (ORCPT + 99 others); Sun, 23 Oct 2022 12:46:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230281AbiJWQqM (ORCPT ); Sun, 23 Oct 2022 12:46:12 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 3138348E81 for ; Sun, 23 Oct 2022 09:46:10 -0700 (PDT) Received: (qmail 1382441 invoked by uid 1000); 23 Oct 2022 12:46:10 -0400 Date: Sun, 23 Oct 2022 12:46:10 -0400 From: Alan Stern To: Greg Kroah-Hartman Cc: Linus Torvalds , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Felipe Balbi , Jakob Koschel , Randy Dunlap , Ira Weiny Subject: Re: [PATCH] USB: gadget: dummy_hcd: switch char * to u8 * Message-ID: References: <20221021064453.3341050-1-gregkh@linuxfoundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Oct 23, 2022 at 05:53:19PM +0200, Greg Kroah-Hartman wrote: > On Fri, Oct 21, 2022 at 10:30:37AM -0700, Linus Torvalds wrote: > > On Thu, Oct 20, 2022 at 11:44 PM Greg Kroah-Hartman > > wrote: > > > > > > The function handle_control_request() casts the urb buffer to a char *, > > > and then treats it like a unsigned char buffer when assigning data to > > > it. On some architectures, "char" is really signed, so let's just > > > properly set this pointer to a u8 to take away any potential problems as > > > that's what is really wanted here. > > > > I think you might as well also remove the cast that was always a bit odd: > > > > buf[0] = (u8)dum->devstatus; > > > > although maybe it's intentional ("look, ma, I'm truncating this > > value") because 'devstatus' is a 'u16' type? > > (adding Alan as he's the owner of this file now) > > Yes, devstatus is a u16 as that's what the USB spec says it should be, > but so far only 7 of the lower bits have been used. I guess to do this > properly we should also copy the upper 8 bits in to buf[1], eventhough > in reality it's only ever going to be 0x00 for now. I count only 5 of the bits being used, not 7. (See Figure 9-4 in section 9.4.5 of the USB-3.1 spec.) Maybe you're thinking of Feature flags rather than Status bits? They do have a lot of overlap. Dave Brownell wrote that code initially, so we'll never know why he included the cast. My guess is the same as Linus's: It's there to alert the reader that a 16-bit value is being shortened to squeeze into an 8-bit slot. > Although if we ever do get another 2 status bits defined, this code will > break so we probably should do that too. > > I'll go do that for a v2 of this and properly comment it. Note that there's an out-of-date comment line just above this part of the code: * device: remote wakeup, selfpowered Thanks to USB-3 support, the device recipient now defines three more bits in devstatus: LTM_ENABLED, U1_ENABLED, and U2_ENABLED. Alan Stern