Skip to content

Commit 7891d37

Browse files
pavelmachekLee Jones
authored andcommitted
mfd: ti-lmu: Use managed resource for everything
This replaces all remaining unmanaged resources with device managed ones, so that the remove function is no longer needed. This makes the code slightly shorter and fixes two problems: 1. The hardware is disabled after the child devices have been removed. Previously there was a potential race condition. 2. The hardware is disabled when mfd_add_devices fails during probe. Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk> Signed-off-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Lee Jones <lee.jones@linaro.org>
1 parent 7a6a395 commit 7891d37

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

drivers/mfd/ti-lmu.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ static int ti_lmu_enable_hw(struct ti_lmu *lmu, enum ti_lmu_id id)
4747
return 0;
4848
}
4949

50-
static void ti_lmu_disable_hw(struct ti_lmu *lmu)
50+
static void ti_lmu_disable_hw(void *data)
5151
{
52+
struct ti_lmu *lmu = data;
5253
if (lmu->en_gpio)
5354
gpiod_set_value(lmu->en_gpio, 0);
5455
}
@@ -205,6 +206,10 @@ static int ti_lmu_probe(struct i2c_client *cl, const struct i2c_device_id *id)
205206
if (ret)
206207
return ret;
207208

209+
ret = devm_add_action_or_reset(dev, ti_lmu_disable_hw, lmu);
210+
if (ret)
211+
return ret;
212+
208213
/*
209214
* Fault circuit(open/short) can be detected by ti-lmu-fault-monitor.
210215
* After fault detection is done, some devices should re-initialize
@@ -214,17 +219,8 @@ static int ti_lmu_probe(struct i2c_client *cl, const struct i2c_device_id *id)
214219

215220
i2c_set_clientdata(cl, lmu);
216221

217-
return mfd_add_devices(lmu->dev, 0, data->cells,
218-
data->num_cells, NULL, 0, NULL);
219-
}
220-
221-
static int ti_lmu_remove(struct i2c_client *cl)
222-
{
223-
struct ti_lmu *lmu = i2c_get_clientdata(cl);
224-
225-
ti_lmu_disable_hw(lmu);
226-
mfd_remove_devices(lmu->dev);
227-
return 0;
222+
return devm_mfd_add_devices(lmu->dev, 0, data->cells,
223+
data->num_cells, NULL, 0, NULL);
228224
}
229225

230226
static const struct i2c_device_id ti_lmu_ids[] = {
@@ -240,7 +236,6 @@ MODULE_DEVICE_TABLE(i2c, ti_lmu_ids);
240236

241237
static struct i2c_driver ti_lmu_driver = {
242238
.probe = ti_lmu_probe,
243-
.remove = ti_lmu_remove,
244239
.driver = {
245240
.name = "ti-lmu",
246241
.of_match_table = ti_lmu_of_match,

0 commit comments

Comments
 (0)