public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] platform: release resource itself instead of resource tree
@ 2019-04-25  6:24 junxiao.chang
  2019-05-30  3:50 ` Chang, Junxiao
  2019-07-25 13:38 ` Greg KH
  0 siblings, 2 replies; 5+ messages in thread
From: junxiao.chang @ 2019-04-25  6:24 UTC (permalink / raw)
  To: linux-kernel; +Cc: gregkh, rafael, junxiao.chang, lili.li

From: Junxiao Chang <junxiao.chang@intel.com>

When platform device is deleted or there is error in adding
device, platform device resources should be released. Currently
API release_resource is used to release platform device resources.
However, this API releases not only platform resource itself but
also its child resources. It might release resources which are
still in use. Calling remove_resource only releases current
resource itself, not resource tree, it moves its child resources
to up level.

For example, platform device 1 and device 2 are registered, then only
device 1 is unregistered in below code:

  ...
  // Register platform test device 1, resource 0xfed1a000 ~ 0xfed1afff
  pdev1 = platform_device_register_full(&pdevinfo1);

  // Register platform test device 2, resource 0xfed1a200 ~ 0xfed1a2ff
  pdev2 = platform_device_register_full(&pdevinfo2);

  // Now platform device 2 resource should be device 1 resource's child

  // Unregister device 1 only
  platform_device_unregister(pdev1);
  ...

Platform device 2 resource will be released as well because its
parent resource(device 1's resource) is released, this is not expected.
If using API remove_resource, device 2 resource will not be released.

This change fixed an intel pmc platform device resource issue when
intel pmc ipc kernel module is inserted/removed for twice.

Signed-off-by: Junxiao Chang <junxiao.chang@intel.com>
---
 drivers/base/platform.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index dab0a5a..5fd1a41 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -461,7 +461,7 @@ int platform_device_add(struct platform_device *pdev)
 	while (--i >= 0) {
 		struct resource *r = &pdev->resource[i];
 		if (r->parent)
-			release_resource(r);
+			remove_resource(r);
 	}
 
  err_out:
@@ -492,7 +492,7 @@ void platform_device_del(struct platform_device *pdev)
 		for (i = 0; i < pdev->num_resources; i++) {
 			struct resource *r = &pdev->resource[i];
 			if (r->parent)
-				release_resource(r);
+				remove_resource(r);
 		}
 	}
 }
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-07-26 14:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-25  6:24 [PATCH] platform: release resource itself instead of resource tree junxiao.chang
2019-05-30  3:50 ` Chang, Junxiao
2019-07-25 13:38 ` Greg KH
2019-07-26 10:24   ` Chang, Junxiao
2019-07-26 14:01     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox