Skip to contentSkip to conversation

devicetree: of_node_put() does not require holding devtree_lock

PATCH In review Sakari Ailus 4 participants 7 messages Feb 22, 2017 – Feb 28, 2017 4 messages not in the archive Device tree

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 devicetree: of_node_put() does not require holding devtree_lock

While holding a reference to a device_node it is allowed to put that node without holding devtree_lock spinlock. Move of_node_put() after releasing the spinlock.

---
 drivers/of/base.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/of/base.c +8 -8
index d4bea3c..a8d7fed 100644
@@ -286,8 +286,8 @@ struct device_node *of_find_all_nodes(struct device_node *prev)
 	raw_spin_lock_irqsave(&devtree_lock, flags);
 	np = __of_find_all_nodes(prev);
 	of_node_get(np);
-	of_node_put(prev);
 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	of_node_put(prev);
 	return np;
 }
 EXPORT_SYMBOL(of_find_all_nodes);
@@ -660,8 +660,8 @@ struct device_node *of_get_next_parent(struct device_node *node)
 
 	raw_spin_lock_irqsave(&devtree_lock, flags);
 	parent = of_node_get(node->parent);
-	of_node_put(node);
 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	of_node_put(node);
 	return parent;
 }
 EXPORT_SYMBOL(of_get_next_parent);
@@ -732,8 +732,8 @@ struct device_node *of_get_next_available_child(const struct device_node *node,
 		if (of_node_get(next))
 			break;
 	}
-	of_node_put(prev);
 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	of_node_put(prev);
 	return next;
 }
 EXPORT_SYMBOL(of_get_next_available_child);
@@ -875,8 +875,8 @@ struct device_node *of_find_node_by_name(struct device_node *from,
 		if (np->name && (of_node_cmp(np->name, name) == 0)
 		    && of_node_get(np))
 			break;
-	of_node_put(from);
 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	of_node_put(from);
 	return np;
 }
 EXPORT_SYMBOL(of_find_node_by_name);
@@ -904,8 +904,8 @@ struct device_node *of_find_node_by_type(struct device_node *from,
 		if (np->type && (of_node_cmp(np->type, type) == 0)
 		    && of_node_get(np))
 			break;
-	of_node_put(from);
 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	of_node_put(from);
 	return np;
 }
 EXPORT_SYMBOL(of_find_node_by_type);
@@ -935,8 +935,8 @@ struct device_node *of_find_compatible_node(struct device_node *from,
 		if (__of_device_is_compatible(np, compatible, type, NULL) &&
 		    of_node_get(np))
 			break;
-	of_node_put(from);
 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	of_node_put(from);
 	return np;
 }
 EXPORT_SYMBOL(of_find_compatible_node);
@@ -970,8 +970,8 @@ struct device_node *of_find_node_with_property(struct device_node *from,
 		}
 	}
 out:
-	of_node_put(from);
 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	of_node_put(from);
 	return np;
 }
 EXPORT_SYMBOL(of_find_node_with_property);
@@ -1051,8 +1051,8 @@ struct device_node *of_find_matching_node_and_match(struct device_node *from,
 			break;
 		}
 	}
-	of_node_put(from);
 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	of_node_put(from);
 	return np;
 }
 EXPORT_SYMBOL(of_find_matching_node_and_match);
Signature · 6 lines
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#1 lore raw
Quoted 3 lines · Sakari Ailus

While holding a reference to a device_node it is allowed to put that node without holding devtree_lock spinlock. Move of_node_put() after releasing the spinlock.

True, but why do you really care? It is not a heavyweight operation.

Rob

Quoted 97 lines
---
 drivers/of/base.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/of/base.c +8 -9
index d4bea3c..a8d7fed 100644
@@ -286,8 +286,8 @@ struct device_node *of_find_all_nodes(struct device_node *prev)
        raw_spin_lock_irqsave(&devtree_lock, flags);
        np = __of_find_all_nodes(prev);
        of_node_get(np);
-       of_node_put(prev);
        raw_spin_unlock_irqrestore(&devtree_lock, flags);
+       of_node_put(prev);
        return np;
 }
 EXPORT_SYMBOL(of_find_all_nodes);
@@ -660,8 +660,8 @@ struct device_node *of_get_next_parent(struct device_node *node)
 
        raw_spin_lock_irqsave(&devtree_lock, flags);
        parent = of_node_get(node->parent);
-       of_node_put(node);
        raw_spin_unlock_irqrestore(&devtree_lock, flags);
+       of_node_put(node);
        return parent;
 }
 EXPORT_SYMBOL(of_get_next_parent);
@@ -732,8 +732,8 @@ struct device_node *of_get_next_available_child(const struct device_node *node,
                if (of_node_get(next))
                        break;
        }
-       of_node_put(prev);
        raw_spin_unlock_irqrestore(&devtree_lock, flags);
+       of_node_put(prev);
        return next;
 }
 EXPORT_SYMBOL(of_get_next_available_child);
@@ -875,8 +875,8 @@ struct device_node *of_find_node_by_name(struct device_node *from,
                if (np->name && (of_node_cmp(np->name, name) == 0)
                    && of_node_get(np))
                        break;
-       of_node_put(from);
        raw_spin_unlock_irqrestore(&devtree_lock, flags);
+       of_node_put(from);
        return np;
 }
 EXPORT_SYMBOL(of_find_node_by_name);
@@ -904,8 +904,8 @@ struct device_node *of_find_node_by_type(struct device_node *from,
                if (np->type && (of_node_cmp(np->type, type) == 0)
                    && of_node_get(np))
                        break;
-       of_node_put(from);
        raw_spin_unlock_irqrestore(&devtree_lock, flags);
+       of_node_put(from);
        return np;
 }
 EXPORT_SYMBOL(of_find_node_by_type);
@@ -935,8 +935,8 @@ struct device_node *of_find_compatible_node(struct device_node *from,
                if (__of_device_is_compatible(np, compatible, type, NULL) &&
                    of_node_get(np))
                        break;
-       of_node_put(from);
        raw_spin_unlock_irqrestore(&devtree_lock, flags);
+       of_node_put(from);
        return np;
 }
 EXPORT_SYMBOL(of_find_compatible_node);
@@ -970,8 +970,8 @@ struct device_node *of_find_node_with_property(struct device_node *from,
                }
        }
 out:
-       of_node_put(from);
        raw_spin_unlock_irqrestore(&devtree_lock, flags);
+       of_node_put(from);
        return np;
 }
 EXPORT_SYMBOL(of_find_node_with_property);
@@ -1051,8 +1051,8 @@ struct device_node *of_find_matching_node_and_match(struct device_node *from,
                        break;
                }
        }
-       of_node_put(from);
        raw_spin_unlock_irqrestore(&devtree_lock, flags);
+       of_node_put(from);
        return np;
 }
 EXPORT_SYMBOL(of_find_matching_node_and_match);
--

2.7.4

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

#3 lore raw
In reply to a message not in the archive

Adding Rob.

Quoted 3 lines · Sakari Ailus

While holding a reference to a device_node it is allowed to put that node without holding devtree_lock spinlock. Move of_node_put() after releasing the spinlock.

Please explain why the change fixes or improves the code. In other words, what is the point of the change?

Please use getmaintainer to find who to send the patch to.

-Frank

Quoted 11 lines
---
 drivers/of/base.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/of/base.c +0 -0
index d4bea3c..a8d7fed 100644

drivers/of/base.c struct device_node *of_find_all_nodes(struct device_node *prev) · line 293

Quoted 9 lines
drivers/of/base.c +1 -1
@@ -286,8 +286,8 @@ struct device_node *of_find_all_nodes(struct device_node *prev)
 	raw_spin_lock_irqsave(&devtree_lock, flags);
 	np = __of_find_all_nodes(prev);
 	of_node_get(np);
-	of_node_put(prev);
 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	of_node_put(prev);
 	return np;
 }
 EXPORT_SYMBOL(of_find_all_nodes);

< snip >

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

#5 lore raw
In reply to a message not in the archive

Hi Frank,

Quoted 9 lines · Frank Rowand

Adding Rob.

Quoted 3 lines · Sakari Ailus

While holding a reference to a device_node it is allowed to put that node without holding devtree_lock spinlock. Move of_node_put() after releasing the spinlock.

Please explain why the change fixes or improves the code. In other words, what is the point of the change?

The spinlock is simply not needed, that's all. I'd say generally moving code that does not require serialising out of a serialised section does improve the code, sometimes also the readability of the code, especially if it doesn't get more complicated as a result.

Quoted 2 lines

Please use getmaintainer to find who to send the patch to.

I'll do that the next time.

Signature · 8 lines
Kind regards,

Sakari Ailus
sakari.ailus-VuQAYsv1563Yd54FQh9/[email protected]
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw
In reply to a message not in the archive
Quoted 5 lines · Sakari Ailus

While holding a reference to a device_node it is allowed to put that node without holding devtree_lock spinlock. Move of_node_put() after releasing the spinlock.

I would rather leave this code the way it is.

The change is a micro-optimization that is not going to have any real impact on performance.

The change also makes the code less clear and readable. (Not significantly, but very slightly). THe code in the current form slightly emphasizes the balancing of gets and puts. I know that this is nit picking, but so be it.

Thus the change is on balance code churn.

-Frank

Quoted 80 lines
---
 drivers/of/base.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/of/base.c +7 -7
index d4bea3c..a8d7fed 100644
@@ -286,8 +286,8 @@ struct device_node *of_find_all_nodes(struct device_node *prev)
 	raw_spin_lock_irqsave(&devtree_lock, flags);
 	np = __of_find_all_nodes(prev);
 	of_node_get(np);
-	of_node_put(prev);
 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	of_node_put(prev);
 	return np;
 }
 EXPORT_SYMBOL(of_find_all_nodes);
@@ -660,8 +660,8 @@ struct device_node *of_get_next_parent(struct device_node *node)
 
 	raw_spin_lock_irqsave(&devtree_lock, flags);
 	parent = of_node_get(node->parent);
-	of_node_put(node);
 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	of_node_put(node);
 	return parent;
 }
 EXPORT_SYMBOL(of_get_next_parent);
@@ -732,8 +732,8 @@ struct device_node *of_get_next_available_child(const struct device_node *node,
 		if (of_node_get(next))
 			break;
 	}
-	of_node_put(prev);
 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	of_node_put(prev);
 	return next;
 }
 EXPORT_SYMBOL(of_get_next_available_child);
@@ -875,8 +875,8 @@ struct device_node *of_find_node_by_name(struct device_node *from,
 		if (np->name && (of_node_cmp(np->name, name) == 0)
 		    && of_node_get(np))
 			break;
-	of_node_put(from);
 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	of_node_put(from);
 	return np;
 }
 EXPORT_SYMBOL(of_find_node_by_name);
@@ -904,8 +904,8 @@ struct device_node *of_find_node_by_type(struct device_node *from,
 		if (np->type && (of_node_cmp(np->type, type) == 0)
 		    && of_node_get(np))
 			break;
-	of_node_put(from);
 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	of_node_put(from);
 	return np;
 }
 EXPORT_SYMBOL(of_find_node_by_type);
@@ -935,8 +935,8 @@ struct device_node *of_find_compatible_node(struct device_node *from,
 		if (__of_device_is_compatible(np, compatible, type, NULL) &&
 		    of_node_get(np))
 			break;
-	of_node_put(from);
 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	of_node_put(from);
 	return np;
 }
 EXPORT_SYMBOL(of_find_compatible_node);
@@ -970,8 +970,8 @@ struct device_node *of_find_node_with_property(struct device_node *from,
 		}
 	}
 out:
-	of_node_put(from);
 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	of_node_put(from);
 	return np;
 }
 EXPORT_SYMBOL(of_find_node_with_property);

drivers/of/base.c struct device_node *of_find_matching_node_and_match(struct device_node *from, · line 1058

Quoted 9 lines
drivers/of/base.c +1 -1
@@ -1051,8 +1051,8 @@ struct device_node *of_find_matching_node_and_match(struct device_node *from,
 			break;
 		}
 	}
-	of_node_put(from);
 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
+	of_node_put(from);
 	return np;
 }
 EXPORT_SYMBOL(of_find_matching_node_and_match);

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

#8 lore raw
In reply to a message not in the archive
Quoted 11 lines · Frank Rowand
Quoted 5 lines · Sakari Ailus

While holding a reference to a device_node it is allowed to put that node without holding devtree_lock spinlock. Move of_node_put() after releasing the spinlock.

I would rather leave this code the way it is.

The change is a micro-optimization that is not going to have any real impact on performance.

I have the same feelings.

Quoted 9 lines

The change also makes the code less clear and readable. (Not significantly, but very slightly). THe code in the current form slightly emphasizes the balancing of gets and puts. I know that this is nit picking, but so be it.

Thus the change is on balance code churn.

-Frank

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

#10 lore raw
In reply to a message not in the archive

Hi Rob and Frank,

Quoted 6 lines · Rob Herring
Quoted 5 lines · Frank Rowand
Quoted 4 lines · Sakari Ailus

While holding a reference to a device_node it is allowed to put that node without holding devtree_lock spinlock. Move of_node_put() after releasing the spinlock.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

I would rather leave this code the way it is.

The change is a micro-optimization that is not going to have any real impact on performance.

I have the same feelings.

Fair enough. Feel free to ignore the patch then.

Signature · 8 lines
Kind regards,

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