Commit 97dd538e authored by Thomas Gleixner's avatar Thomas Gleixner

drivers/base: Convert dev->sem to mutex

The semaphore is used as mutex so make it a mutex. Clean up all
users outside of drivers/base as well.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 37be6ed9
......@@ -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 */
......@@ -742,10 +742,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;
}
......@@ -777,10 +777,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);
}
......
......@@ -20,7 +20,6 @@
#include <linux/notifier.h>
#include <linux/genhd.h>
#include <linux/kallsyms.h>
#include <linux/semaphore.h>
#include <linux/mutex.h>
#include <linux/async.h>
......@@ -550,7 +549,7 @@ void device_initialize(struct device *dev)
dev->kobj.kset = devices_kset;
kobject_init(&dev->kobj, &device_ktype);
INIT_LIST_HEAD(&dev->dma_pools);
init_MUTEX(&dev->sem);
mutex_init(&dev->mutex);
spin_lock_init(&dev->devres_lock);
INIT_LIST_HEAD(&dev->devres_head);
device_init_wakeup(dev, 0);
......
......@@ -84,7 +84,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)
{
......@@ -189,8 +189,8 @@ EXPORT_SYMBOL_GPL(wait_for_device_probe);
* This function returns -ENODEV if the device is not registered,
* 1 if the device is bound sucessfully 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)
{
......@@ -229,13 +229,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)
......@@ -247,7 +247,7 @@ int device_attach(struct device *dev)
} else {
ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach);
}
up(&dev->sem);
mutex_unlock(&dev->mutex);
return ret;
}
EXPORT_SYMBOL_GPL(device_attach);
......@@ -270,13 +270,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;
}
......@@ -297,8 +297,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)
{
......@@ -332,7 +332,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)
{
......@@ -341,9 +341,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);
......@@ -370,13 +370,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);
}
}
......@@ -33,8 +33,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.
*/
......@@ -381,7 +381,7 @@ static int device_resume(struct device *dev, pm_message_t state)
TRACE_DEVICE(dev);
TRACE_RESUME(0);
down(&dev->sem);
mutex_lock(&dev->mutex);
if (dev->bus) {
if (dev->bus->pm) {
......@@ -414,7 +414,7 @@ static int device_resume(struct device *dev, pm_message_t state)
}
}
End:
up(&dev->sem);
mutex_unlock(&dev->mutex);
TRACE_RESUME(error);
return error;
......@@ -468,7 +468,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 ");
......@@ -485,7 +485,7 @@ static void device_complete(struct device *dev, pm_message_t state)
dev->bus->pm->complete(dev);
}
up(&dev->sem);
mutex_unlock(&dev->mutex);
}
/**
......@@ -619,7 +619,7 @@ static int device_suspend(struct device *dev, pm_message_t state)
{
int error = 0;
down(&dev->sem);
mutex_lock(&dev->mutex);
if (dev->class) {
if (dev->class->pm) {
......@@ -654,7 +654,7 @@ static int device_suspend(struct device *dev, pm_message_t state)
}
}
End:
up(&dev->sem);
mutex_unlock(&dev->mutex);
return error;
}
......@@ -705,7 +705,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 ");
......@@ -729,7 +729,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;
}
......
......@@ -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;
......
......@@ -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);
......
......@@ -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>
......
......@@ -240,9 +240,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;
}
......
......@@ -2211,7 +2211,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 = pcie_flr(dev, probe);
......@@ -2229,7 +2229,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);
}
......
......@@ -1082,9 +1082,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;
}
......@@ -1092,9 +1092,9 @@ static void 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);
}
/************************ per-device sysfs output ***************************/
......
......@@ -391,10 +391,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);
......
......@@ -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)
device_for_each_child(parent, parent, umc_bus_post_reset_helper);
up(&parent->sem);
mutex_unlock(&parent->mutex);
return ret;
}
......
......@@ -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__ */
......@@ -21,7 +21,6 @@
#include <linux/types.h>
#include <linux/module.h>
#include <linux/pm.h>
#include <linux/semaphore.h>
#include <asm/atomic.h>
#include <asm/device.h>
......@@ -105,7 +104,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 */
......@@ -373,7 +372,7 @@ struct device {
const char *init_name; /* initial name of the device */
struct device_type *type;
struct semaphore sem; /* semaphore to synchronize calls to
struct mutex mutex; /* mutex to synchronize calls to
* its driver.
*/
......
......@@ -529,9 +529,9 @@ extern struct usb_device *usb_get_dev(struct usb_device *dev);
extern void usb_put_dev(struct usb_device *dev);
/* 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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment