greybus: embed the i2c adapter struct
authorAlex Elder <elder@linaro.org>
Mon, 27 Oct 2014 08:48:32 +0000 (03:48 -0500)
committerGreg Kroah-Hartman <greg@kroah.com>
Mon, 27 Oct 2014 08:53:10 +0000 (16:53 +0800)
We don't need to dynamically allocate the i2c adapter structure, we
can just embed it right in struct gb_i2c_device.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
drivers/staging/greybus/i2c-gb.c

index 9ecfd79..e208011 100644 (file)
@@ -22,7 +22,7 @@ struct gb_i2c_device {
        u16                     timeout_msec;
        u8                      retries;
 
-       struct i2c_adapter      *adapter;
+       struct i2c_adapter      adapter;
 };
 
 /* Version of the Greybus i2c protocol we support */
@@ -469,7 +469,7 @@ static int gb_i2c_device_setup(struct gb_i2c_device *gb_i2c_dev)
 int gb_i2c_device_init(struct gb_connection *connection)
 {
        struct gb_i2c_device *gb_i2c_dev;
-       struct i2c_adapter *adapter = NULL;
+       struct i2c_adapter *adapter;
        int ret;
 
        gb_i2c_dev = kzalloc(sizeof(*gb_i2c_dev), GFP_KERNEL);
@@ -482,13 +482,8 @@ int gb_i2c_device_init(struct gb_connection *connection)
        if (ret)
                goto out_err;
 
-       /* Looks good; allocate and set up our i2c adapter */
-       adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
-       if (!adapter) {
-               ret = -ENOMEM;
-               goto out_err;
-       }
-
+       /* Looks good; up our i2c adapter */
+       adapter = &gb_i2c_dev->adapter;
        adapter->owner = THIS_MODULE;
        adapter->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
        adapter->algo = &gb_i2c_algorithm;
@@ -504,12 +499,10 @@ int gb_i2c_device_init(struct gb_connection *connection)
        if (ret)
                goto out_err;
 
-       gb_i2c_dev->adapter = adapter;
        connection->private = gb_i2c_dev;
 
        return 0;
 out_err:
-       kfree(adapter);
        /* kref_put(gb_i2c_dev->connection) */
        kfree(gb_i2c_dev);
 
@@ -520,8 +513,7 @@ void gb_i2c_device_exit(struct gb_connection *connection)
 {
        struct gb_i2c_device *gb_i2c_dev = connection->private;
 
-       i2c_del_adapter(gb_i2c_dev->adapter);
-       kfree(gb_i2c_dev->adapter);
+       i2c_del_adapter(&gb_i2c_dev->adapter);
        /* kref_put(gb_i2c_dev->connection) */
        kfree(gb_i2c_dev);
 }