public inbox for linux-wireless@vger.kernel.org
 help / color / mirror / Atom feed
From: Stanislaw Gruszka <stf_xl@wp.pl>
To: Johan Hovold <johan@kernel.org>
Cc: linux-wireless@vger.kernel.org,
	Brian Norris <briannorris@chromium.org>,
	Francesco Dolcini <francesco@dolcini.it>,
	Felix Fietkau <nbd@nbd.name>,
	Lorenzo Bianconi <lorenzo@kernel.org>,
	Ryder Lee <ryder.lee@mediatek.com>,
	Shayne Chen <shayne.chen@mediatek.com>,
	Sean Wang <sean.wang@mediatek.com>,
	Jakub Kicinski <kuba@kernel.org>,
	Hin-Tak Leung <hintak.leung@gmail.com>,
	Jes Sorensen <Jes.Sorensen@gmail.com>,
	Ping-Ke Shih <pkshih@realtek.com>,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Claudiu Beznea <claudiu.beznea@tuxon.dev>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	libertas-dev@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 10/13] wifi: rt2x00: drop redundant device reference
Date: Thu, 5 Mar 2026 14:37:55 +0100	[thread overview]
Message-ID: <20260305133755.GA75655@wp.pl> (raw)
In-Reply-To: <20260305110713.17725-11-johan@kernel.org>

On Thu, Mar 05, 2026 at 12:07:10PM +0100, Johan Hovold wrote:
> Driver core holds a reference to the USB interface and its parent USB
> device while the interface is bound to a driver and there is no need to
> take additional references unless the structures are needed after
> disconnect.
> 
> Drop the redundant device reference to reduce cargo culting, make it

Getting the reference in probe() and drop it in disconnect() was not a cargo cult.
That was requirement from usb_get_dev() comment, that later it was changed
by below commit:

commit f6a9a2d64dd168b7d71076c0e6b2be7db7cb7399
Author: Alan Stern <stern@rowland.harvard.edu>
Date:   Fri Feb 25 09:38:25 2022 -0500

    USB: core: Update kerneldoc for usb_get_dev() and usb_get_intf()

    The kerneldoc for usb_get_dev() and usb_get_intf() says that drivers
    should always refcount the references they hold for the usb_device or
    usb_interface structure, respectively.  But this is an overstatement:
    In many cases drivers do not access these references after they have
    been unbound, and in such cases refcounting is unnecessary.

    This patch updates the kerneldoc for the two routines, explaining when
    a driver does not need to increment and decrement the refcount.  This
    should help dispel misconceptions which might otherwise afflict
    programmers new to the USB subsystem.

    Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
    Link: https://lore.kernel.org/r/Yhjp4Rp9Alipmwtq@rowland.harvard.edu
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Regards
Stanislaw

> easier to spot drivers where an extra reference is needed, and reduce
> the risk of memory leaks when drivers fail to release it.
> 
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>  drivers/net/wireless/ralink/rt2x00/rt2x00usb.c | 12 +-----------
>  1 file changed, 1 insertion(+), 11 deletions(-)
> 
> diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
> index 54599cad78f9..83d00b6baf64 100644
> --- a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
> +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
> @@ -802,14 +802,12 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,
>  	struct rt2x00_dev *rt2x00dev;
>  	int retval;
>  
> -	usb_dev = usb_get_dev(usb_dev);
>  	usb_reset_device(usb_dev);
>  
>  	hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw);
>  	if (!hw) {
>  		rt2x00_probe_err("Failed to allocate hardware\n");
> -		retval = -ENOMEM;
> -		goto exit_put_device;
> +		return -ENOMEM;
>  	}
>  
>  	usb_set_intfdata(usb_intf, hw);
> @@ -851,10 +849,6 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,
>  
>  exit_free_device:
>  	ieee80211_free_hw(hw);
> -
> -exit_put_device:
> -	usb_put_dev(usb_dev);
> -
>  	usb_set_intfdata(usb_intf, NULL);
>  
>  	return retval;
> @@ -873,11 +867,7 @@ void rt2x00usb_disconnect(struct usb_interface *usb_intf)
>  	rt2x00usb_free_reg(rt2x00dev);
>  	ieee80211_free_hw(hw);
>  
> -	/*
> -	 * Free the USB device data.
> -	 */
>  	usb_set_intfdata(usb_intf, NULL);
> -	usb_put_dev(interface_to_usbdev(usb_intf));
>  }
>  EXPORT_SYMBOL_GPL(rt2x00usb_disconnect);
>  
> -- 
> 2.52.0
> 

  reply	other threads:[~2026-03-05 13:38 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-05 11:07 [PATCH 00/13] wifi: drop redundant USB device references Johan Hovold
2026-03-05 11:07 ` [PATCH 01/13] wifi: at76c50x: drop redundant device reference Johan Hovold
2026-03-05 11:07 ` [PATCH 02/13] wifi: libertas: " Johan Hovold
2026-03-05 11:07 ` [PATCH 03/13] wifi: libertas_tf: " Johan Hovold
2026-03-05 11:07 ` [PATCH 04/13] wifi: mwifiex: " Johan Hovold
2026-03-06  9:46   ` Francesco Dolcini
2026-03-05 11:07 ` [PATCH 05/13] wifi: mt76: " Johan Hovold
2026-03-05 11:07 ` [PATCH 06/13] wifi: mt76x0u: " Johan Hovold
2026-03-05 11:07 ` [PATCH 07/13] wifi: mt76x2u: " Johan Hovold
2026-03-05 11:07 ` [PATCH 08/13] wifi: mt76: mt792xu: " Johan Hovold
2026-03-05 11:07 ` [PATCH 09/13] wifi: mt7601u: " Johan Hovold
2026-03-05 11:07 ` [PATCH 10/13] wifi: rt2x00: " Johan Hovold
2026-03-05 13:37   ` Stanislaw Gruszka [this message]
2026-03-05 14:15     ` Johan Hovold
2026-03-05 16:52   ` Stanislaw Gruszka
2026-03-05 11:07 ` [PATCH 11/13] wifi: rtl818x: " Johan Hovold
2026-03-05 11:07 ` [PATCH 12/13] wifi: rtl8xxxu: " Johan Hovold
2026-03-05 11:07 ` [PATCH 13/13] wifi: rtlwifi: usb: " Johan Hovold
2026-03-06  1:40 ` [PATCH 00/13] wifi: drop redundant USB device references Ping-Ke Shih
2026-03-06  8:09   ` Johan Hovold
2026-03-06  9:04     ` Ping-Ke Shih
2026-03-06  9:34       ` Johan Hovold
2026-03-06  9:36         ` Ping-Ke Shih
2026-03-06  9:49       ` Greg Kroah-Hartman

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=20260305133755.GA75655@wp.pl \
    --to=stf_xl@wp.pl \
    --cc=Jes.Sorensen@gmail.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=briannorris@chromium.org \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=francesco@dolcini.it \
    --cc=hintak.leung@gmail.com \
    --cc=johan@kernel.org \
    --cc=kuba@kernel.org \
    --cc=libertas-dev@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=matthias.bgg@gmail.com \
    --cc=nbd@nbd.name \
    --cc=nicolas.ferre@microchip.com \
    --cc=pkshih@realtek.com \
    --cc=ryder.lee@mediatek.com \
    --cc=sean.wang@mediatek.com \
    --cc=shayne.chen@mediatek.com \
    /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