Commit 1704f47b authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Greg Kroah-Hartman

lockdep: Add novalidate class for dev->mutex conversion

The conversion of device->sem to device->mutex resulted in lockdep
warnings. Create a novalidate class for now until the driver folks
come up with separate classes. That way we have at least the basic
mutex debugging coverage.

Add a checkpatch error so the usage is reserved for device->mutex.

[ tglx: checkpatch and compile fix for LOCKDEP=n ]
Signed-off-by: default avatarPeter Zijlstra <peterz@infradead.org>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 3142788b
...@@ -559,6 +559,7 @@ void device_initialize(struct device *dev) ...@@ -559,6 +559,7 @@ void device_initialize(struct device *dev)
kobject_init(&dev->kobj, &device_ktype); kobject_init(&dev->kobj, &device_ktype);
INIT_LIST_HEAD(&dev->dma_pools); INIT_LIST_HEAD(&dev->dma_pools);
mutex_init(&dev->mutex); mutex_init(&dev->mutex);
lockdep_set_novalidate_class(&dev->mutex);
spin_lock_init(&dev->devres_lock); spin_lock_init(&dev->devres_lock);
INIT_LIST_HEAD(&dev->devres_head); INIT_LIST_HEAD(&dev->devres_head);
device_pm_init(dev); device_pm_init(dev);
......
...@@ -44,6 +44,8 @@ struct lock_class_key { ...@@ -44,6 +44,8 @@ struct lock_class_key {
struct lockdep_subclass_key subkeys[MAX_LOCKDEP_SUBCLASSES]; struct lockdep_subclass_key subkeys[MAX_LOCKDEP_SUBCLASSES];
}; };
extern struct lock_class_key __lockdep_no_validate__;
#define LOCKSTAT_POINTS 4 #define LOCKSTAT_POINTS 4
/* /*
...@@ -270,6 +272,9 @@ extern void lockdep_init_map(struct lockdep_map *lock, const char *name, ...@@ -270,6 +272,9 @@ extern void lockdep_init_map(struct lockdep_map *lock, const char *name,
#define lockdep_set_subclass(lock, sub) \ #define lockdep_set_subclass(lock, sub) \
lockdep_init_map(&(lock)->dep_map, #lock, \ lockdep_init_map(&(lock)->dep_map, #lock, \
(lock)->dep_map.key, sub) (lock)->dep_map.key, sub)
#define lockdep_set_novalidate_class(lock) \
lockdep_set_class(lock, &__lockdep_no_validate__)
/* /*
* Compare locking classes * Compare locking classes
*/ */
...@@ -354,6 +359,9 @@ static inline void lockdep_on(void) ...@@ -354,6 +359,9 @@ static inline void lockdep_on(void)
#define lockdep_set_class_and_subclass(lock, key, sub) \ #define lockdep_set_class_and_subclass(lock, key, sub) \
do { (void)(key); } while (0) do { (void)(key); } while (0)
#define lockdep_set_subclass(lock, sub) do { } while (0) #define lockdep_set_subclass(lock, sub) do { } while (0)
#define lockdep_set_novalidate_class(lock) do { } while (0)
/* /*
* We don't define lockdep_match_class() and lockdep_match_key() for !LOCKDEP * We don't define lockdep_match_class() and lockdep_match_key() for !LOCKDEP
* case since the result is not well defined and the caller should rather * case since the result is not well defined and the caller should rather
......
...@@ -2711,6 +2711,8 @@ void lockdep_init_map(struct lockdep_map *lock, const char *name, ...@@ -2711,6 +2711,8 @@ void lockdep_init_map(struct lockdep_map *lock, const char *name,
} }
EXPORT_SYMBOL_GPL(lockdep_init_map); EXPORT_SYMBOL_GPL(lockdep_init_map);
struct lock_class_key __lockdep_no_validate__;
/* /*
* This gets called for every mutex_lock*()/spin_lock*() operation. * This gets called for every mutex_lock*()/spin_lock*() operation.
* We maintain the dependency maps and validate the locking attempt: * We maintain the dependency maps and validate the locking attempt:
...@@ -2745,6 +2747,9 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, ...@@ -2745,6 +2747,9 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
return 0; return 0;
} }
if (lock->key == &__lockdep_no_validate__)
check = 1;
if (!subclass) if (!subclass)
class = lock->class_cache; class = lock->class_cache;
/* /*
......
...@@ -2656,6 +2656,7 @@ sub process { ...@@ -2656,6 +2656,7 @@ sub process {
# check for semaphores used as mutexes # check for semaphores used as mutexes
if ($line =~ /^.\s*init_MUTEX_LOCKED\s*\(/) { if ($line =~ /^.\s*init_MUTEX_LOCKED\s*\(/) {
WARN("consider using a completion\n" . $herecurr); WARN("consider using a completion\n" . $herecurr);
} }
# recommend strict_strto* over simple_strto* # recommend strict_strto* over simple_strto*
if ($line =~ /\bsimple_(strto.*?)\s*\(/) { if ($line =~ /\bsimple_(strto.*?)\s*\(/) {
...@@ -2740,6 +2741,16 @@ sub process { ...@@ -2740,6 +2741,16 @@ sub process {
WARN("use of in_atomic() is incorrect outside core kernel code\n" . $herecurr); WARN("use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
} }
} }
# check for lockdep_set_novalidate_class
if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ ||
$line =~ /__lockdep_no_validate__\s*\)/ ) {
if ($realfile !~ m@^kernel/lockdep@ &&
$realfile !~ m@^include/linux/lockdep@ &&
$realfile !~ m@^drivers/base/core@) {
ERROR("lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr);
}
}
} }
# If we have no input at all, then there is nothing to report on # If we have no input at all, then there is nothing to report on
......
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