linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] [ARM] omap-pm: resource: Lock resource list in update_resource_level
@ 2010-05-04  0:34 Mike Chan
  2010-05-04  0:34 ` [PATCH 2/2] [ARM] omap-pm: resource: Only update resource level if there is a change Mike Chan
  0 siblings, 1 reply; 2+ messages in thread
From: Mike Chan @ 2010-05-04  0:34 UTC (permalink / raw)
  Cc: khilman, linux-omap, Mike Chan

Take the resource mutex when iterating over the resource user_list.
A race can occur if resource_request() adds a first time user to
the user_list while update_resource_level() is called.

Signed-off-by: Mike Chan <mike@android.com>
---
 arch/arm/plat-omap/resource.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/arm/plat-omap/resource.c b/arch/arm/plat-omap/resource.c
index f769f7c..6d3bba6 100644
--- a/arch/arm/plat-omap/resource.c
+++ b/arch/arm/plat-omap/resource.c
@@ -106,6 +106,7 @@ static int update_resource_level(struct shared_resource *resp)
 	unsigned long target_level;
 	int ret;
 
+	mutex_lock(&resp->resource_mutex);
 	/* Regenerate the target_value for the resource */
 	if (resp->flags & RES_TYPE_PERFORMANCE) {
 		target_level = RES_PERFORMANCE_DEFAULTLEVEL;
@@ -118,9 +119,11 @@ static int update_resource_level(struct shared_resource *resp)
 			if (user->level < target_level)
 				target_level = user->level;
 	} else {
+		mutex_unlock(&resp->resource_mutex);
 		pr_debug("SRF: Unknown resource type\n");
 		return -EINVAL;
 	}
+	mutex_unlock(&resp->resource_mutex);
 
 	pr_debug("SRF: Changing Level for resource %s to %ld\n",
 				resp->name, target_level);
@@ -439,10 +442,12 @@ int resource_release(const char *name, struct device *dev)
 	list_del(&user->node);
 	free_user(user);
 
-	/* Recompute and set the current level for the resource */
-	ret = update_resource_level(resp);
 res_unlock:
 	mutex_unlock(&resp->resource_mutex);
+	/* Recompute and set the current level for the resource */
+	if (!ret)
+		ret = update_resource_level(resp);
+
 	return ret;
 }
 EXPORT_SYMBOL(resource_release);
-- 
1.7.0.1


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

end of thread, other threads:[~2010-05-04  0:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-04  0:34 [PATCH 1/2] [ARM] omap-pm: resource: Lock resource list in update_resource_level Mike Chan
2010-05-04  0:34 ` [PATCH 2/2] [ARM] omap-pm: resource: Only update resource level if there is a change Mike Chan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).