All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Chen <hzpeterchen@gmail.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Brian Norris <computersforpeace@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] usb: core: correct usb_get_dev() documentation
Date: Fri, 28 Oct 2016 13:05:46 +0800	[thread overview]
Message-ID: <20161028050546.GA2393@b29397-desktop> (raw)
In-Reply-To: <20161027234918.GD12312@dtor-ws>

On Thu, Oct 27, 2016 at 04:49:18PM -0700, Dmitry Torokhov wrote:
> 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 <computersforpeace@gmail.com>
> 
> 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 <dmitry.torokhov@gmail.com>
> 

Yes, current code seems a little messy for get{put}_device.
Eg, for USB device, it tries to call get_device again at usb_set_configuration
when create its child device (interface device).
For USB interface device, it handles get{put}_device at message.c for
common interface, it seems to be not necessary to call
usb_get{put}_dev again at individual interface driver.

Peter
> > ---
> > 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
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 

Best Regards,
Peter Chen

      reply	other threads:[~2016-10-28  5:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-27 22:02 [RFC PATCH] usb: core: correct usb_get_dev() documentation Brian Norris
2016-10-27 23:49 ` Dmitry Torokhov
2016-10-28  5:05   ` Peter Chen [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=20161028050546.GA2393@b29397-desktop \
    --to=hzpeterchen@gmail.com \
    --cc=computersforpeace@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /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.