提交 79831fd4 编写于 作者: G Guenter Roeck

hwmon: (mcp3021) Convert to use devm_ functions

Convert to use devm_ functions to reduce code size and simplify the code.

Cc: Mingkai Hu <Mingkai.hu@freescale.com>
Cc: Xie Xiaobo <X.Xie@freescale.com>
Signed-off-by: NGuenter Roeck <linux@roeck-us.net>
上级 effb8ab1
...@@ -103,7 +103,8 @@ static int mcp3021_probe(struct i2c_client *client, ...@@ -103,7 +103,8 @@ static int mcp3021_probe(struct i2c_client *client,
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
return -ENODEV; return -ENODEV;
data = kzalloc(sizeof(struct mcp3021_data), GFP_KERNEL); data = devm_kzalloc(&client->dev, sizeof(struct mcp3021_data),
GFP_KERNEL);
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
...@@ -111,17 +112,14 @@ static int mcp3021_probe(struct i2c_client *client, ...@@ -111,17 +112,14 @@ static int mcp3021_probe(struct i2c_client *client,
if (client->dev.platform_data) { if (client->dev.platform_data) {
data->vdd = *(u32 *)client->dev.platform_data; data->vdd = *(u32 *)client->dev.platform_data;
if (data->vdd > MCP3021_VDD_MAX || if (data->vdd > MCP3021_VDD_MAX || data->vdd < MCP3021_VDD_MIN)
data->vdd < MCP3021_VDD_MIN) { return -EINVAL;
err = -EINVAL;
goto exit_free;
}
} else } else
data->vdd = MCP3021_VDD_REF; data->vdd = MCP3021_VDD_REF;
err = sysfs_create_file(&client->dev.kobj, &dev_attr_in0_input.attr); err = sysfs_create_file(&client->dev.kobj, &dev_attr_in0_input.attr);
if (err) if (err)
goto exit_free; return err;
data->hwmon_dev = hwmon_device_register(&client->dev); data->hwmon_dev = hwmon_device_register(&client->dev);
if (IS_ERR(data->hwmon_dev)) { if (IS_ERR(data->hwmon_dev)) {
...@@ -133,8 +131,6 @@ static int mcp3021_probe(struct i2c_client *client, ...@@ -133,8 +131,6 @@ static int mcp3021_probe(struct i2c_client *client,
exit_remove: exit_remove:
sysfs_remove_file(&client->dev.kobj, &dev_attr_in0_input.attr); sysfs_remove_file(&client->dev.kobj, &dev_attr_in0_input.attr);
exit_free:
kfree(data);
return err; return err;
} }
...@@ -144,7 +140,6 @@ static int mcp3021_remove(struct i2c_client *client) ...@@ -144,7 +140,6 @@ static int mcp3021_remove(struct i2c_client *client)
hwmon_device_unregister(data->hwmon_dev); hwmon_device_unregister(data->hwmon_dev);
sysfs_remove_file(&client->dev.kobj, &dev_attr_in0_input.attr); sysfs_remove_file(&client->dev.kobj, &dev_attr_in0_input.attr);
kfree(data);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
新手
引导
客服 返回
顶部