Re: devm_kfree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 27 Dec 2011, Adam Jiang wrote:

2011/12/26 Julia Lawall <julia.lawall@xxxxxxx>:
Is it reasonable to use devm_kfree in a probe function that fails or a
remove function that succeeds?

I cannot catch your question. If the memory is allocated by
devm_kzalloc(), it is not necessary to release with devm_kfree() at
all. It would be release once the driver was detached or destroyed.

Perhaps it is undesirable to keep it around until then, as in my last
example below where the probe function seems to want to go with a
different solution in some cases?

I was also worried that one call could make some information required by
another one unavailable.  For example in the following case:

drivers/dma/mpc512x_dma.c

        devm_free_irq(dev, mdma->irq, mdma);
        irq_dispose_mapping(mdma->irq);

Is it OK to call irq_dispose_mapping and then let devm_free_irq be called
implicitly afterwards?

julia





Examples from drivers/watchdog/shwdt.c:

sh_wdt_probe:

       ...
 out_unreg:
       unregister_reboot_notifier(&sh_wdt_notifier);
 out_unmap:
-       devm_iounmap(&pdev->dev, wdt->base);
 out_err:
-       devm_kfree(&pdev->dev, wdt);

It is necessary?

 out_release:
-       devm_release_mem_region(&pdev->dev, res->start, resource_size(res));

It is necessary?


       return rc;
 }


sh_wdt_remove:

       ...
       unregister_reboot_notifier(&sh_wdt_notifier);
       devm_release_mem_region(&pdev->dev, res->start, resource_size(res));
       devm_iounmap(&pdev->dev, wdt->base);
       devm_kfree(&pdev->dev, wdt);

These lines should be deleted if the driver has detached.


       return 0;
}


On the other hand, perhaps devm_kfree is needed in probe function that
succeeds, eg in drivers/input/keyboard/samsung-keypad.c:

       if (pdev->dev.of_node) {
               devm_kfree(&pdev->dev, (void *)pdata->keymap_data->keymap);
               devm_kfree(&pdev->dev, (void *)pdata->keymap_data);
               devm_kfree(&pdev->dev, (void *)pdata);
       }
       return 0;

julia
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux