aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHimangi Saraogi <himangi774@gmail.com>2014-07-23 17:15:40 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-07-27 14:10:42 -0400
commit7b9d1f0b7a18b86db0ac1de628fa91c0994fefbe (patch)
treec97eba4fbc61dfd28f14399c8f4ca3ff4647139b
parentee5311420d03eccee02e447e698d2fda6c25583d (diff)
misc: bh1780: Introduce the use of devm_kzalloc
This patch introduces the use of devm_kzalloc and does away with the kfrees in the probe and remove functions. A label and the kfree being called on the return path of failure on i2c_check_functionality, which is completely unnecessary and removed. The NULL assignment of ddata is no longer required is also done away with. Signed-off-by: Himangi Saraogi <himangi774@gmail.com> Acked-by: Julia Lawall <julia.lawall@lip6.fr> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/misc/bh1780gli.c33
1 files changed, 9 insertions, 24 deletions
diff --git a/drivers/misc/bh1780gli.c b/drivers/misc/bh1780gli.c
index 48ea33d15a79..4c4a59b25537 100644
--- a/drivers/misc/bh1780gli.c
+++ b/drivers/misc/bh1780gli.c
@@ -149,50 +149,35 @@ static int bh1780_probe(struct i2c_client *client,
149 const struct i2c_device_id *id) 149 const struct i2c_device_id *id)
150{ 150{
151 int ret; 151 int ret;
152 struct bh1780_data *ddata = NULL; 152 struct bh1780_data *ddata;
153 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 153 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
154 154
155 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) { 155 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
156 ret = -EIO; 156 return -EIO;
157 goto err_op_failed;
158 }
159 157
160 ddata = kzalloc(sizeof(struct bh1780_data), GFP_KERNEL); 158 ddata = devm_kzalloc(&client->dev, sizeof(struct bh1780_data),
161 if (ddata == NULL) { 159 GFP_KERNEL);
162 ret = -ENOMEM; 160 if (ddata == NULL)
163 goto err_op_failed; 161 return -ENOMEM;
164 }
165 162
166 ddata->client = client; 163 ddata->client = client;
167 i2c_set_clientdata(client, ddata); 164 i2c_set_clientdata(client, ddata);
168 165
169 ret = bh1780_read(ddata, BH1780_REG_PARTID, "PART ID"); 166 ret = bh1780_read(ddata, BH1780_REG_PARTID, "PART ID");
170 if (ret < 0) 167 if (ret < 0)
171 goto err_op_failed; 168 return ret;
172 169
173 dev_info(&client->dev, "Ambient Light Sensor, Rev : %d\n", 170 dev_info(&client->dev, "Ambient Light Sensor, Rev : %d\n",
174 (ret & BH1780_REVMASK)); 171 (ret & BH1780_REVMASK));
175 172
176 mutex_init(&ddata->lock); 173 mutex_init(&ddata->lock);
177 174
178 ret = sysfs_create_group(&client->dev.kobj, &bh1780_attr_group); 175 return sysfs_create_group(&client->dev.kobj, &bh1780_attr_group);
179 if (ret)
180 goto err_op_failed;
181
182 return 0;
183
184err_op_failed:
185 kfree(ddata);
186 return ret;
187} 176}
188 177
189static int bh1780_remove(struct i2c_client *client) 178static int bh1780_remove(struct i2c_client *client)
190{ 179{
191 struct bh1780_data *ddata;
192
193 ddata = i2c_get_clientdata(client);
194 sysfs_remove_group(&client->dev.kobj, &bh1780_attr_group); 180 sysfs_remove_group(&client->dev.kobj, &bh1780_attr_group);
195 kfree(ddata);
196 181
197 return 0; 182 return 0;
198} 183}