Skip to content

Commit f760bf2

Browse files
bbrezillonmiquelraynal
authored andcommitted
mtd: rawnand: fsl_upm: Allocate the fsl_upm_nand object using devm_kzalloc()
This simplifies the init error path and remove function. Signed-off-by: Boris Brezillon <[email protected]> Reviewed-by: Miquel Raynal <[email protected]> Signed-off-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent 5290833 commit f760bf2

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

drivers/mtd/nand/raw/fsl_upm.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,36 +205,34 @@ static int fun_probe(struct platform_device *ofdev)
205205
int size;
206206
int i;
207207

208-
fun = kzalloc(sizeof(*fun), GFP_KERNEL);
208+
fun = devm_kzalloc(&ofdev->dev, sizeof(*fun), GFP_KERNEL);
209209
if (!fun)
210210
return -ENOMEM;
211211

212212
ret = of_address_to_resource(ofdev->dev.of_node, 0, &io_res);
213213
if (ret) {
214214
dev_err(&ofdev->dev, "can't get IO base\n");
215-
goto err1;
215+
return ret;
216216
}
217217

218218
ret = fsl_upm_find(io_res.start, &fun->upm);
219219
if (ret) {
220220
dev_err(&ofdev->dev, "can't find UPM\n");
221-
goto err1;
221+
return ret;
222222
}
223223

224224
prop = of_get_property(ofdev->dev.of_node, "fsl,upm-addr-offset",
225225
&size);
226226
if (!prop || size != sizeof(uint32_t)) {
227227
dev_err(&ofdev->dev, "can't get UPM address offset\n");
228-
ret = -EINVAL;
229-
goto err1;
228+
return -EINVAL;
230229
}
231230
fun->upm_addr_offset = *prop;
232231

233232
prop = of_get_property(ofdev->dev.of_node, "fsl,upm-cmd-offset", &size);
234233
if (!prop || size != sizeof(uint32_t)) {
235234
dev_err(&ofdev->dev, "can't get UPM command offset\n");
236-
ret = -EINVAL;
237-
goto err1;
235+
return -EINVAL;
238236
}
239237
fun->upm_cmd_offset = *prop;
240238

@@ -244,7 +242,7 @@ static int fun_probe(struct platform_device *ofdev)
244242
fun->mchip_count = size / sizeof(uint32_t);
245243
if (fun->mchip_count >= NAND_MAX_CHIPS) {
246244
dev_err(&ofdev->dev, "too much multiple chips\n");
247-
goto err1;
245+
return -EINVAL;
248246
}
249247
for (i = 0; i < fun->mchip_count; i++)
250248
fun->mchip_offsets[i] = be32_to_cpu(prop[i]);
@@ -306,8 +304,6 @@ static int fun_probe(struct platform_device *ofdev)
306304
break;
307305
gpio_free(fun->rnb_gpio[i]);
308306
}
309-
err1:
310-
kfree(fun);
311307

312308
return ret;
313309
}
@@ -330,8 +326,6 @@ static int fun_remove(struct platform_device *ofdev)
330326
gpio_free(fun->rnb_gpio[i]);
331327
}
332328

333-
kfree(fun);
334-
335329
return 0;
336330
}
337331

0 commit comments

Comments
 (0)