Skip to content

Commit

Permalink
regulator: lp397x: use devm_kzalloc() to make cleanup paths simpler
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolay Balandin <nbalandin@dev.rtsoft.ru>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
  • Loading branch information
Nikolay Balandin authored and Mark Brown committed May 27, 2013
1 parent e4aa937 commit 2af0af6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
11 changes: 3 additions & 8 deletions drivers/regulator/lp3971.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ static int lp3971_i2c_probe(struct i2c_client *i2c,
return -ENODEV;
}

lp3971 = kzalloc(sizeof(struct lp3971), GFP_KERNEL);
lp3971 = devm_kzalloc(&i2c->dev, sizeof(struct lp3971), GFP_KERNEL);
if (lp3971 == NULL)
return -ENOMEM;

Expand All @@ -449,19 +449,15 @@ static int lp3971_i2c_probe(struct i2c_client *i2c,
ret = -ENODEV;
if (ret < 0) {
dev_err(&i2c->dev, "failed to detect device\n");
goto err_detect;
return ret;
}

ret = setup_regulators(lp3971, pdata);
if (ret < 0)
goto err_detect;
return ret;

i2c_set_clientdata(i2c, lp3971);
return 0;

err_detect:
kfree(lp3971);
return ret;
}

static int lp3971_i2c_remove(struct i2c_client *i2c)
Expand All @@ -473,7 +469,6 @@ static int lp3971_i2c_remove(struct i2c_client *i2c)
regulator_unregister(lp3971->rdev[i]);

kfree(lp3971->rdev);
kfree(lp3971);

return 0;
}
Expand Down
11 changes: 3 additions & 8 deletions drivers/regulator/lp3972.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ static int lp3972_i2c_probe(struct i2c_client *i2c,
return -ENODEV;
}

lp3972 = kzalloc(sizeof(struct lp3972), GFP_KERNEL);
lp3972 = devm_kzalloc(&i2c->dev, sizeof(struct lp3972), GFP_KERNEL);
if (!lp3972)
return -ENOMEM;

Expand All @@ -546,19 +546,15 @@ static int lp3972_i2c_probe(struct i2c_client *i2c,
}
if (ret < 0) {
dev_err(&i2c->dev, "failed to detect device. ret = %d\n", ret);
goto err_detect;
return ret;
}

ret = setup_regulators(lp3972, pdata);
if (ret < 0)
goto err_detect;
return ret;

i2c_set_clientdata(i2c, lp3972);
return 0;

err_detect:
kfree(lp3972);
return ret;
}

static int lp3972_i2c_remove(struct i2c_client *i2c)
Expand All @@ -569,7 +565,6 @@ static int lp3972_i2c_remove(struct i2c_client *i2c)
for (i = 0; i < lp3972->num_regulators; i++)
regulator_unregister(lp3972->rdev[i]);
kfree(lp3972->rdev);
kfree(lp3972);

return 0;
}
Expand Down

0 comments on commit 2af0af6

Please sign in to comment.