diff options
author | David Brownell <dbrownell@users.sourceforge.net> | 2008-10-14 11:30:05 -0400 |
---|---|---|
committer | Jean Delvare <khali@mahadeva.delvare> | 2008-10-14 11:30:05 -0400 |
commit | 1d0b19c9a0612c653d1a0df267ba159089f6d139 (patch) | |
tree | 406b09500a13eaf91f2f8a925e76db40f450a712 /drivers | |
parent | 7c15fd1249658e203b2ac8661e48da6c2102e563 (diff) |
i2c: Guard against oopses from bad init sequences
Guard I2C against oopsing because of init sequence problems, by
verifying that i2c_init() has been called before calling any
routines that rely on that initialization. This specific test
just requires that bus_register(&i2c_bus_type) was called.
Examples of this kind of oopsing come from subystems and drivers
which register I2C drivers in their subsys_initcall code but
which are statically linked before I2C by drivers/Makefile.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/i2c/i2c-core.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index b346a687ab59..a96e1bf27649 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -437,6 +437,10 @@ static int i2c_register_adapter(struct i2c_adapter *adap) | |||
437 | { | 437 | { |
438 | int res = 0, dummy; | 438 | int res = 0, dummy; |
439 | 439 | ||
440 | /* Can't register until after driver model init */ | ||
441 | if (unlikely(WARN_ON(!i2c_bus_type.p))) | ||
442 | return -EAGAIN; | ||
443 | |||
440 | mutex_init(&adap->bus_lock); | 444 | mutex_init(&adap->bus_lock); |
441 | mutex_init(&adap->clist_lock); | 445 | mutex_init(&adap->clist_lock); |
442 | INIT_LIST_HEAD(&adap->clients); | 446 | INIT_LIST_HEAD(&adap->clients); |
@@ -696,6 +700,10 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver) | |||
696 | { | 700 | { |
697 | int res; | 701 | int res; |
698 | 702 | ||
703 | /* Can't register until after driver model init */ | ||
704 | if (unlikely(WARN_ON(!i2c_bus_type.p))) | ||
705 | return -EAGAIN; | ||
706 | |||
699 | /* new style driver methods can't mix with legacy ones */ | 707 | /* new style driver methods can't mix with legacy ones */ |
700 | if (is_newstyle_driver(driver)) { | 708 | if (is_newstyle_driver(driver)) { |
701 | if (driver->attach_adapter || driver->detach_adapter | 709 | if (driver->attach_adapter || driver->detach_adapter |