diff options
author | Guenter Roeck <linux@roeck-us.net> | 2012-06-02 14:20:19 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2012-09-24 00:08:32 -0400 |
commit | 79831fd4e0820bdc882d08707e4650ed4dfff3b8 (patch) | |
tree | 4c1ea24c39319e26b0085aad006b991b4fe15e19 /drivers/hwmon | |
parent | effb8ab114f7ed574f3c033dac642cd2c4ae0021 (diff) |
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: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/mcp3021.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/drivers/hwmon/mcp3021.c b/drivers/hwmon/mcp3021.c index d0afc0cd3ff4..5162bb95bc61 100644 --- a/drivers/hwmon/mcp3021.c +++ b/drivers/hwmon/mcp3021.c | |||
@@ -103,7 +103,8 @@ static int mcp3021_probe(struct i2c_client *client, | |||
103 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) | 103 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) |
104 | return -ENODEV; | 104 | return -ENODEV; |
105 | 105 | ||
106 | data = kzalloc(sizeof(struct mcp3021_data), GFP_KERNEL); | 106 | data = devm_kzalloc(&client->dev, sizeof(struct mcp3021_data), |
107 | GFP_KERNEL); | ||
107 | if (!data) | 108 | if (!data) |
108 | return -ENOMEM; | 109 | return -ENOMEM; |
109 | 110 | ||
@@ -111,17 +112,14 @@ static int mcp3021_probe(struct i2c_client *client, | |||
111 | 112 | ||
112 | if (client->dev.platform_data) { | 113 | if (client->dev.platform_data) { |
113 | data->vdd = *(u32 *)client->dev.platform_data; | 114 | data->vdd = *(u32 *)client->dev.platform_data; |
114 | if (data->vdd > MCP3021_VDD_MAX || | 115 | if (data->vdd > MCP3021_VDD_MAX || data->vdd < MCP3021_VDD_MIN) |
115 | data->vdd < MCP3021_VDD_MIN) { | 116 | return -EINVAL; |
116 | err = -EINVAL; | ||
117 | goto exit_free; | ||
118 | } | ||
119 | } else | 117 | } else |
120 | data->vdd = MCP3021_VDD_REF; | 118 | data->vdd = MCP3021_VDD_REF; |
121 | 119 | ||
122 | err = sysfs_create_file(&client->dev.kobj, &dev_attr_in0_input.attr); | 120 | err = sysfs_create_file(&client->dev.kobj, &dev_attr_in0_input.attr); |
123 | if (err) | 121 | if (err) |
124 | goto exit_free; | 122 | return err; |
125 | 123 | ||
126 | data->hwmon_dev = hwmon_device_register(&client->dev); | 124 | data->hwmon_dev = hwmon_device_register(&client->dev); |
127 | if (IS_ERR(data->hwmon_dev)) { | 125 | if (IS_ERR(data->hwmon_dev)) { |
@@ -133,8 +131,6 @@ static int mcp3021_probe(struct i2c_client *client, | |||
133 | 131 | ||
134 | exit_remove: | 132 | exit_remove: |
135 | sysfs_remove_file(&client->dev.kobj, &dev_attr_in0_input.attr); | 133 | sysfs_remove_file(&client->dev.kobj, &dev_attr_in0_input.attr); |
136 | exit_free: | ||
137 | kfree(data); | ||
138 | return err; | 134 | return err; |
139 | } | 135 | } |
140 | 136 | ||
@@ -144,7 +140,6 @@ static int mcp3021_remove(struct i2c_client *client) | |||
144 | 140 | ||
145 | hwmon_device_unregister(data->hwmon_dev); | 141 | hwmon_device_unregister(data->hwmon_dev); |
146 | sysfs_remove_file(&client->dev.kobj, &dev_attr_in0_input.attr); | 142 | sysfs_remove_file(&client->dev.kobj, &dev_attr_in0_input.attr); |
147 | kfree(data); | ||
148 | 143 | ||
149 | return 0; | 144 | return 0; |
150 | } | 145 | } |