mirror of
https://github.com/torvalds/linux.git
synced 2024-12-04 01:51:34 +00:00
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>
This commit is contained in:
parent
acd8bc1a70
commit
bfb7971c30
@ -312,16 +312,13 @@ static int i2c_platform_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
pr_debug("i2c_platform_probe\n");
|
pr_debug("i2c_platform_probe\n");
|
||||||
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||||
if (!r) {
|
if (!r)
|
||||||
ret = -ENODEV;
|
return -ENODEV;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
priv = kzalloc(sizeof(struct i2c_platform_data), GFP_KERNEL);
|
priv = devm_kzalloc(&pdev->dev, sizeof(struct i2c_platform_data),
|
||||||
if (!priv) {
|
GFP_KERNEL);
|
||||||
ret = -ENOMEM;
|
if (!priv)
|
||||||
goto out;
|
return -ENOMEM;
|
||||||
}
|
|
||||||
|
|
||||||
/* FIXME: need to allocate resource in PIC32 space */
|
/* FIXME: need to allocate resource in PIC32 space */
|
||||||
#if 0
|
#if 0
|
||||||
@ -330,10 +327,8 @@ static int i2c_platform_probe(struct platform_device *pdev)
|
|||||||
#else
|
#else
|
||||||
priv->base = r->start;
|
priv->base = r->start;
|
||||||
#endif
|
#endif
|
||||||
if (!priv->base) {
|
if (!priv->base)
|
||||||
ret = -EBUSY;
|
return -EBUSY;
|
||||||
goto out_mem;
|
|
||||||
}
|
|
||||||
|
|
||||||
priv->xfer_timeout = 200;
|
priv->xfer_timeout = 200;
|
||||||
priv->ack_timeout = 200;
|
priv->ack_timeout = 200;
|
||||||
@ -348,17 +343,13 @@ static int i2c_platform_probe(struct platform_device *pdev)
|
|||||||
i2c_platform_setup(priv);
|
i2c_platform_setup(priv);
|
||||||
|
|
||||||
ret = i2c_add_numbered_adapter(&priv->adap);
|
ret = i2c_add_numbered_adapter(&priv->adap);
|
||||||
if (ret == 0) {
|
if (ret) {
|
||||||
platform_set_drvdata(pdev, priv);
|
i2c_platform_disable(priv);
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
i2c_platform_disable(priv);
|
platform_set_drvdata(pdev, priv);
|
||||||
|
return 0;
|
||||||
out_mem:
|
|
||||||
kfree(priv);
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int i2c_platform_remove(struct platform_device *pdev)
|
static int i2c_platform_remove(struct platform_device *pdev)
|
||||||
@ -369,7 +360,6 @@ static int i2c_platform_remove(struct platform_device *pdev)
|
|||||||
platform_set_drvdata(pdev, NULL);
|
platform_set_drvdata(pdev, NULL);
|
||||||
i2c_del_adapter(&priv->adap);
|
i2c_del_adapter(&priv->adap);
|
||||||
i2c_platform_disable(priv);
|
i2c_platform_disable(priv);
|
||||||
kfree(priv);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user