aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHimangi Saraogi <himangi774@gmail.com>2014-07-21 04:25:35 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-07-22 19:28:11 -0400
commit4734e39064219fca321ddbc930b46e7c3c194143 (patch)
tree417fed86b2900eb0ae3c6e329a398ed63feed10b
parent0178a7a54d408d2c5b7bbe7eee9450bffbec0989 (diff)
misc: bh1770glc: Use managed functions
This patch introduces the use of managed interfaces like devm_kzalloc, devm_regulator_bulk_get and does away with the functions to free the allocated memory in the probe and remove functions. Also, some labels are removed and renamed to preserve the ordering. 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/bh1770glc.c35
1 files changed, 14 insertions, 21 deletions
diff --git a/drivers/misc/bh1770glc.c b/drivers/misc/bh1770glc.c
index 99a04686e45f..7b55f8a152d4 100644
--- a/drivers/misc/bh1770glc.c
+++ b/drivers/misc/bh1770glc.c
@@ -1185,7 +1185,7 @@ static int bh1770_probe(struct i2c_client *client,
1185 struct bh1770_chip *chip; 1185 struct bh1770_chip *chip;
1186 int err; 1186 int err;
1187 1187
1188 chip = kzalloc(sizeof *chip, GFP_KERNEL); 1188 chip = devm_kzalloc(&client->dev, sizeof *chip, GFP_KERNEL);
1189 if (!chip) 1189 if (!chip)
1190 return -ENOMEM; 1190 return -ENOMEM;
1191 1191
@@ -1198,8 +1198,7 @@ static int bh1770_probe(struct i2c_client *client,
1198 1198
1199 if (client->dev.platform_data == NULL) { 1199 if (client->dev.platform_data == NULL) {
1200 dev_err(&client->dev, "platform data is mandatory\n"); 1200 dev_err(&client->dev, "platform data is mandatory\n");
1201 err = -EINVAL; 1201 return -EINVAL;
1202 goto fail1;
1203 } 1202 }
1204 1203
1205 chip->pdata = client->dev.platform_data; 1204 chip->pdata = client->dev.platform_data;
@@ -1224,24 +1223,24 @@ static int bh1770_probe(struct i2c_client *client,
1224 chip->regs[0].supply = reg_vcc; 1223 chip->regs[0].supply = reg_vcc;
1225 chip->regs[1].supply = reg_vleds; 1224 chip->regs[1].supply = reg_vleds;
1226 1225
1227 err = regulator_bulk_get(&client->dev, 1226 err = devm_regulator_bulk_get(&client->dev,
1228 ARRAY_SIZE(chip->regs), chip->regs); 1227 ARRAY_SIZE(chip->regs), chip->regs);
1229 if (err < 0) { 1228 if (err < 0) {
1230 dev_err(&client->dev, "Cannot get regulators\n"); 1229 dev_err(&client->dev, "Cannot get regulators\n");
1231 goto fail1; 1230 return err;
1232 } 1231 }
1233 1232
1234 err = regulator_bulk_enable(ARRAY_SIZE(chip->regs), 1233 err = regulator_bulk_enable(ARRAY_SIZE(chip->regs),
1235 chip->regs); 1234 chip->regs);
1236 if (err < 0) { 1235 if (err < 0) {
1237 dev_err(&client->dev, "Cannot enable regulators\n"); 1236 dev_err(&client->dev, "Cannot enable regulators\n");
1238 goto fail2; 1237 return err;
1239 } 1238 }
1240 1239
1241 usleep_range(BH1770_STARTUP_DELAY, BH1770_STARTUP_DELAY * 2); 1240 usleep_range(BH1770_STARTUP_DELAY, BH1770_STARTUP_DELAY * 2);
1242 err = bh1770_detect(chip); 1241 err = bh1770_detect(chip);
1243 if (err < 0) 1242 if (err < 0)
1244 goto fail3; 1243 goto fail0;
1245 1244
1246 /* Start chip */ 1245 /* Start chip */
1247 bh1770_chip_on(chip); 1246 bh1770_chip_on(chip);
@@ -1252,14 +1251,14 @@ static int bh1770_probe(struct i2c_client *client,
1252 if (chip->lux_corr == 0) { 1251 if (chip->lux_corr == 0) {
1253 dev_err(&client->dev, "Improper correction values\n"); 1252 dev_err(&client->dev, "Improper correction values\n");
1254 err = -EINVAL; 1253 err = -EINVAL;
1255 goto fail3; 1254 goto fail0;
1256 } 1255 }
1257 1256
1258 if (chip->pdata->setup_resources) { 1257 if (chip->pdata->setup_resources) {
1259 err = chip->pdata->setup_resources(); 1258 err = chip->pdata->setup_resources();
1260 if (err) { 1259 if (err) {
1261 err = -EINVAL; 1260 err = -EINVAL;
1262 goto fail3; 1261 goto fail0;
1263 } 1262 }
1264 } 1263 }
1265 1264
@@ -1267,7 +1266,7 @@ static int bh1770_probe(struct i2c_client *client,
1267 &bh1770_attribute_group); 1266 &bh1770_attribute_group);
1268 if (err < 0) { 1267 if (err < 0) {
1269 dev_err(&chip->client->dev, "Sysfs registration failed\n"); 1268 dev_err(&chip->client->dev, "Sysfs registration failed\n");
1270 goto fail4; 1269 goto fail1;
1271 } 1270 }
1272 1271
1273 /* 1272 /*
@@ -1283,22 +1282,18 @@ static int bh1770_probe(struct i2c_client *client,
1283 if (err) { 1282 if (err) {
1284 dev_err(&client->dev, "could not get IRQ %d\n", 1283 dev_err(&client->dev, "could not get IRQ %d\n",
1285 client->irq); 1284 client->irq);
1286 goto fail5; 1285 goto fail2;
1287 } 1286 }
1288 regulator_bulk_disable(ARRAY_SIZE(chip->regs), chip->regs); 1287 regulator_bulk_disable(ARRAY_SIZE(chip->regs), chip->regs);
1289 return err; 1288 return err;
1290fail5: 1289fail2:
1291 sysfs_remove_group(&chip->client->dev.kobj, 1290 sysfs_remove_group(&chip->client->dev.kobj,
1292 &bh1770_attribute_group); 1291 &bh1770_attribute_group);
1293fail4: 1292fail1:
1294 if (chip->pdata->release_resources) 1293 if (chip->pdata->release_resources)
1295 chip->pdata->release_resources(); 1294 chip->pdata->release_resources();
1296fail3: 1295fail0:
1297 regulator_bulk_disable(ARRAY_SIZE(chip->regs), chip->regs); 1296 regulator_bulk_disable(ARRAY_SIZE(chip->regs), chip->regs);
1298fail2:
1299 regulator_bulk_free(ARRAY_SIZE(chip->regs), chip->regs);
1300fail1:
1301 kfree(chip);
1302 return err; 1297 return err;
1303} 1298}
1304 1299
@@ -1322,8 +1317,6 @@ static int bh1770_remove(struct i2c_client *client)
1322 pm_runtime_disable(&client->dev); 1317 pm_runtime_disable(&client->dev);
1323 pm_runtime_set_suspended(&client->dev); 1318 pm_runtime_set_suspended(&client->dev);
1324 1319
1325 regulator_bulk_free(ARRAY_SIZE(chip->regs), chip->regs);
1326 kfree(chip);
1327 return 0; 1320 return 0;
1328} 1321}
1329 1322