Skip to contentSkip to conversation

omap: resource: Fix race in register_resource()

PATCH In review Mike Chan 2 participants 5 messages Sep 17, 2009 – Sep 30, 2009

Subsystems (2)
lore
Share & tools
lore

Mike Chan

author
#0 lore raw

PATCH 1/1 omap: resource: Fix race in register_resource()

Checking if the resource is already registered and adding to the list must be atomic or bad things can happen.

---
 arch/arm/plat-omap/resource.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)
arch/arm/plat-omap/resource.c +8 -5
index 111020a..4631912 100644
@@ -255,6 +255,7 @@ int resource_refresh(void)
  */
 int resource_register(struct shared_resource *resp)
 {
+	int ret = 0;
 	if (!resp)
 		return -EINVAL;
 
@@ -262,12 +263,13 @@ int resource_register(struct shared_resource *resp)
 		return -EINVAL;
 
 	/* Verify that the resource is not already registered */
-	if (resource_lookup(resp->name))
-		return -EEXIST;
+	down(&res_mutex);
+	if (_resource_lookup(resp->name))
+		ret = -EEXIST;
+		goto out;
 
 	INIT_LIST_HEAD(&resp->users_list);
 
-	down(&res_mutex);
 	/* Add the resource to the resource list */
 	list_add(&resp->node, &res_list);
 
@@ -275,10 +277,11 @@ int resource_register(struct shared_resource *resp)
 	if (resp->ops->init)
 		resp->ops->init(resp);
 
-	up(&res_mutex);
 	pr_debug("resource: registered %s\n", resp->name);
 
-	return 0;
+out:
+	up(&res_mutex);
+	return ret;
 }
 EXPORT_SYMBOL(resource_register);
 
Signature · 1 line
1.5.4.5
author
#1 lore raw
Quoted 52 lines · Mike Chan

Checking if the resource is already registered and adding to the list must be atomic or bad things can happen.

---
 arch/arm/plat-omap/resource.c |   13 ++++++++-----

 1 files changed, 8 insertions(+), 5 deletions(-)
arch/arm/plat-omap/resource.c +8 -6
index 111020a..4631912 100644
@@ -255,6 +255,7 @@ int resource_refresh(void)
  */
  int resource_register(struct shared_resource *resp)
  {
+       int ret = 0;
        if (!resp)
                return -EINVAL;
 
@@ -262,12 +263,13 @@ int resource_register(struct shared_resource *resp)
                return -EINVAL;
 
        /* Verify that the resource is not already registered */
-       if (resource_lookup(resp->name))
-               return -EEXIST;
+       down(&res_mutex);
+       if (_resource_lookup(resp->name))
+               ret = -EEXIST;
+               goto out;
 
        INIT_LIST_HEAD(&resp->users_list);
 
-       down(&res_mutex);
        /* Add the resource to the resource list */
        list_add(&resp->node, &res_list);
 
@@ -275,10 +277,11 @@ int resource_register(struct shared_resource *resp)
        if (resp->ops->init)
                resp->ops->init(resp);
 
-       up(&res_mutex);
        pr_debug("resource: registered %s\n", resp->name);
 
-       return 0;
+out:
+       up(&res_mutex);
+       return ret;
  }
  EXPORT_SYMBOL(resource_register);
 
--
Quoted 3 lines

1.5.4.5

Kevin, this should be based off of your pm branch (2.6.30?)

-- Mike
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
In reply to Mike Chan
Quoted 4 lines · Mike Chan

Checking if the resource is already registered and adding to the list must be atomic or bad things can happen.

Thanks, this one applies. Pushing to PM branch and pm-2.6.29.

Kevin

Quoted 49 lines
---
 arch/arm/plat-omap/resource.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)
arch/arm/plat-omap/resource.c +8 -5
index 111020a..4631912 100644
@@ -255,6 +255,7 @@ int resource_refresh(void)
  */
 int resource_register(struct shared_resource *resp)
 {
+	int ret = 0;
 	if (!resp)
 		return -EINVAL;
 
@@ -262,12 +263,13 @@ int resource_register(struct shared_resource *resp)
 		return -EINVAL;
 
 	/* Verify that the resource is not already registered */
-	if (resource_lookup(resp->name))
-		return -EEXIST;
+	down(&res_mutex);
+	if (_resource_lookup(resp->name))
+		ret = -EEXIST;
+		goto out;
 
 	INIT_LIST_HEAD(&resp->users_list);
 
-	down(&res_mutex);
 	/* Add the resource to the resource list */
 	list_add(&resp->node, &res_list);
 
@@ -275,10 +277,11 @@ int resource_register(struct shared_resource *resp)
 	if (resp->ops->init)
 		resp->ops->init(resp);
 
-	up(&res_mutex);
 	pr_debug("resource: registered %s\n", resp->name);
 
-	return 0;
+out:
+	up(&res_mutex);
+	return ret;
 }
 EXPORT_SYMBOL(resource_register);
 
Signature · 1 line
1.5.4.5
#3 lore raw
In reply to Mike Chan
Quoted 21 lines · Mike Chan

Checking if the resource is already registered and adding to the list must be atomic or bad things can happen.

---
 arch/arm/plat-omap/resource.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)
arch/arm/plat-omap/resource.c +1 -0
index 111020a..4631912 100644
@@ -255,6 +255,7 @@ int resource_refresh(void)
  */
 int resource_register(struct shared_resource *resp)
 {
+	int ret = 0;
 	if (!resp)
 		return -EINVAL;
 

arch/arm/plat-omap/resource.c int resource_register(struct shared_resource *resp) · line 269

Quoted 9 lines
arch/arm/plat-omap/resource.c +4 -2
@@ -262,12 +263,13 @@ int resource_register(struct shared_resource *resp)
 		return -EINVAL;
 
 	/* Verify that the resource is not already registered */
-	if (resource_lookup(resp->name))
-		return -EEXIST;
+	down(&res_mutex);
+	if (_resource_lookup(resp->name))
+		ret = -EEXIST;
+		goto out;

Ahem, you're rebased version has a little problem. Missing {} block mans this goto is always executed and no resources are ever added.

I'll fix this up manually before applying, but some more testing next time would be helpful

Thanks,

Kevin

Quoted 22 lines
arch/arm/plat-omap/resource.c +3 -3
 	INIT_LIST_HEAD(&resp->users_list);
 
-	down(&res_mutex);
 	/* Add the resource to the resource list */
 	list_add(&resp->node, &res_list);
 
@@ -275,10 +277,11 @@ int resource_register(struct shared_resource *resp)
 	if (resp->ops->init)
 		resp->ops->init(resp);
 
-	up(&res_mutex);
 	pr_debug("resource: registered %s\n", resp->name);
 
-	return 0;
+out:
+	up(&res_mutex);
+	return ret;
 }
 EXPORT_SYMBOL(resource_register);
 
Signature · 1 line
1.5.4.5
author
#4 lore raw
Quoted 36 lines · Kevin Hilman
Quoted 21 lines · Mike Chan

Checking if the resource is already registered and adding to the list must be atomic or bad things can happen.

---
 arch/arm/plat-omap/resource.c |   13 ++++++++-----

 1 files changed, 8 insertions(+), 5 deletions(-)
arch/arm/plat-omap/resource.c +1 -0
index 111020a..4631912 100644
@@ -255,6 +255,7 @@ int resource_refresh(void)
   */
  int resource_register(struct shared_resource *resp)
  {
+     int ret = 0;
       if (!resp)
               return -EINVAL;
 

arch/arm/plat-omap/resource.c int resource_register(struct shared_resource *resp) · line 269

Quoted 9 lines
arch/arm/plat-omap/resource.c +4 -2
@@ -262,12 +263,13 @@ int resource_register(struct shared_resource *resp)
               return -EINVAL;
 
       /* Verify that the resource is not already registered */
-     if (resource_lookup(resp->name))
-             return -EEXIST;
+     down(&res_mutex);
+     if (_resource_lookup(resp->name))
+             ret = -EEXIST;
+             goto out;

Ahem, you're rebased version has a little problem.  Missing {} block mans this goto is always executed and no resources are ever added.

Quoted 3 lines

I'll fix this up manually before applying, but some more testing next time would be helpful

Opps, sorry about that :/ and thanks for cleaning it up.

-- Mike

Quoted 25 lines

Thanks,

Kevin

Quoted 20 lines
arch/arm/plat-omap/resource.c +3 -3
       INIT_LIST_HEAD(&resp->users_list);
 
-     down(&res_mutex);
       /* Add the resource to the resource list */
       list_add(&resp->node, &res_list);
 
@@ -275,10 +277,11 @@ int resource_register(struct shared_resource *resp)
       if (resp->ops->init)
               resp->ops->init(resp);
 
-     up(&res_mutex);
       pr_debug("resource: registered %s\n", resp->name);
 
-     return 0;
+out:
+     up(&res_mutex);
+     return ret;
  }
  EXPORT_SYMBOL(resource_register);
 
Quoted 3 lines
Quoted 2 lines

--
1.5.4.5

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html