diff options
author | Paul Gortmaker <paul.gortmaker@windriver.com> | 2011-02-07 00:46:55 -0500 |
---|---|---|
committer | Paul Gortmaker <paul.gortmaker@windriver.com> | 2011-02-07 00:46:55 -0500 |
commit | 85dcfa5c67cbdd74844fc92601c1a78acf0c4abd (patch) | |
tree | bcd566abe4544198032df341045780057ec962a1 | |
parent | 51312a113ecfa9d69524cd2ec4d13752efe4a3ff (diff) | |
download | rt-patches-85dcfa5c67cbdd74844fc92601c1a78acf0c4abd.tar.gz |
rewrite/scrap dev-sem-to-mutex patch
Upstream 8e9394ce2412254ec69fd2a4f3e44a66eade2297 has abstracted out
all the users, so the conversion is now largely in just one place.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
-rw-r--r-- | drivers-base-Convert-dev-sem-to-mutex.patch | 490 |
1 files changed, 29 insertions, 461 deletions
diff --git a/drivers-base-Convert-dev-sem-to-mutex.patch b/drivers-base-Convert-dev-sem-to-mutex.patch index 89a91cf..677f6dc 100644 --- a/drivers-base-Convert-dev-sem-to-mutex.patch +++ b/drivers-base-Convert-dev-sem-to-mutex.patch @@ -1,78 +1,20 @@ -From 14e60eebb854c1f3843475b11a7c2a995e054d02 Mon Sep 17 00:00:00 2001 +From 8dbc7a12cfa50a6a9d0c86f1dcf520682446039c Mon Sep 17 00:00:00 2001 From: Thomas Gleixner <tglx@linutronix.de> Date: Sun, 26 Jul 2009 00:11:46 +0200 Subject: [PATCH] drivers/base: Convert dev->sem to mutex commit 97dd538e3998fcada84d8106a4d974fdab729cb1 in tip. -The semaphore is used as mutex so make it a mutex. Clean up all -users outside of drivers/base as well. +The semaphore is used as mutex so make it a mutex. + +[PG: upstream abstraction of all users in 8e9394ce2412 drastically + reduces the footprint of this vs. the original tip commit.] Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> -diff --git a/drivers/base/bus.c b/drivers/base/bus.c -index c0c5a43..9d1a0b1 100644 ---- a/drivers/base/bus.c -+++ b/drivers/base/bus.c -@@ -173,10 +173,10 @@ static ssize_t driver_unbind(struct device_driver *drv, - dev = bus_find_device_by_name(bus, NULL, buf); - if (dev && dev->driver == drv) { - if (dev->parent) /* Needed for USB */ -- down(&dev->parent->sem); -+ mutex_lock(&dev->parent->mutex); - device_release_driver(dev); - if (dev->parent) -- up(&dev->parent->sem); -+ mutex_unlock(&dev->parent->mutex); - err = count; - } - put_device(dev); -@@ -200,12 +200,12 @@ static ssize_t driver_bind(struct device_driver *drv, - dev = bus_find_device_by_name(bus, NULL, buf); - if (dev && dev->driver == NULL && driver_match_device(drv, dev)) { - if (dev->parent) /* Needed for USB */ -- down(&dev->parent->sem); -- down(&dev->sem); -+ mutex_lock(&dev->parent->mutex); -+ mutex_lock(&dev->mutex); - err = driver_probe_device(drv, dev); -- up(&dev->sem); -+ mutex_unlock(&dev->mutex); - if (dev->parent) -- up(&dev->parent->sem); -+ mutex_unlock(&dev->parent->mutex); - - if (err > 0) { - /* success */ -@@ -744,10 +744,10 @@ static int __must_check bus_rescan_devices_helper(struct device *dev, - - if (!dev->driver) { - if (dev->parent) /* Needed for USB */ -- down(&dev->parent->sem); -+ mutex_lock(&dev->parent->mutex); - ret = device_attach(dev); - if (dev->parent) -- up(&dev->parent->sem); -+ mutex_unlock(&dev->parent->mutex); - } - return ret < 0 ? ret : 0; - } -@@ -779,10 +779,10 @@ int device_reprobe(struct device *dev) - { - if (dev->driver) { - if (dev->parent) /* Needed for USB */ -- down(&dev->parent->sem); -+ mutex_lock(&dev->parent->mutex); - device_release_driver(dev); - if (dev->parent) -- up(&dev->parent->sem); -+ mutex_unlock(&dev->parent->mutex); - } - return bus_rescan_devices_helper(dev, NULL); - } diff --git a/drivers/base/core.c b/drivers/base/core.c -index 2820257..004302c 100644 +index ef55df3..09c10e9 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -20,7 +20,6 @@ @@ -83,7 +25,7 @@ index 2820257..004302c 100644 #include <linux/mutex.h> #include <linux/async.h> -@@ -564,7 +563,7 @@ void device_initialize(struct device *dev) +@@ -559,7 +558,7 @@ void device_initialize(struct device *dev) dev->kobj.kset = devices_kset; kobject_init(&dev->kobj, &device_ktype); INIT_LIST_HEAD(&dev->dma_pools); @@ -92,377 +34,8 @@ index 2820257..004302c 100644 spin_lock_init(&dev->devres_lock); INIT_LIST_HEAD(&dev->devres_head); device_init_wakeup(dev, 0); -diff --git a/drivers/base/dd.c b/drivers/base/dd.c -index ee95c76..45c092e 100644 ---- a/drivers/base/dd.c -+++ b/drivers/base/dd.c -@@ -85,7 +85,7 @@ static void driver_sysfs_remove(struct device *dev) - * for before calling this. (It is ok to call with no other effort - * from a driver's probe() method.) - * -- * This function must be called with @dev->sem held. -+ * This function must be called with @dev->mutex held. - */ - int device_bind_driver(struct device *dev) - { -@@ -190,8 +190,8 @@ EXPORT_SYMBOL_GPL(wait_for_device_probe); - * This function returns -ENODEV if the device is not registered, - * 1 if the device is bound successfully and 0 otherwise. - * -- * This function must be called with @dev->sem held. When called for a -- * USB interface, @dev->parent->sem must be held as well. -+ * This function must be called with @dev->mutex held. When called for a -+ * USB interface, @dev->parent->mutex must be held as well. - */ - int driver_probe_device(struct device_driver *drv, struct device *dev) - { -@@ -233,13 +233,13 @@ static int __device_attach(struct device_driver *drv, void *data) - * 0 if no matching driver was found; - * -ENODEV if the device is not registered. - * -- * When called for a USB interface, @dev->parent->sem must be held. -+ * When called for a USB interface, @dev->parent->mutex must be held. - */ - int device_attach(struct device *dev) - { - int ret = 0; - -- down(&dev->sem); -+ mutex_lock(&dev->mutex); - if (dev->driver) { - ret = device_bind_driver(dev); - if (ret == 0) -@@ -253,7 +253,7 @@ int device_attach(struct device *dev) - ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach); - pm_runtime_put_sync(dev); - } -- up(&dev->sem); -+ mutex_unlock(&dev->mutex); - return ret; - } - EXPORT_SYMBOL_GPL(device_attach); -@@ -276,13 +276,13 @@ static int __driver_attach(struct device *dev, void *data) - return 0; - - if (dev->parent) /* Needed for USB */ -- down(&dev->parent->sem); -- down(&dev->sem); -+ mutex_lock(&dev->parent->mutex); -+ mutex_lock(&dev->mutex); - if (!dev->driver) - driver_probe_device(drv, dev); -- up(&dev->sem); -+ mutex_unlock(&dev->mutex); - if (dev->parent) -- up(&dev->parent->sem); -+ mutex_unlock(&dev->parent->mutex); - - return 0; - } -@@ -303,8 +303,8 @@ int driver_attach(struct device_driver *drv) - EXPORT_SYMBOL_GPL(driver_attach); - - /* -- * __device_release_driver() must be called with @dev->sem held. -- * When called for a USB interface, @dev->parent->sem must be held as well. -+ * __device_release_driver() must be called with @dev->mutex held. -+ * When called for a USB interface, @dev->parent->mutex must be held as well. - */ - static void __device_release_driver(struct device *dev) - { -@@ -343,7 +343,7 @@ static void __device_release_driver(struct device *dev) - * @dev: device. - * - * Manually detach device from driver. -- * When called for a USB interface, @dev->parent->sem must be held. -+ * When called for a USB interface, @dev->parent->mutex must be held. - */ - void device_release_driver(struct device *dev) - { -@@ -352,9 +352,9 @@ void device_release_driver(struct device *dev) - * within their ->remove callback for the same device, they - * will deadlock right here. - */ -- down(&dev->sem); -+ mutex_lock(&dev->mutex); - __device_release_driver(dev); -- up(&dev->sem); -+ mutex_unlock(&dev->mutex); - } - EXPORT_SYMBOL_GPL(device_release_driver); - -@@ -381,13 +381,13 @@ void driver_detach(struct device_driver *drv) - spin_unlock(&drv->p->klist_devices.k_lock); - - if (dev->parent) /* Needed for USB */ -- down(&dev->parent->sem); -- down(&dev->sem); -+ mutex_lock(&dev->parent->mutex); -+ mutex_lock(&dev->mutex); - if (dev->driver == drv) - __device_release_driver(dev); -- up(&dev->sem); -+ mutex_unlock(&dev->mutex); - if (dev->parent) -- up(&dev->parent->sem); -+ mutex_unlock(&dev->parent->mutex); - put_device(dev); - } - } -diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c -index 0e26a6f..c3b06e4 100644 ---- a/drivers/base/power/main.c -+++ b/drivers/base/power/main.c -@@ -35,8 +35,8 @@ - * because children are guaranteed to be discovered after parents, and - * are inserted at the back of the list on discovery. - * -- * Since device_pm_add() may be called with a device semaphore held, -- * we must never try to acquire a device semaphore while holding -+ * Since device_pm_add() may be called with a device mutex held, -+ * we must never try to acquire a device mutex while holding - * dpm_list_mutex. - */ - -@@ -508,7 +508,7 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) - TRACE_RESUME(0); - - dpm_wait(dev->parent, async); -- down(&dev->sem); -+ mutex_lock(&dev->mutex); - - dev->power.status = DPM_RESUMING; - -@@ -543,7 +543,7 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) - } - } - End: -- up(&dev->sem); -+ mutex_unlock(&dev->mutex); - complete_all(&dev->power.completion); - - TRACE_RESUME(error); -@@ -629,7 +629,7 @@ static void dpm_resume(pm_message_t state) - */ - static void device_complete(struct device *dev, pm_message_t state) - { -- down(&dev->sem); -+ mutex_lock(&dev->mutex); - - if (dev->class && dev->class->pm && dev->class->pm->complete) { - pm_dev_dbg(dev, state, "completing class "); -@@ -646,7 +646,7 @@ static void device_complete(struct device *dev, pm_message_t state) - dev->bus->pm->complete(dev); - } - -- up(&dev->sem); -+ mutex_unlock(&dev->mutex); - } - - /** -@@ -809,7 +809,7 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) - int error = 0; - - dpm_wait_for_children(dev, async); -- down(&dev->sem); -+ mutex_lock(&dev->mutex); - - if (async_error) - goto End; -@@ -849,7 +849,7 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) - dev->power.status = DPM_OFF; - - End: -- up(&dev->sem); -+ mutex_unlock(&dev->mutex); - complete_all(&dev->power.completion); - - return error; -@@ -938,7 +938,7 @@ static int device_prepare(struct device *dev, pm_message_t state) - { - int error = 0; - -- down(&dev->sem); -+ mutex_lock(&dev->mutex); - - if (dev->bus && dev->bus->pm && dev->bus->pm->prepare) { - pm_dev_dbg(dev, state, "preparing "); -@@ -962,7 +962,7 @@ static int device_prepare(struct device *dev, pm_message_t state) - suspend_report_result(dev->class->pm->prepare, error); - } - End: -- up(&dev->sem); -+ mutex_unlock(&dev->mutex); - - return error; - } -diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c -index 9d0dfcb..b090e6e 100644 ---- a/drivers/firewire/core-device.c -+++ b/drivers/firewire/core-device.c -@@ -762,9 +762,9 @@ static int update_unit(struct device *dev, void *data) - struct fw_driver *driver = (struct fw_driver *)dev->driver; - - if (is_fw_unit(dev) && driver != NULL && driver->update != NULL) { -- down(&dev->sem); -+ mutex_lock(&dev->mutex); - driver->update(unit); -- up(&dev->sem); -+ mutex_unlock(&dev->mutex); - } - - return 0; -diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c -index 5122b5a..bcc3d32 100644 ---- a/drivers/ieee1394/nodemgr.c -+++ b/drivers/ieee1394/nodemgr.c -@@ -1397,9 +1397,9 @@ static int update_pdrv(struct device *dev, void *data) - pdrv = container_of(drv, struct hpsb_protocol_driver, - driver); - if (pdrv->update) { -- down(&ud->device.sem); -+ mutex_lock(&ud->device.mutex); - error = pdrv->update(ud); -- up(&ud->device.sem); -+ mutex_unlock(&ud->device.mutex); - } - if (error) - device_release_driver(&ud->device); -diff --git a/drivers/net/mlx4/mlx4.h b/drivers/net/mlx4/mlx4.h -index bc72d6e..13343e8 100644 ---- a/drivers/net/mlx4/mlx4.h -+++ b/drivers/net/mlx4/mlx4.h -@@ -40,6 +40,7 @@ - #include <linux/mutex.h> - #include <linux/radix-tree.h> - #include <linux/timer.h> -+#include <linux/semaphore.h> - #include <linux/workqueue.h> - - #include <linux/mlx4/device.h> -diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c -index 712250f..b7cf072 100644 ---- a/drivers/pci/bus.c -+++ b/drivers/pci/bus.c -@@ -288,9 +288,9 @@ void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *), - next = dev->bus_list.next; - - /* Run device routines with the device locked */ -- down(&dev->dev.sem); -+ mutex_lock(&dev->dev.mutex); - retval = cb(dev, userdata); -- up(&dev->dev.sem); -+ mutex_unlock(&dev->dev.mutex); - if (retval) - break; - } -diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c -index 2b9ac9e..afec84c 100644 ---- a/drivers/pci/pci.c -+++ b/drivers/pci/pci.c -@@ -2443,7 +2443,7 @@ static int pci_dev_reset(struct pci_dev *dev, int probe) - if (!probe) { - pci_block_user_cfg_access(dev); - /* block PM suspend, driver probe, etc. */ -- down(&dev->dev.sem); -+ mutex_lock(&dev->dev.mutex); - } - - rc = pci_dev_specific_reset(dev, probe); -@@ -2465,7 +2465,7 @@ static int pci_dev_reset(struct pci_dev *dev, int probe) - rc = pci_parent_bus_reset(dev, probe); - done: - if (!probe) { -- up(&dev->dev.sem); -+ mutex_unlock(&dev->dev.mutex); - pci_unblock_user_cfg_access(dev); - } - -diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c -index 0f98be4..09a047f 100644 ---- a/drivers/pcmcia/ds.c -+++ b/drivers/pcmcia/ds.c -@@ -971,9 +971,9 @@ static int runtime_suspend(struct device *dev) - { - int rc; - -- down(&dev->sem); -+ mutex_lock(&dev->mutex); - rc = pcmcia_dev_suspend(dev, PMSG_SUSPEND); -- up(&dev->sem); -+ mutex_unlock(&dev->mutex); - return rc; - } - -@@ -981,9 +981,9 @@ static int runtime_resume(struct device *dev) - { - int rc; - -- down(&dev->sem); -+ mutex_lock(&dev->mutex); - rc = pcmcia_dev_resume(dev); -- up(&dev->sem); -+ mutex_unlock(&dev->mutex); - return rc; - } - -diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c -index f2f055e..7e6ddb5 100644 ---- a/drivers/usb/core/driver.c -+++ b/drivers/usb/core/driver.c -@@ -470,10 +470,10 @@ void usb_driver_release_interface(struct usb_driver *driver, - if (device_is_registered(dev)) { - device_release_driver(dev); - } else { -- down(&dev->sem); -+ mutex_lock(&dev->mutex); - usb_unbind_interface(dev); - dev->driver = NULL; -- up(&dev->sem); -+ mutex_unlock(&dev->mutex); - } - } - EXPORT_SYMBOL_GPL(usb_driver_release_interface); -diff --git a/drivers/uwb/umc-bus.c b/drivers/uwb/umc-bus.c -index cdd6c8e..f063451 100644 ---- a/drivers/uwb/umc-bus.c -+++ b/drivers/uwb/umc-bus.c -@@ -62,12 +62,12 @@ int umc_controller_reset(struct umc_dev *umc) - struct device *parent = umc->dev.parent; - int ret = 0; - -- if(down_trylock(&parent->sem)) -+ if (!mutex_trylock(&parent->mutex)) - return -EAGAIN; - ret = device_for_each_child(parent, parent, umc_bus_pre_reset_helper); - if (ret >= 0) - ret = device_for_each_child(parent, parent, umc_bus_post_reset_helper); -- up(&parent->sem); -+ mutex_unlock(&parent->mutex); - - return ret; - } -diff --git a/drivers/uwb/uwb-internal.h b/drivers/uwb/uwb-internal.h -index d5bcfc1..17b10b9 100644 ---- a/drivers/uwb/uwb-internal.h -+++ b/drivers/uwb/uwb-internal.h -@@ -366,12 +366,12 @@ struct dentry *uwb_dbg_create_pal_dir(struct uwb_pal *pal); - - static inline void uwb_dev_lock(struct uwb_dev *uwb_dev) - { -- down(&uwb_dev->dev.sem); -+ mutex_lock(&uwb_dev->dev.mutex); - } - - static inline void uwb_dev_unlock(struct uwb_dev *uwb_dev) - { -- up(&uwb_dev->dev.sem); -+ mutex_unlock(&uwb_dev->dev.mutex); - } - - #endif /* #ifndef __UWB_INTERNAL_H__ */ diff --git a/include/linux/device.h b/include/linux/device.h -index b30527d..61011f9 100644 +index 1821928..d0fd2b4 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -22,7 +22,6 @@ @@ -473,16 +46,7 @@ index b30527d..61011f9 100644 #include <asm/atomic.h> #include <asm/device.h> -@@ -106,7 +105,7 @@ extern int bus_unregister_notifier(struct bus_type *bus, - - /* All 4 notifers below get called with the target struct device * - * as an argument. Note that those functions are likely to be called -- * with the device semaphore held in the core, so be careful. -+ * with the device mutex held in the core, so be careful. - */ - #define BUS_NOTIFY_ADD_DEVICE 0x00000001 /* device added */ - #define BUS_NOTIFY_DEL_DEVICE 0x00000002 /* device removed */ -@@ -385,7 +384,7 @@ struct device { +@@ -404,7 +403,7 @@ struct device { const char *init_name; /* initial name of the device */ struct device_type *type; @@ -491,23 +55,27 @@ index b30527d..61011f9 100644 * its driver. */ -diff --git a/include/linux/usb.h b/include/linux/usb.h -index 332eaea..f559335 100644 ---- a/include/linux/usb.h -+++ b/include/linux/usb.h -@@ -528,9 +528,9 @@ extern struct usb_device *usb_get_dev(struct usb_device *dev); - extern void usb_put_dev(struct usb_device *dev); +@@ -510,17 +509,17 @@ static inline bool device_async_suspend_enabled(struct device *dev) + + static inline void device_lock(struct device *dev) + { +- down(&dev->sem); ++ mutex_lock(&dev->mutex); + } + + static inline int device_trylock(struct device *dev) + { +- return down_trylock(&dev->sem); ++ return !mutex_trylock(&dev->mutex); + } - /* USB device locking */ --#define usb_lock_device(udev) down(&(udev)->dev.sem) --#define usb_unlock_device(udev) up(&(udev)->dev.sem) --#define usb_trylock_device(udev) down_trylock(&(udev)->dev.sem) -+#define usb_lock_device(udev) mutex_lock(&(udev)->dev.mutex) -+#define usb_unlock_device(udev) mutex_unlock(&(udev)->dev.mutex) -+#define usb_trylock_device(udev) mutex_trylock(&(udev)->dev.mutex) - extern int usb_lock_device_for_reset(struct usb_device *udev, - const struct usb_interface *iface); + static inline void device_unlock(struct device *dev) + { +- up(&dev->sem); ++ mutex_unlock(&dev->mutex); + } + void driver_init(void); -- -1.7.1 +1.7.1.1 |