Commit 81f4e227 authored by Alex Elder's avatar Alex Elder Committed by Greg Kroah-Hartman

greybus: embed the i2c adapter struct

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: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent 81d631ca
......@@ -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);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment