]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/i2c/i2c-core.c
i2c: Fix NULL pointer dereference in i2c_new_probed_device
[linux-2.6-omap-h63xx.git] / drivers / i2c / i2c-core.c
index 0a79f7661017b0a548868db95bba17e2d73a2796..c16dcad94412c438998ad9e2014061a7546931cb 100644 (file)
@@ -654,6 +654,10 @@ int i2c_del_adapter(struct i2c_adapter *adap)
 
        dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name);
 
+       /* Clear the device structure in case this adapter is ever going to be
+          added again */
+       memset(&adap->dev, 0, sizeof(adap->dev));
+
  out_unlock:
        mutex_unlock(&core_lock);
        return res;
@@ -718,7 +722,8 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
 
        INIT_LIST_HEAD(&driver->clients);
        /* Walk the adapters that are already present */
-       class_for_each_device(&i2c_adapter_class, driver, __attach_adapter);
+       class_for_each_device(&i2c_adapter_class, NULL, driver,
+                             __attach_adapter);
 
        mutex_unlock(&core_lock);
        return 0;
@@ -778,7 +783,8 @@ void i2c_del_driver(struct i2c_driver *driver)
 {
        mutex_lock(&core_lock);
 
-       class_for_each_device(&i2c_adapter_class, driver, __detach_adapter);
+       class_for_each_device(&i2c_adapter_class, NULL, driver,
+                             __detach_adapter);
 
        driver_unregister(&driver->driver);
        pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name);
@@ -1445,9 +1451,11 @@ i2c_new_probed_device(struct i2c_adapter *adap,
                if ((addr_list[i] & ~0x07) == 0x30
                 || (addr_list[i] & ~0x0f) == 0x50
                 || !i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK)) {
+                       union i2c_smbus_data data;
+
                        if (i2c_smbus_xfer(adap, addr_list[i], 0,
                                           I2C_SMBUS_READ, 0,
-                                          I2C_SMBUS_BYTE, NULL) >= 0)
+                                          I2C_SMBUS_BYTE, &data) >= 0)
                                break;
                } else {
                        if (i2c_smbus_xfer(adap, addr_list[i], 0,