Message ID | 1429701102-22320-8-git-send-email-timo.kokkonen@offcode.fi (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 04/22/2015 04:11 AM, Timo Kokkonen wrote: > Structures allocated on the beginning of the probe function must be > freed in case of failure. Really ? The functions are allocated with devm_kzalloc. It might be useful to introduce an error on purpose, have the code jump to your new label, and observe what happens. Guenter
On 26.04.2015 18:32, Guenter Roeck wrote: > On 04/22/2015 04:11 AM, Timo Kokkonen wrote: >> Structures allocated on the beginning of the probe function must be >> freed in case of failure. > > Really ? The functions are allocated with devm_kzalloc. > It might be useful to introduce an error on purpose, have the code > jump to your new label, and observe what happens. Interesting. I wasn't aware of devm_kzalloc. I will have to remove this patch from the series and rework the another omap patch to apply without this. Thanks! -Timo
diff --git a/drivers/watchdog/omap_wdt.c b/drivers/watchdog/omap_wdt.c index 1e6be9e..bbaf39a 100644 --- a/drivers/watchdog/omap_wdt.c +++ b/drivers/watchdog/omap_wdt.c @@ -226,8 +226,10 @@ static int omap_wdt_probe(struct platform_device *pdev) /* reserve static register mappings */ res = platform_get_resource(pdev, IORESOURCE_MEM, 0); wdev->base = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(wdev->base)) - return PTR_ERR(wdev->base); + if (IS_ERR(wdev->base)) { + ret = PTR_ERR(wdev->base); + goto err_ioremap; + } omap_wdt->info = &omap_wdt_info; omap_wdt->ops = &omap_wdt_ops; @@ -258,10 +260,8 @@ static int omap_wdt_probe(struct platform_device *pdev) omap_wdt_disable(wdev); ret = watchdog_register_device(omap_wdt); - if (ret) { - pm_runtime_disable(wdev->dev); - return ret; - } + if (ret) + goto err_register_device; pr_info("OMAP Watchdog Timer Rev 0x%02x: initial timeout %d sec\n", readl_relaxed(wdev->base + OMAP_WATCHDOG_REV) & 0xFF, @@ -270,6 +270,14 @@ static int omap_wdt_probe(struct platform_device *pdev) pm_runtime_put_sync(wdev->dev); return 0; + +err_register_device: + pm_runtime_disable(wdev->dev); +err_ioremap: + kfree(wdev); + kfree(omap_wdt); + + return ret; } static void omap_wdt_shutdown(struct platform_device *pdev)
Structures allocated on the beginning of the probe function must be freed in case of failure. Signed-off-by: Timo Kokkonen <timo.kokkonen@offcode.fi> --- drivers/watchdog/omap_wdt.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)