pwm: omap-dmtimer: Simplify error handling
[ Upstream commit5.4-rM2-2.2.x-imx-squashedc4cf7aa57e
] Instead of doing error handling in the middle of ->probe(), move error handling and freeing the reference to timer to the end. This fixes a resource leak as dm_timer wasn't freed when allocating *omap failed. Implementation note: The put: label was never reached without a goto and ret being unequal to 0, so the removed return statement is fine. Fixes:6604c6556d
("pwm: Add PWM driver for OMAP using dual-mode timers") Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Thierry Reding <thierry.reding@gmail.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
parent
971579fae1
commit
a3536e5589
|
@ -298,15 +298,10 @@ static int pwm_omap_dmtimer_probe(struct platform_device *pdev)
|
||||||
goto put;
|
goto put;
|
||||||
}
|
}
|
||||||
|
|
||||||
put:
|
|
||||||
of_node_put(timer);
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
omap = devm_kzalloc(&pdev->dev, sizeof(*omap), GFP_KERNEL);
|
omap = devm_kzalloc(&pdev->dev, sizeof(*omap), GFP_KERNEL);
|
||||||
if (!omap) {
|
if (!omap) {
|
||||||
pdata->free(dm_timer);
|
ret = -ENOMEM;
|
||||||
return -ENOMEM;
|
goto err_alloc_omap;
|
||||||
}
|
}
|
||||||
|
|
||||||
omap->pdata = pdata;
|
omap->pdata = pdata;
|
||||||
|
@ -339,13 +334,28 @@ put:
|
||||||
ret = pwmchip_add(&omap->chip);
|
ret = pwmchip_add(&omap->chip);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
dev_err(&pdev->dev, "failed to register PWM\n");
|
dev_err(&pdev->dev, "failed to register PWM\n");
|
||||||
omap->pdata->free(omap->dm_timer);
|
goto err_pwmchip_add;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
of_node_put(timer);
|
||||||
|
|
||||||
platform_set_drvdata(pdev, omap);
|
platform_set_drvdata(pdev, omap);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
err_pwmchip_add:
|
||||||
|
|
||||||
|
/*
|
||||||
|
* *omap is allocated using devm_kzalloc,
|
||||||
|
* so no free necessary here
|
||||||
|
*/
|
||||||
|
err_alloc_omap:
|
||||||
|
|
||||||
|
pdata->free(dm_timer);
|
||||||
|
put:
|
||||||
|
of_node_put(timer);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pwm_omap_dmtimer_remove(struct platform_device *pdev)
|
static int pwm_omap_dmtimer_remove(struct platform_device *pdev)
|
||||||
|
|
Loading…
Reference in New Issue