USB: drop redundant references
cover USB: drop redundant references
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 redundant references 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 them.
Johan
Johan Hovold (5):
USB: cypress_cy7c63: drop redundant device reference
USB: cytherm: drop redundant device reference
USB: ljca: drop redundant interface reference
USB: trancevibrator: drop redundant device reference
USB: usbsevseg: drop redundant device reference
drivers/usb/misc/cypress_cy7c63.c | 4 +--- drivers/usb/misc/cytherm.c | 4 +--- drivers/usb/misc/trancevibrator.c | 3 +-- drivers/usb/misc/usb-ljca.c | 15 +++++---------- drivers/usb/misc/usbsevseg.c | 3 +-- 5 files changed, 9 insertions(+), 20 deletions(-)
Signature · 1 line
2.52.0
PATCH 1/5 USB: cypress_cy7c63: drop redundant device reference
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 easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.
--- drivers/usb/misc/cypress_cy7c63.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/usb/misc/cypress_cy7c63.c +1 -3
@@ -215,7 +215,7 @@ static int cypress_probe(struct usb_interface *interface,if (!dev) goto error_mem; - dev->udev =usb_get_dev (interface_to_usbdev (interface)); + dev->udev =interface_to_usbdev (interface);/* save our data pointer in this interface device */ usb_set_intfdata (interface, dev);
@@ -239,8 +239,6 @@ static void cypress_disconnect(struct usb_interface *interface)* device files have been removed */ usb_set_intfdata (interface,NULL ); -usb_put_dev (dev->udev); -dev_info (&interface->dev,"Cypress CY7C63xxx device now disconnected\n" );
Signature · 1 line
2.52.0
PATCH 2/5 USB: cytherm: drop redundant device reference
In reply to Johan HovoldDriver 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 easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.
--- drivers/usb/misc/cytherm.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/usb/misc/cytherm.c +1 -3
@@ -311,7 +311,7 @@ static int cytherm_probe(struct usb_interface *interface,if (!dev) goto error_mem; - dev->udev =usb_get_dev (udev); + dev->udev = udev;usb_set_intfdata (interface, dev);
@@ -334,8 +334,6 @@ static void cytherm_disconnect(struct usb_interface *interface)/* first remove the files, then NULL the pointer */ usb_set_intfdata (interface,NULL ); -usb_put_dev (dev->udev); -kfree (dev);dev_info (&interface->dev,"Cypress thermometer now disconnected\n" );
Signature · 1 line
2.52.0
PATCH 3/5 USB: ljca: drop redundant interface reference
In reply to Johan HovoldDriver core holds a reference to the USB interface while it is bound to a driver and there is no need to take another reference unless the interface is needed after disconnect.
Drop the redundant interface 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.
--- drivers/usb/misc/usb-ljca.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/usb/misc/usb-ljca.c +5 -10
@@ -776,7 +776,7 @@ static int ljca_probe(struct usb_interface *interface,init_completion (&adap->cmd_completion);INIT_LIST_HEAD (&adap->client_list); - adap->intf =usb_get_intf (interface); + adap->intf = interface; adap->usb_dev = usb_dev; adap->dev = dev;
@@ -787,7 +787,7 @@ static int ljca_probe(struct usb_interface *interface, ret =usb_find_common_endpoints (alt, &ep_in, &ep_out,NULL ,NULL );if (ret) {dev_err (dev,"bulk endpoints not found\n" ); - goto err_put; + goto err_destroy_mutex; } adap->rx_pipe =usb_rcvbulkpipe (usb_dev,usb_endpoint_num (ep_in)); adap->tx_pipe =usb_sndbulkpipe (usb_dev,usb_endpoint_num (ep_out));
@@ -797,14 +797,14 @@ static int ljca_probe(struct usb_interface *interface, adap->rx_buf =devm_kzalloc (dev, adap->rx_len,GFP_KERNEL );if (!adap->rx_buf) { ret = -ENOMEM ; - goto err_put; + goto err_destroy_mutex; }/* alloc rx urb */ adap->rx_urb =usb_alloc_urb (0 ,GFP_KERNEL );if (!adap->rx_urb) { ret = -ENOMEM ; - goto err_put; + goto err_destroy_mutex; }usb_fill_bulk_urb (adap->rx_urb, usb_dev, adap->rx_pipe, adap->rx_buf, adap->rx_len, ljca_recv, adap);
@@ -836,10 +836,7 @@ static int ljca_probe(struct usb_interface *interface, err_free:usb_free_urb (adap->rx_urb); - -err_put: -usb_put_intf (adap->intf); - +err_destroy_mutex:mutex_destroy (&adap->mutex);return ret;
@@ -864,8 +861,6 @@ static void ljca_disconnect(struct usb_interface *interface)usb_free_urb (adap->rx_urb); -usb_put_intf (adap->intf); -mutex_destroy (&adap->mutex); }
Signature · 1 line
2.52.0
PATCH 4/5 USB: trancevibrator: drop redundant device reference
In reply to Johan HovoldDriver 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 easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.
--- drivers/usb/misc/trancevibrator.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/usb/misc/trancevibrator.c +1 -2
@@ -92,7 +92,7 @@ static int tv_probe(struct usb_interface *interface, goto error; } - dev->udev =usb_get_dev (udev); + dev->udev = udev;usb_set_intfdata (interface, dev);return 0 ;
@@ -108,7 +108,6 @@ static void tv_disconnect(struct usb_interface *interface) dev =usb_get_intfdata (interface);usb_set_intfdata (interface,NULL ); -usb_put_dev (dev->udev);kfree (dev); }
Signature · 1 line
2.52.0
PATCH 5/5 USB: usbsevseg: drop redundant device reference
In reply to Johan HovoldDriver 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 easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.
--- drivers/usb/misc/usbsevseg.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/usb/misc/usbsevseg.c +1 -2
@@ -312,7 +312,7 @@ static int sevseg_probe(struct usb_interface *interface,if (!mydev) goto error_mem; - mydev->udev =usb_get_dev (udev); + mydev->udev = udev; mydev->intf = interface;usb_set_intfdata (interface, mydev);
@@ -338,7 +338,6 @@ static void sevseg_disconnect(struct usb_interface *interface) mydev =usb_get_intfdata (interface);usb_set_intfdata (interface,NULL ); -usb_put_dev (mydev->udev);kfree (mydev);dev_info (&interface->dev,"USB 7 Segment now disconnected\n" ); }
Signature · 1 line
2.52.0
Re: [PATCH 3/5] USB: ljca: drop redundant interface reference
In reply to Johan HovoldHi Johan,
Thanks for the patch.
Quoted 9 lines · Johan Hovold
Driver core holds a reference to the USB interface while it is bound to a driver and there is no need to take another reference unless the interface is needed after disconnect.
Drop the redundant interface 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 <[email protected]>
Signature · 3 lines
Kind regards, Sakari Ailus