linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Salah Triki <salah.triki@gmail.com>
To: Marcel Holtmann <marcel@holtmann.org>
Cc: Johan Hedberg <johan.hedberg@gmail.com>,
	Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	open list <linux-kernel@vger.kernel.org>,
	Alan Stern <stern@rowland.harvard.edu>,
	Oliver Neukum <oliver@neukum.org>
Subject: Re: [PATCH v2] bluetooth: bcm203x: update the reference count of udev
Date: Mon, 2 Aug 2021 20:34:11 +0100	[thread overview]
Message-ID: <20210802193411.GA1006176@pc> (raw)
In-Reply-To: <9B2209B6-D371-432B-A3F5-F1CD7C7967A3@holtmann.org>

On Sun, Aug 01, 2021 at 08:01:06PM +0200, Marcel Holtmann wrote:
> Hi Salah,
> 
> > Use usb_get_dev() to increment the reference count of the usb device
> > structure in order to avoid releasing the structure while it is still in
> > use. And use usb_put_dev() to decrement the reference count and thus,
> > when it will be equal to 0 the structure will be released.
> > 
> > Signed-off-by: Salah Triki <salah.triki@gmail.com>
> > ---
> > Change since v1:
> > 	Modification of the description
> > 
> > drivers/bluetooth/bcm203x.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/bluetooth/bcm203x.c b/drivers/bluetooth/bcm203x.c
> > index e667933c3d70..547d35425d70 100644
> > --- a/drivers/bluetooth/bcm203x.c
> > +++ b/drivers/bluetooth/bcm203x.c
> > @@ -166,7 +166,7 @@ static int bcm203x_probe(struct usb_interface *intf, const struct usb_device_id
> > 	if (!data)
> > 		return -ENOMEM;
> > 
> > -	data->udev  = udev;
> > +	data->udev  = usb_get_dev(udev);
> > 	data->state = BCM203X_LOAD_MINIDRV;
> > 
> > 	data->urb = usb_alloc_urb(0, GFP_KERNEL);
> > @@ -244,6 +244,8 @@ static void bcm203x_disconnect(struct usb_interface *intf)
> > 
> > 	usb_set_intfdata(intf, NULL);
> > 
> > +	usb_put_dev(data->udev);
> > +
> > 	usb_free_urb(data->urb);
> > 	kfree(data->fw_data);
> > 	kfree(data->buffer);
> 
> I do not understand this. If this is something broken, then it is broken in
> btusb.c as well and that driver is heavily used by all sorts of devices. So
> we should have seen bug reports about this.
> 
> Regards
> 
> Marcel
> 
Hi Marcel,

The patch is based on the following documentation of usb_get_dev():

[quote]
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.
[/quote]

Regards

Salah

  reply	other threads:[~2021-08-02 19:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-31 15:41 [PATCH v2] bluetooth: bcm203x: update the reference count of udev Salah Triki
2021-08-01 18:01 ` Marcel Holtmann
2021-08-02 19:34   ` Salah Triki [this message]
2021-08-02 20:16     ` Alan Stern

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=20210802193411.GA1006176@pc \
    --to=salah.triki@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan.hedberg@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    --cc=oliver@neukum.org \
    --cc=stern@rowland.harvard.edu \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).