Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6920059rwb; Mon, 12 Dec 2022 07:58:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf5cVpTbaY6/FwKbs+NcH9a0Eq69U1Z8GVntuWHwIxmmAF8dsQT2wYRJAUL6jWSiGmiLP+x2 X-Received: by 2002:a05:6402:540a:b0:461:f999:c8b1 with SMTP id ev10-20020a056402540a00b00461f999c8b1mr14020809edb.19.1670860720996; Mon, 12 Dec 2022 07:58:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670860720; cv=none; d=google.com; s=arc-20160816; b=rlbOrc0cuxXyPa/QAlLbDtTrQd2QiuI6JDUG02zK2PUlVG/32Up9J/fthcv88VUQyT SZWg8sEQDweM5hETHbooa7xUTf2pIoFw944tF4M2Jc3/yyca69OdHeMiPn/0AnOP4sDc r7P7nxZHJ/MRvpS0i71ymv4OrP2wErW65MkzkM8t9JJs/GzuePhpVXtScxORcVkUcROf cI9QiKpBc3a4r12AeGGibPlTjWkM38znlp1Cw4qa8BFBd5ZQ/vs10rD29f4kEm7+ptGP ByBh86n9azagkyab0Hb+56OSZ+rujKXlBFSByTrdvGIKdrC6Dc01wahJ33I2FvGytaHL bkQw== 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=Ul8pQb+p4ZxvSn+nKtUJANqhjXad/rMOXGRfHla73TU=; b=yWHNKK+OUAlX/8ut8P5X7e/xgPeDiUhyo6vYscwvk1I+aDSGFMMjSPCn8fxG9aHo76 YEGZFvKdnpmXS0unDGg+AXP+Toh/PZu+uKg6EoER0iQcsYFRyhokhTJPKCp2s4ZDb3Vj TuSE2Aqd+k/YZHQn5OWaEu7Hj96Xe/XOuMA36Mh+0YGBgHMYjm6eQVuPpYacyWHHYxSU YwSYyZ4SkPKs7O8H9M/e0ePT7JBb/nktJP9DymQWhgN7DAMi//qbayaKRV65aK523ITD +O5cCusbej4PBfQK+V8ALb1Sqggs3bCW4fIccyRU3GYe4Lk0vL48OU1Vm/d2RRSQw/T2 xQLg== 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 g17-20020a50ee11000000b00469054c7246si6648237eds.506.2022.12.12.07.58.23; Mon, 12 Dec 2022 07:58:40 -0800 (PST) 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 S232360AbiLLPdU (ORCPT + 74 others); Mon, 12 Dec 2022 10:33:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231462AbiLLPdQ (ORCPT ); Mon, 12 Dec 2022 10:33:16 -0500 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 630A3DF61 for ; Mon, 12 Dec 2022 07:33:14 -0800 (PST) Received: (qmail 855217 invoked by uid 1000); 12 Dec 2022 10:33:13 -0500 Date: Mon, 12 Dec 2022 10:33:13 -0500 From: Alan Stern To: Johan Hovold Cc: Greg Kroah-Hartman , Vincent Mailhol , Oliver Neukum , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] USB: fix misleading usb_set_intfdata() kernel doc Message-ID: References: <20221212152035.31806-1-johan@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221212152035.31806-1-johan@kernel.org> 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 Mon, Dec 12, 2022 at 04:20:35PM +0100, Johan Hovold wrote: > The struct device driver-data pointer is used for any data that a driver > may need in various callbacks while bound to the device. For > convenience, subsystems typically provide wrappers such as > usb_set_intfdata() of the generic accessor functions for use in bus > callbacks. > > There is generally no longer any need for a driver to clear the pointer, > but since commit 0998d0631001 ("device-core: Ensure drvdata = NULL when > no driver is bound") the driver-data pointer is set to NULL by driver > core post unbind anyway. > > For historical reasons, USB core also clears this pointer when an > explicitly claimed interface is released. > > Due to a misunderstanding, a misleading kernel doc comment for > usb_set_intfdata() was recently added which claimed that the driver data > pointer must not be cleared during disconnect before "all actions [are] > completed", which is both imprecise and incorrect. > > Specifically, drivers like cdc-acm which claim additional interfaces use > the driver-data pointer as a flag which is cleared when the first > interface is unbound. As long as a driver does not do something odd like > dereference the pointer in, for example, completion callbacks, this can > be done at any time during disconnect. And in any case this is no > different than for any other resource, like the driver data itself, > which may be freed by the disconnect callback. > > Note that the comment actually also claimed that the interface itself > was somehow being set to NULL by driver core. > > Fix the kernel doc by removing incorrect, overly specific and misleading > details and adding a comment about why some drivers do clear the > driver-data pointer. > > Fixes: 27ef17849779 ("usb: add usb_set_intfdata() documentation") > Signed-off-by: Johan Hovold > --- > > Changes in v2 > - fix up rather than drop the comment > > > include/linux/usb.h | 15 +++++++-------- > 1 file changed, 7 insertions(+), 8 deletions(-) > > diff --git a/include/linux/usb.h b/include/linux/usb.h > index b47371d44d1b..8a32e17f826e 100644 > --- a/include/linux/usb.h > +++ b/include/linux/usb.h > @@ -267,16 +267,15 @@ static inline void *usb_get_intfdata(struct usb_interface *intf) > } > > /** > - * usb_set_intfdata() - associate driver-specific data with the interface > - * @intf: the usb interface > - * @data: pointer to the device priv structure or %NULL > + * usb_set_intfdata() - associate driver-specific data with an interface > + * @intf: USB interface > + * @data: driver data > * > - * Drivers should use this function in their probe() to associate their > - * driver-specific data with the usb interface. > + * Drivers can use this function in their probe() callbacks to associate > + * driver-specific data with an interface. > * > - * When disconnecting, the core will take care of setting @intf back to %NULL, > - * so no actions are needed on the driver side. The interface should not be set > - * to %NULL before all actions completed (e.g. no outsanding URB remaining). > + * Note that there is generally no need to clear the driver-data pointer even > + * if some drivers do so for historical or implementation-specific reasons. I would add (bikeshedding, I realize -- rephrase to suit yourself): This is because the USB core always clears the pointer after unbinding a driver from the interface. Apart from that: Acked-by: Alan Stern > */ > static inline void usb_set_intfdata(struct usb_interface *intf, void *data) > { > -- > 2.37.4 >