Commit bb7f086b authored by Yicong Yang's avatar Yicong Yang Committed by Wolfram Sang

i2c: core: simplify devm_i2c_new_dummy_device()

Use devm_add_action_or_reset() instead of devres_alloc() and
devres_add(), which works the same. This will simplify the
code. There is no functional change.
Signed-off-by: default avatarYicong Yang <yangyicong@hisilicon.com>
Reviewed-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
parent 3ab4ce2d
...@@ -1016,15 +1016,9 @@ struct i2c_client *i2c_new_dummy_device(struct i2c_adapter *adapter, u16 address ...@@ -1016,15 +1016,9 @@ struct i2c_client *i2c_new_dummy_device(struct i2c_adapter *adapter, u16 address
} }
EXPORT_SYMBOL_GPL(i2c_new_dummy_device); EXPORT_SYMBOL_GPL(i2c_new_dummy_device);
struct i2c_dummy_devres { static void devm_i2c_release_dummy(void *client)
struct i2c_client *client;
};
static void devm_i2c_release_dummy(struct device *dev, void *res)
{ {
struct i2c_dummy_devres *this = res; i2c_unregister_device(client);
i2c_unregister_device(this->client);
} }
/** /**
...@@ -1041,20 +1035,16 @@ struct i2c_client *devm_i2c_new_dummy_device(struct device *dev, ...@@ -1041,20 +1035,16 @@ struct i2c_client *devm_i2c_new_dummy_device(struct device *dev,
struct i2c_adapter *adapter, struct i2c_adapter *adapter,
u16 address) u16 address)
{ {
struct i2c_dummy_devres *dr;
struct i2c_client *client; struct i2c_client *client;
int ret;
dr = devres_alloc(devm_i2c_release_dummy, sizeof(*dr), GFP_KERNEL);
if (!dr)
return ERR_PTR(-ENOMEM);
client = i2c_new_dummy_device(adapter, address); client = i2c_new_dummy_device(adapter, address);
if (IS_ERR(client)) { if (IS_ERR(client))
devres_free(dr); return client;
} else {
dr->client = client; ret = devm_add_action_or_reset(dev, devm_i2c_release_dummy, client);
devres_add(dev, dr); if (ret)
} return ERR_PTR(ret);
return client; return client;
} }
......
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