Skip to content

Commit d2a3b91

Browse files
Matthew Wilcoxgregkh
authored andcommitted
class: add lockdep infrastructure
This adds the infrastructure to properly handle lockdep issues when the internal class semaphore is changed to a mutex. Matthew wrote the original patch, and Greg fixed it up to work properly with the class_create() function. From: Matthew Wilcox <matthew@wil.cx> Cc: Kay Sievers <kay.sievers@vrfy.org> Cc: Dave Young <hidave.darkstar@gmail.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: James Bottomley <James.Bottomley@HansenPartnership.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ingo Molnar <mingo@elte.hu> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 1e41250 commit d2a3b91

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

drivers/base/class.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static void remove_class_attrs(struct class *cls)
134134
}
135135
}
136136

137-
int class_register(struct class *cls)
137+
int __class_register(struct class *cls, struct lock_class_key *key)
138138
{
139139
struct class_private *cp;
140140
int error;
@@ -178,6 +178,7 @@ int class_register(struct class *cls)
178178
class_put(cls);
179179
return error;
180180
}
181+
EXPORT_SYMBOL_GPL(__class_register);
181182

182183
void class_unregister(struct class *cls)
183184
{
@@ -203,7 +204,8 @@ static void class_create_release(struct class *cls)
203204
* Note, the pointer created here is to be destroyed when finished by
204205
* making a call to class_destroy().
205206
*/
206-
struct class *class_create(struct module *owner, const char *name)
207+
struct class *__class_create(struct module *owner, const char *name,
208+
struct lock_class_key *key)
207209
{
208210
struct class *cls;
209211
int retval;
@@ -218,7 +220,7 @@ struct class *class_create(struct module *owner, const char *name)
218220
cls->owner = owner;
219221
cls->class_release = class_create_release;
220222

221-
retval = class_register(cls);
223+
retval = __class_register(cls, key);
222224
if (retval)
223225
goto error;
224226

@@ -228,6 +230,7 @@ struct class *class_create(struct module *owner, const char *name)
228230
kfree(cls);
229231
return ERR_PTR(retval);
230232
}
233+
EXPORT_SYMBOL_GPL(__class_create);
231234

232235
/**
233236
* class_destroy - destroys a struct class structure
@@ -412,9 +415,7 @@ int __init classes_init(void)
412415

413416
EXPORT_SYMBOL_GPL(class_create_file);
414417
EXPORT_SYMBOL_GPL(class_remove_file);
415-
EXPORT_SYMBOL_GPL(class_register);
416418
EXPORT_SYMBOL_GPL(class_unregister);
417-
EXPORT_SYMBOL_GPL(class_create);
418419
EXPORT_SYMBOL_GPL(class_destroy);
419420

420421
EXPORT_SYMBOL_GPL(class_interface_register);

include/linux/device.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/kobject.h>
1717
#include <linux/klist.h>
1818
#include <linux/list.h>
19+
#include <linux/lockdep.h>
1920
#include <linux/compiler.h>
2021
#include <linux/types.h>
2122
#include <linux/module.h>
@@ -205,8 +206,18 @@ struct class {
205206

206207
extern struct kobject *sysfs_dev_block_kobj;
207208
extern struct kobject *sysfs_dev_char_kobj;
208-
extern int __must_check class_register(struct class *class);
209+
extern int __must_check __class_register(struct class *class,
210+
struct lock_class_key *key);
209211
extern void class_unregister(struct class *class);
212+
213+
/* This is a #define to keep the compiler from merging different
214+
* instances of the __key variable */
215+
#define class_register(class) \
216+
({ \
217+
static struct lock_class_key __key; \
218+
__class_register(class, &__key); \
219+
})
220+
210221
extern int class_for_each_device(struct class *class, struct device *start,
211222
void *data,
212223
int (*fn)(struct device *dev, void *data));
@@ -239,9 +250,19 @@ struct class_interface {
239250
extern int __must_check class_interface_register(struct class_interface *);
240251
extern void class_interface_unregister(struct class_interface *);
241252

242-
extern struct class *class_create(struct module *owner, const char *name);
253+
extern struct class * __must_check __class_create(struct module *owner,
254+
const char *name,
255+
struct lock_class_key *key);
243256
extern void class_destroy(struct class *cls);
244257

258+
/* This is a #define to keep the compiler from merging different
259+
* instances of the __key variable */
260+
#define class_create(owner, name) \
261+
({ \
262+
static struct lock_class_key __key; \
263+
__class_create(owner, name, &__key); \
264+
})
265+
245266
/*
246267
* The type of device, "struct device" is embedded in. A class
247268
* or bus can contain devices of different types

0 commit comments

Comments
 (0)