Skip to content

Commit ddefcd7

Browse files
javiercarrascocruzdtor
authored andcommitted
Input: sparcspkr - use device managed memory for 'state'
Use devm_kzalloc() in bbc_bee_probe() and grover_beep_probe() to automatically free 'state' when the device is removed. Drop the kfree(state) calls from the probe error paths and the remove functions accordingly. Suggested-by: Dmitry Torokhov <[email protected]> Signed-off-by: Javier Carrasco <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 6951ec3 commit ddefcd7

File tree

1 file changed

+14
-27
lines changed

1 file changed

+14
-27
lines changed

drivers/input/misc/sparcspkr.c

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -183,46 +183,39 @@ static int bbc_beep_probe(struct platform_device *op)
183183
struct sparcspkr_state *state;
184184
struct bbc_beep_info *info;
185185
struct device_node *dp;
186-
int err = -ENOMEM;
186+
int err;
187187

188-
state = kzalloc(sizeof(*state), GFP_KERNEL);
188+
state = devm_kzalloc(&op->dev, sizeof(*state), GFP_KERNEL);
189189
if (!state)
190-
goto out_err;
190+
return -ENOMEM;
191191

192192
state->name = "Sparc BBC Speaker";
193193
state->event = bbc_spkr_event;
194194
spin_lock_init(&state->lock);
195195

196196
dp = of_find_node_by_path("/");
197-
err = -ENODEV;
198197
if (!dp)
199-
goto out_free;
198+
return -ENODEV;
200199

201200
info = &state->u.bbc;
202201
info->clock_freq = of_getintprop_default(dp, "clock-frequency", 0);
203202
of_node_put(dp);
204203
if (!info->clock_freq)
205-
goto out_free;
204+
return -ENODEV;
206205

207206
info->regs = of_ioremap(&op->resource[0], 0, 6, "bbc beep");
208207
if (!info->regs)
209-
goto out_free;
208+
return -ENODEV;
210209

211210
platform_set_drvdata(op, state);
212211

213212
err = sparcspkr_probe(&op->dev);
214-
if (err)
215-
goto out_clear_drvdata;
213+
if (err) {
214+
of_iounmap(&op->resource[0], info->regs, 6);
215+
return err;
216+
}
216217

217218
return 0;
218-
219-
out_clear_drvdata:
220-
of_iounmap(&op->resource[0], info->regs, 6);
221-
222-
out_free:
223-
kfree(state);
224-
out_err:
225-
return err;
226219
}
227220

228221
static void bbc_remove(struct platform_device *op)
@@ -237,8 +230,6 @@ static void bbc_remove(struct platform_device *op)
237230
input_unregister_device(input_dev);
238231

239232
of_iounmap(&op->resource[0], info->regs, 6);
240-
241-
kfree(state);
242233
}
243234

244235
static const struct of_device_id bbc_beep_match[] = {
@@ -266,9 +257,9 @@ static int grover_beep_probe(struct platform_device *op)
266257
struct grover_beep_info *info;
267258
int err = -ENOMEM;
268259

269-
state = kzalloc(sizeof(*state), GFP_KERNEL);
260+
state = devm_kzalloc(&op->dev, sizeof(*state), GFP_KERNEL);
270261
if (!state)
271-
goto out_err;
262+
return err;
272263

273264
state->name = "Sparc Grover Speaker";
274265
state->event = grover_spkr_event;
@@ -277,7 +268,7 @@ static int grover_beep_probe(struct platform_device *op)
277268
info = &state->u.grover;
278269
info->freq_regs = of_ioremap(&op->resource[2], 0, 2, "grover beep freq");
279270
if (!info->freq_regs)
280-
goto out_free;
271+
return err;
281272

282273
info->enable_reg = of_ioremap(&op->resource[3], 0, 1, "grover beep enable");
283274
if (!info->enable_reg)
@@ -296,9 +287,7 @@ static int grover_beep_probe(struct platform_device *op)
296287

297288
out_unmap_freq_regs:
298289
of_iounmap(&op->resource[2], info->freq_regs, 2);
299-
out_free:
300-
kfree(state);
301-
out_err:
290+
302291
return err;
303292
}
304293

@@ -315,8 +304,6 @@ static void grover_remove(struct platform_device *op)
315304

316305
of_iounmap(&op->resource[3], info->enable_reg, 1);
317306
of_iounmap(&op->resource[2], info->freq_regs, 2);
318-
319-
kfree(state);
320307
}
321308

322309
static const struct of_device_id grover_beep_match[] = {

0 commit comments

Comments
 (0)