Commit 88b01c8a authored by Uwe Kleine-König's avatar Uwe Kleine-König Committed by Herbert Xu

crypto: stm32/cryp - Convert to platform remove callback returning void

The .remove() callback for a platform driver returns an int which makes
many driver authors wrongly assume it's possible to do error handling by
returning an error code. However the value returned is (mostly) ignored
and this typically results in resource leaks. To improve here there is a
quest to make the remove callback return void. In the first step of this
quest all drivers are converted to .remove_new() which already returns
void.

The driver adapted here suffered from this wrong assumption and had
several error paths resulting in resource leaks.

The check for cryp being non-NULL is harmless. This can never happen as
.remove() is only called after .probe() completed successfully and in
that case drvdata was set to a non-NULL value. So this check can just be
dropped.

If pm_runtime_get() fails, the other resources held by the device must
still be freed. Only clk_disable_unprepare() should be skipped as the
pm_runtime_get() failed to call clk_prepare_enable().

After these changes the remove function returns zero unconditionally and
can trivially be converted to the prototype required for .remove_new().
Signed-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent afa39e6e
...@@ -2084,17 +2084,12 @@ static int stm32_cryp_probe(struct platform_device *pdev) ...@@ -2084,17 +2084,12 @@ static int stm32_cryp_probe(struct platform_device *pdev)
return ret; return ret;
} }
static int stm32_cryp_remove(struct platform_device *pdev) static void stm32_cryp_remove(struct platform_device *pdev)
{ {
struct stm32_cryp *cryp = platform_get_drvdata(pdev); struct stm32_cryp *cryp = platform_get_drvdata(pdev);
int ret; int ret;
if (!cryp) ret = pm_runtime_get_sync(cryp->dev);
return -ENODEV;
ret = pm_runtime_resume_and_get(cryp->dev);
if (ret < 0)
return ret;
if (cryp->caps->aeads_support) if (cryp->caps->aeads_support)
crypto_engine_unregister_aeads(aead_algs, ARRAY_SIZE(aead_algs)); crypto_engine_unregister_aeads(aead_algs, ARRAY_SIZE(aead_algs));
...@@ -2109,9 +2104,8 @@ static int stm32_cryp_remove(struct platform_device *pdev) ...@@ -2109,9 +2104,8 @@ static int stm32_cryp_remove(struct platform_device *pdev)
pm_runtime_disable(cryp->dev); pm_runtime_disable(cryp->dev);
pm_runtime_put_noidle(cryp->dev); pm_runtime_put_noidle(cryp->dev);
clk_disable_unprepare(cryp->clk); if (ret >= 0)
clk_disable_unprepare(cryp->clk);
return 0;
} }
#ifdef CONFIG_PM #ifdef CONFIG_PM
...@@ -2148,7 +2142,7 @@ static const struct dev_pm_ops stm32_cryp_pm_ops = { ...@@ -2148,7 +2142,7 @@ static const struct dev_pm_ops stm32_cryp_pm_ops = {
static struct platform_driver stm32_cryp_driver = { static struct platform_driver stm32_cryp_driver = {
.probe = stm32_cryp_probe, .probe = stm32_cryp_probe,
.remove = stm32_cryp_remove, .remove_new = stm32_cryp_remove,
.driver = { .driver = {
.name = DRIVER_NAME, .name = DRIVER_NAME,
.pm = &stm32_cryp_pm_ops, .pm = &stm32_cryp_pm_ops,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment