Commit:     dc4c15d44b2b43279b2667baa7645c65c2ff960e
Parent:     c7308c81a8220ab68eebfadde37db881a2800064
Author:     Jean Delvare <[EMAIL PROTECTED]>
AuthorDate: Wed May 2 20:55:54 2007 +0200
Committer:  Greg Kroah-Hartman <[EMAIL PROTECTED]>
CommitDate: Wed May 2 18:57:59 2007 -0700

    platform: reorder platform_device_del
    In platform_device_del(), we currently delete the device resources
    first, then we delete the device itself. This causes a (minor) bug to
    occur when one unregisters a platform device before unregistering its
    platform driver, and the driver is requesting (in .probe()) and
    releasing (in .remove()) a resource of the device. The device
    resources are already gone by the time the driver gets the chance to
    release the resources it had been requesting, causing an error like:
    Trying to free nonexistent resource <0000000000000295-0000000000000296>
    If the platform driver is unregistered first, the problem doesn't
    occur, as the driver will have the opportunity to release the
    resources it had requested before the device resources themselves are
    released. It's a bit odd that unregistering the driver first or the
    device first doesn't lead to the same result.
    So I believe that we should delete the device first in
    platform_device_del(). I've searched the git history and found that it
    used to be the case before 2.6.8, but was changed here:
    > 2004/07/14 16:09:44-07:00 dtor_core
    > [PATCH] Driver core: Fix OOPS in device_platform_unregister
    > Driver core: platform_device_unregister should release resources first
    >              and only then call device_unregister, otherwise if there
    >              are no more references to the device it will be freed and
    >              the fucntion will try to access freed memory.
    However we now have an explicit call to put_device() at the end of
    platform_device_unregister() so I guess the original problem no longer
    exists and it is safe to revert that change.
    Signed-off-by: Jean Delvare <[EMAIL PROTECTED]>
    Signed-off-by: Greg Kroah-Hartman <[EMAIL PROTECTED]>
 drivers/base/platform.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 30480f6..17b5ece 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -292,20 +292,22 @@ EXPORT_SYMBOL_GPL(platform_device_add);
  *     @pdev:  platform device we're removing
  *     Note that this function will also release all memory- and port-based
- *     resources owned by the device (@dev->resource).
+ *     resources owned by the device (@dev->resource).  This function
+ *     must _only_ be externally called in error cases.  All other usage
+ *     is a bug.
 void platform_device_del(struct platform_device *pdev)
        int i;
        if (pdev) {
+               device_del(&pdev->dev);
                for (i = 0; i < pdev->num_resources; i++) {
                        struct resource *r = &pdev->resource[i];
                        if (r->flags & (IORESOURCE_MEM|IORESOURCE_IO))
-               device_del(&pdev->dev);
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at

Reply via email to