From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034261AbcJ0Xtl (ORCPT ); Thu, 27 Oct 2016 19:49:41 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34119 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030644AbcJ0Xtj (ORCPT ); Thu, 27 Oct 2016 19:49:39 -0400 Date: Thu, 27 Oct 2016 16:49:18 -0700 From: Dmitry Torokhov To: Brian Norris Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH] usb: core: correct usb_get_dev() documentation Message-ID: <20161027234918.GD12312@dtor-ws> References: <1477605750-30117-1-git-send-email-computersforpeace@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1477605750-30117-1-git-send-email-computersforpeace@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 27, 2016 at 03:02:30PM -0700, Brian Norris wrote: > In reading through a USB interface driver, I noticed that it called > usb_{get,put}_dev() in its probe() and disconnect() methods. This seemed > unnecessary, but a look at the comments here matched the usage. > > USB interface devices seem to be well covered by the parent/child > relationship of the device model, and so it should be unnecessary for a > child device to grab a refcount on its parent device. > > Signed-off-by: Brian Norris Yes, usb_device is parent of usb_interface and device core does "parent = get_device(dev->parent);" as part of device_add() when registering new interfaces. Reviewed-by: Dmitry Torokhov > --- > This reflects my understanding (and testing), as well as the majority of usage > -- there are *very* few interface drivers that actually call usb_get_dev(). If > I'm wrong, please feel free to tell me so! But I thought patching the > documentation would be the best way to solicit a response :) > > drivers/usb/core/usb.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c > index 592151461017..0ba7e070f04e 100644 > --- a/drivers/usb/core/usb.c > +++ b/drivers/usb/core/usb.c > @@ -539,9 +539,9 @@ EXPORT_SYMBOL_GPL(usb_alloc_dev); > * > * Each live reference to a device should be refcounted. > * > - * Drivers for USB interfaces should normally record such references in > - * their probe() methods, when they bind to an interface, and release > - * them by calling usb_put_dev(), in their disconnect() methods. > + * The device driver core automatically handles this refcounting for USB > + * interface drivers, but this API can be used for non-parent/child > + * relationships. > * > * Return: A pointer to the device with the incremented reference counter. > */ > -- > 2.8.0.rc3.226.g39d4020 > -- Dmitry