[PATCH 1/2] USB: apple-mfi-fastcharge: drop redundant device reference

Johan Hovold posted 2 patches 1 month ago
[PATCH 1/2] USB: apple-mfi-fastcharge: drop redundant device reference
Posted by Johan Hovold 1 month ago
Driver core holds a reference to the USB device while it is bound to a
driver and there is no need to take additional references unless the
structure is needed after disconnect.

Drop the redundant device reference to reduce cargo culting, make it
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/usb/misc/apple-mfi-fastcharge.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/usb/misc/apple-mfi-fastcharge.c b/drivers/usb/misc/apple-mfi-fastcharge.c
index 339f6cd2e9b2..af266e19f2fd 100644
--- a/drivers/usb/misc/apple-mfi-fastcharge.c
+++ b/drivers/usb/misc/apple-mfi-fastcharge.c
@@ -210,7 +210,7 @@ static int mfi_fc_probe(struct usb_device *udev)
 		goto err_free_name;
 	}
 
-	mfi->udev = usb_get_dev(udev);
+	mfi->udev = udev;
 	dev_set_drvdata(&udev->dev, mfi);
 
 	return 0;
@@ -231,7 +231,6 @@ static void mfi_fc_disconnect(struct usb_device *udev)
 		power_supply_unregister(mfi->battery);
 	kfree(mfi->battery_desc.name);
 	dev_set_drvdata(&udev->dev, NULL);
-	usb_put_dev(mfi->udev);
 	kfree(mfi);
 }
 
-- 
2.52.0
Re: [PATCH 1/2] USB: apple-mfi-fastcharge: drop redundant device reference
Posted by Bastien Nocera 1 month ago
On Thu, 2026-03-05 at 14:38 +0100, Johan Hovold wrote:
> Driver core holds a reference to the USB device while it is bound to
> a
> driver and there is no need to take additional references unless the
> structure is needed after disconnect.
> 
> Drop the redundant device reference to reduce cargo culting, make it
> 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>

Reviewed-by: Bastien Nocera <hadess@hadess.net>

> ---
>  drivers/usb/misc/apple-mfi-fastcharge.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/misc/apple-mfi-fastcharge.c
> b/drivers/usb/misc/apple-mfi-fastcharge.c
> index 339f6cd2e9b2..af266e19f2fd 100644
> --- a/drivers/usb/misc/apple-mfi-fastcharge.c
> +++ b/drivers/usb/misc/apple-mfi-fastcharge.c
> @@ -210,7 +210,7 @@ static int mfi_fc_probe(struct usb_device *udev)
>  		goto err_free_name;
>  	}
>  
> -	mfi->udev = usb_get_dev(udev);
> +	mfi->udev = udev;
>  	dev_set_drvdata(&udev->dev, mfi);
>  
>  	return 0;
> @@ -231,7 +231,6 @@ static void mfi_fc_disconnect(struct usb_device
> *udev)
>  		power_supply_unregister(mfi->battery);
>  	kfree(mfi->battery_desc.name);
>  	dev_set_drvdata(&udev->dev, NULL);
> -	usb_put_dev(mfi->udev);
>  	kfree(mfi);
>  }
>