diff mbox

omap: resource: Add per-resource mutex for OMAP resource framework

Message ID 1268179753-4063-1-git-send-email-y (mailing list archive)
State Accepted
Delegated to: Kevin Hilman
Headers show

Commit Message

y@google.com March 10, 2010, 12:09 a.m. UTC
None
diff mbox

Patch

diff --git a/arch/arm/plat-omap/include/plat/resource.h b/arch/arm/plat-omap/include/plat/resource.h
index 9acebcc..b5aff1f 100644
--- a/arch/arm/plat-omap/include/plat/resource.h
+++ b/arch/arm/plat-omap/include/plat/resource.h
@@ -54,6 +54,8 @@  struct shared_resource {
 	/* Shared resource operations */
 	struct shared_resource_ops *ops;
 	struct list_head node;
+	/* Protect each resource */
+	struct mutex resource_mutex;
 };
 
 struct shared_resource_ops {
diff --git a/arch/arm/plat-omap/resource.c b/arch/arm/plat-omap/resource.c
index f1cdecf..0a7b79b 100644
--- a/arch/arm/plat-omap/resource.c
+++ b/arch/arm/plat-omap/resource.c
@@ -277,6 +277,7 @@  int resource_register(struct shared_resource *resp)
 	}
 
 	INIT_LIST_HEAD(&resp->users_list);
+	mutex_init(&resp->resource_mutex);
 
 	/* Add the resource to the resource list */
 	list_add(&resp->node, &res_list);
@@ -339,14 +340,13 @@  int resource_request(const char *name, struct device *dev,
 	struct  users_list *user;
 	int 	found = 0, ret = 0;
 
-	down(&res_mutex);
-	resp = _resource_lookup(name);
+	resp = resource_lookup(name);
 	if (!resp) {
 		printk(KERN_ERR "resource_request: Invalid resource name\n");
-		ret = -EINVAL;
-		goto res_unlock;
+		return -EINVAL;
 	}
 
+	mutex_lock(&resp->resource_mutex);
 	/* Call the resource specific validate function */
 	if (resp->ops->validate_level) {
 		ret = resp->ops->validate_level(resp, level);
@@ -375,7 +375,7 @@  int resource_request(const char *name, struct device *dev,
 	user->level = level;
 
 res_unlock:
-	up(&res_mutex);
+	mutex_unlock(&resp->resource_mutex);
 	/*
 	 * Recompute and set the current level for the resource.
 	 * NOTE: update_resource level moved out of spin_lock, as it may call
@@ -406,14 +406,13 @@  int resource_release(const char *name, struct device *dev)
 	struct users_list *user;
 	int found = 0, ret = 0;
 
-	down(&res_mutex);
-	resp = _resource_lookup(name);
+	resp = resource_lookup(name);
 	if (!resp) {
 		printk(KERN_ERR "resource_release: Invalid resource name\n");
-		ret = -EINVAL;
-		goto res_unlock;
+		return -EINVAL;
 	}
 
+	mutex_lock(&resp->resource_mutex);
 	list_for_each_entry(user, &resp->users_list, node) {
 		if (user->dev == dev) {
 			found = 1;
@@ -434,7 +433,7 @@  int resource_release(const char *name, struct device *dev)
 	/* Recompute and set the current level for the resource */
 	ret = update_resource_level(resp);
 res_unlock:
-	up(&res_mutex);
+	mutex_unlock(&resp->resource_mutex);
 	return ret;
 }
 EXPORT_SYMBOL(resource_release);
@@ -458,7 +457,7 @@  int resource_get_level(const char *name)
 		up(&res_mutex);
 		return -EINVAL;
 	}
-	ret = resp->curr_level;
+	ret =  resp->curr_level;
 	up(&res_mutex);
 	return ret;
 }