All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] USB: core: Remove usbfs_mutex
@ 2019-06-25 20:03 Alan Stern
  2019-06-26  2:30 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Alan Stern @ 2019-06-25 20:03 UTC (permalink / raw)
  To: Greg KH; +Cc: USB list

Commit 4a2a8a2cce86 ("usbfs: private mutex for open, release, and
remove") is now obsolete.  The commit was created back when we had
to handle both usbfs device nodes and the old usbdevfs filesystem
(/proc/bus/usb/), but usbdevfs no longer exists.

This means there's no longer any need to hold a mutex during two
separate removal operations (and thus during an entire notifier chain
call).  Furthermore, the one remaining remove/release pair doesn't
race with open thanks to the synchronization provided by the device
model core in bus_find_device().  Remove and release don't race with
each other because they both run with the device lock held.

The upshot is that usbfs_mutex isn't needed any more.  This patch
removes it entirely.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>

---


[as1904]


 drivers/usb/core/devio.c  |    9 ---------
 drivers/usb/core/notify.c |    3 ---
 drivers/usb/core/usb.h    |    1 -
 3 files changed, 13 deletions(-)

Index: usb-devel/drivers/usb/core/devio.c
===================================================================
--- usb-devel.orig/drivers/usb/core/devio.c
+++ usb-devel/drivers/usb/core/devio.c
@@ -48,9 +48,6 @@
 #define USB_DEVICE_MAX			(USB_MAXBUS * 128)
 #define USB_SG_SIZE			16384 /* split-size for large txs */
 
-/* Mutual exclusion for removal, open, and release */
-DEFINE_MUTEX(usbfs_mutex);
-
 struct usb_dev_state {
 	struct list_head list;      /* state list */
 	struct usb_device *dev;
@@ -979,15 +976,9 @@ static int usbdev_open(struct inode *ino
 
 	ret = -ENODEV;
 
-	/* Protect against simultaneous removal or release */
-	mutex_lock(&usbfs_mutex);
-
 	/* usbdev device-node */
 	if (imajor(inode) == USB_DEVICE_MAJOR)
 		dev = usbdev_lookup_by_devt(inode->i_rdev);
-
-	mutex_unlock(&usbfs_mutex);
-
 	if (!dev)
 		goto out_free_ps;
 
Index: usb-devel/drivers/usb/core/notify.c
===================================================================
--- usb-devel.orig/drivers/usb/core/notify.c
+++ usb-devel/drivers/usb/core/notify.c
@@ -53,11 +53,8 @@ void usb_notify_add_device(struct usb_de
 
 void usb_notify_remove_device(struct usb_device *udev)
 {
-	/* Protect against simultaneous usbfs open */
-	mutex_lock(&usbfs_mutex);
 	blocking_notifier_call_chain(&usb_notifier_list,
 			USB_DEVICE_REMOVE, udev);
-	mutex_unlock(&usbfs_mutex);
 }
 
 void usb_notify_add_bus(struct usb_bus *ubus)
Index: usb-devel/drivers/usb/core/usb.h
===================================================================
--- usb-devel.orig/drivers/usb/core/usb.h
+++ usb-devel/drivers/usb/core/usb.h
@@ -169,7 +169,6 @@ extern const struct attribute_group *usb
 extern const struct attribute_group *usb_interface_groups[];
 
 /* usbfs stuff */
-extern struct mutex usbfs_mutex;
 extern struct usb_driver usbfs_driver;
 extern const struct file_operations usbfs_devices_fops;
 extern const struct file_operations usbdev_file_operations;


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] USB: core: Remove usbfs_mutex
  2019-06-25 20:03 [PATCH] USB: core: Remove usbfs_mutex Alan Stern
@ 2019-06-26  2:30 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2019-06-26  2:30 UTC (permalink / raw)
  To: Alan Stern; +Cc: USB list

On Tue, Jun 25, 2019 at 04:03:58PM -0400, Alan Stern wrote:
> Commit 4a2a8a2cce86 ("usbfs: private mutex for open, release, and
> remove") is now obsolete.  The commit was created back when we had
> to handle both usbfs device nodes and the old usbdevfs filesystem
> (/proc/bus/usb/), but usbdevfs no longer exists.
> 
> This means there's no longer any need to hold a mutex during two
> separate removal operations (and thus during an entire notifier chain
> call).  Furthermore, the one remaining remove/release pair doesn't
> race with open thanks to the synchronization provided by the device
> model core in bus_find_device().  Remove and release don't race with
> each other because they both run with the device lock held.
> 
> The upshot is that usbfs_mutex isn't needed any more.  This patch
> removes it entirely.
> 
> Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
> 

Ah, nice, I forgot all about this mutex, thanks for removing it!

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-06-26  2:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-25 20:03 [PATCH] USB: core: Remove usbfs_mutex Alan Stern
2019-06-26  2:30 ` Greg KH

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.