diff options
author | Himangi Saraogi <himangi774@gmail.com> | 2014-05-20 14:09:42 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2014-05-26 10:06:35 -0400 |
commit | bfb7971c30a3dbca1d3bbc3ada47d72a4ea688f9 (patch) | |
tree | 6a0a7df43750aa1aa7514524f4a334ab6eb4271d /arch/mips/mti-sead3 | |
parent | acd8bc1a70ffff39018cd5cd1977e20d0ffce8d3 (diff) |
MIPS: SEAD3: Introduce the use of the managed version of kzalloc
This patch moves data allocated using kzalloc to managed data allocated
using devm_kzalloc and cleans now unnecessary kfrees in probe and remove
functions. Also, the now unnecessary labels out_mem and out are done
away with. The error handling code is moved under if and return 0 is now
at the end of the function.
The following Coccinelle semantic patch was used for making the change:
@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
.probe = probefn,
.remove = removefn,
};
@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
<+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
...
?-kfree(e);
...+>
}
@rem depends on prb@
identifier platform.removefn;
expression e;
@@
removefn(...) {
<...
- kfree(e);
...>
}
Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Tested-by: Markos Chandras <markos.chandras@imgtec.com>
Reviewed-by: Markos Chandras <markos.chandras@imgtec.com>
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/6977/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips/mti-sead3')
-rw-r--r-- | arch/mips/mti-sead3/sead3-pic32-i2c-drv.c | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/arch/mips/mti-sead3/sead3-pic32-i2c-drv.c b/arch/mips/mti-sead3/sead3-pic32-i2c-drv.c index b921e5ec507c..80fe194cfa53 100644 --- a/arch/mips/mti-sead3/sead3-pic32-i2c-drv.c +++ b/arch/mips/mti-sead3/sead3-pic32-i2c-drv.c | |||
@@ -312,16 +312,13 @@ static int i2c_platform_probe(struct platform_device *pdev) | |||
312 | 312 | ||
313 | pr_debug("i2c_platform_probe\n"); | 313 | pr_debug("i2c_platform_probe\n"); |
314 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 314 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
315 | if (!r) { | 315 | if (!r) |
316 | ret = -ENODEV; | 316 | return -ENODEV; |
317 | goto out; | ||
318 | } | ||
319 | 317 | ||
320 | priv = kzalloc(sizeof(struct i2c_platform_data), GFP_KERNEL); | 318 | priv = devm_kzalloc(&pdev->dev, sizeof(struct i2c_platform_data), |
321 | if (!priv) { | 319 | GFP_KERNEL); |
322 | ret = -ENOMEM; | 320 | if (!priv) |
323 | goto out; | 321 | return -ENOMEM; |
324 | } | ||
325 | 322 | ||
326 | /* FIXME: need to allocate resource in PIC32 space */ | 323 | /* FIXME: need to allocate resource in PIC32 space */ |
327 | #if 0 | 324 | #if 0 |
@@ -330,10 +327,8 @@ static int i2c_platform_probe(struct platform_device *pdev) | |||
330 | #else | 327 | #else |
331 | priv->base = r->start; | 328 | priv->base = r->start; |
332 | #endif | 329 | #endif |
333 | if (!priv->base) { | 330 | if (!priv->base) |
334 | ret = -EBUSY; | 331 | return -EBUSY; |
335 | goto out_mem; | ||
336 | } | ||
337 | 332 | ||
338 | priv->xfer_timeout = 200; | 333 | priv->xfer_timeout = 200; |
339 | priv->ack_timeout = 200; | 334 | priv->ack_timeout = 200; |
@@ -348,17 +343,13 @@ static int i2c_platform_probe(struct platform_device *pdev) | |||
348 | i2c_platform_setup(priv); | 343 | i2c_platform_setup(priv); |
349 | 344 | ||
350 | ret = i2c_add_numbered_adapter(&priv->adap); | 345 | ret = i2c_add_numbered_adapter(&priv->adap); |
351 | if (ret == 0) { | 346 | if (ret) { |
352 | platform_set_drvdata(pdev, priv); | 347 | i2c_platform_disable(priv); |
353 | return 0; | 348 | return ret; |
354 | } | 349 | } |
355 | 350 | ||
356 | i2c_platform_disable(priv); | 351 | platform_set_drvdata(pdev, priv); |
357 | 352 | return 0; | |
358 | out_mem: | ||
359 | kfree(priv); | ||
360 | out: | ||
361 | return ret; | ||
362 | } | 353 | } |
363 | 354 | ||
364 | static int i2c_platform_remove(struct platform_device *pdev) | 355 | static int i2c_platform_remove(struct platform_device *pdev) |
@@ -369,7 +360,6 @@ static int i2c_platform_remove(struct platform_device *pdev) | |||
369 | platform_set_drvdata(pdev, NULL); | 360 | platform_set_drvdata(pdev, NULL); |
370 | i2c_del_adapter(&priv->adap); | 361 | i2c_del_adapter(&priv->adap); |
371 | i2c_platform_disable(priv); | 362 | i2c_platform_disable(priv); |
372 | kfree(priv); | ||
373 | return 0; | 363 | return 0; |
374 | } | 364 | } |
375 | 365 | ||