aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2010-02-17 13:57:05 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2010-03-07 20:04:52 -0500
commit8e9394ce2412254ec69fd2a4f3e44a66eade2297 (patch)
tree355f25148b4ce3f5cfebeaf0939d71cb6beaf88b /include
parent62e877b893e6350c900d381f353aa62ed48dcc97 (diff)
Driver core: create lock/unlock functions for struct device
In the future, we are going to be changing the lock type for struct device (once we get the lockdep infrastructure properly worked out) To make that changeover easier, and to possibly burry the lock in a different part of struct device, let's create some functions to lock and unlock a device so that no out-of-core code needs to be changed in the future. This patch creates the device_lock/unlock/trylock() functions, and converts all in-tree users to them. Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Jean Delvare <khali@linux-fr.org> Cc: Dave Young <hidave.darkstar@gmail.com> Cc: Ming Lei <tom.leiming@gmail.com> Cc: Jiri Kosina <jkosina@suse.cz> Cc: Phil Carmody <ext-phil.2.carmody@nokia.com> Cc: Arjan van de Ven <arjan@linux.intel.com> Cc: Cornelia Huck <cornelia.huck@de.ibm.com> Cc: Rafael J. Wysocki <rjw@sisk.pl> Cc: Pavel Machek <pavel@ucw.cz> Cc: Len Brown <len.brown@intel.com> Cc: Magnus Damm <damm@igel.co.jp> Cc: Alan Stern <stern@rowland.harvard.edu> Cc: Randy Dunlap <randy.dunlap@oracle.com> Cc: Stefan Richter <stefanr@s5r6.in-berlin.de> Cc: David Brownell <dbrownell@users.sourceforge.net> Cc: Vegard Nossum <vegard.nossum@gmail.com> Cc: Jesse Barnes <jbarnes@virtuousgeek.org> Cc: Alex Chiang <achiang@hp.com> Cc: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andrew Patterson <andrew.patterson@hp.com> Cc: Yu Zhao <yu.zhao@intel.com> Cc: Dominik Brodowski <linux@dominikbrodowski.net> Cc: Samuel Ortiz <sameo@linux.intel.com> Cc: Wolfram Sang <w.sang@pengutronix.de> Cc: CHENG Renquan <rqcheng@smu.edu.sg> Cc: Oliver Neukum <oliver@neukum.org> Cc: Frans Pop <elendil@planet.nl> Cc: David Vrabel <david.vrabel@csr.com> Cc: Kay Sievers <kay.sievers@vrfy.org> Cc: Sarah Sharp <sarah.a.sharp@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'include')
-rw-r--r--include/linux/device.h17
-rw-r--r--include/linux/usb.h6
2 files changed, 19 insertions, 4 deletions
diff --git a/include/linux/device.h b/include/linux/device.h
index f95d5bfe8248..182192892d45 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -106,7 +106,7 @@ extern int bus_unregister_notifier(struct bus_type *bus,
106 106
107/* All 4 notifers below get called with the target struct device * 107/* All 4 notifers below get called with the target struct device *
108 * as an argument. Note that those functions are likely to be called 108 * as an argument. Note that those functions are likely to be called
109 * with the device semaphore held in the core, so be careful. 109 * with the device lock held in the core, so be careful.
110 */ 110 */
111#define BUS_NOTIFY_ADD_DEVICE 0x00000001 /* device added */ 111#define BUS_NOTIFY_ADD_DEVICE 0x00000001 /* device added */
112#define BUS_NOTIFY_DEL_DEVICE 0x00000002 /* device removed */ 112#define BUS_NOTIFY_DEL_DEVICE 0x00000002 /* device removed */
@@ -508,6 +508,21 @@ static inline bool device_async_suspend_enabled(struct device *dev)
508 return !!dev->power.async_suspend; 508 return !!dev->power.async_suspend;
509} 509}
510 510
511static inline void device_lock(struct device *dev)
512{
513 down(&dev->sem);
514}
515
516static inline int device_trylock(struct device *dev)
517{
518 return down_trylock(&dev->sem);
519}
520
521static inline void device_unlock(struct device *dev)
522{
523 up(&dev->sem);
524}
525
511void driver_init(void); 526void driver_init(void);
512 527
513/* 528/*
diff --git a/include/linux/usb.h b/include/linux/usb.h
index 3492abf82e75..8c9f053111bb 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -512,9 +512,9 @@ extern struct usb_device *usb_get_dev(struct usb_device *dev);
512extern void usb_put_dev(struct usb_device *dev); 512extern void usb_put_dev(struct usb_device *dev);
513 513
514/* USB device locking */ 514/* USB device locking */
515#define usb_lock_device(udev) down(&(udev)->dev.sem) 515#define usb_lock_device(udev) device_lock(&(udev)->dev)
516#define usb_unlock_device(udev) up(&(udev)->dev.sem) 516#define usb_unlock_device(udev) device_unlock(&(udev)->dev)
517#define usb_trylock_device(udev) down_trylock(&(udev)->dev.sem) 517#define usb_trylock_device(udev) device_trylock(&(udev)->dev)
518extern int usb_lock_device_for_reset(struct usb_device *udev, 518extern int usb_lock_device_for_reset(struct usb_device *udev,
519 const struct usb_interface *iface); 519 const struct usb_interface *iface);
520 520