From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Brownell Subject: [patch 2.6.27-rc7] i2c: guard against oopses from bad init sequences Date: Tue, 23 Sep 2008 11:38:19 -0700 Message-ID: <200809231138.19583.david-b@pacbell.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: i2c-bounces-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org Errors-To: i2c-bounces-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org To: i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org List-Id: linux-i2c@vger.kernel.org From: David Brownell 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 --- Alternatively have postcore_initcall(i2c_init), which may be better ... the initcall levels are pretty limited, and in these cases the "subsystem" of interest builds on I2C and needs to work before device_initcall. Having I2C use subsys_initcall kind of forces things into fs_initcall. I'd encourage the anti-oopsing paranoia in any case, even if i2c switches to postcore_initcall (or earlier). drivers/i2c/i2c-core.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -443,6 +443,12 @@ static int i2c_register_adapter(struct i mutex_lock(&core_lock); + /* can't register until after driver model init */ + if (WARN_ON(!i2c_bus_type.p)) { + res = -ENOENT; + goto out_list; + } + /* Add the adapter to the driver core. * If the parent pointer is not set up, * we add this adapter to the host bus. @@ -696,6 +702,10 @@ int i2c_register_driver(struct module *o { int res; + /* can't register until after driver model init */ + if (WARN_ON(!i2c_bus_type.p)) + return -ENOENT; + /* new style driver methods can't mix with legacy ones */ if (is_newstyle_driver(driver)) { if (driver->attach_adapter || driver->detach_adapter _______________________________________________ i2c mailing list i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org http://lists.lm-sensors.org/mailman/listinfo/i2c