Skip to contentSkip to conversation

mfd: twl4030-audio: fix sibling-node lookup

PATCH Applied Johan Hovold 3 participants 9 messages Nov 11, 2017 – Nov 29, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 mfd: twl4030-audio: fix sibling-node lookup

A helper purported to look up a child node based on its name was using the wrong of-helper and ended up prematurely freeing the parent of-node while leaking any matching node.

To make things worse, any matching node would not even necessarily be a child node as the whole device tree was searched depth-first starting at the parent.

Fixes 019a7e6b7b31 ("mfd: twl4030-audio: Add DT support")
Cc stable <[email protected]> # 3.7
Cc Peter Ujfalusi <[email protected]>
---
 drivers/mfd/twl4030-audio.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/mfd/twl4030-audio.c +7 -2
index da16bf45fab4..dc94ffc6321a 100644
@@ -159,13 +159,18 @@ unsigned int twl4030_audio_get_mclk(void)
 EXPORT_SYMBOL_GPL(twl4030_audio_get_mclk);
 
 static bool twl4030_audio_has_codec(struct twl4030_audio_data *pdata,
-			      struct device_node *node)
+			      struct device_node *parent)
 {
+	struct device_node *node;
+
 	if (pdata && pdata->codec)
 		return true;
 
-	if (of_find_node_by_name(node, "codec"))
+	node = of_get_child_by_name(parent, "codec");
+	if (node) {
+		of_node_put(node);
 		return true;
+	}
 
 	return false;
 }
Signature · 1 line
2.15.0
#1 lore raw

PATCH 2/2 mfd: twl6040: fix child-node lookup

Fix child-node lookup during probe, which ended up searching the whole device tree depth-first starting at the parent rather than just matching on its children.

To make things worse, the parent node was prematurely freed, while the child node was leaked.

Note that the CONFIG_OF compile guard can be removed as of_get_child_by_name() provides a !CONFIG_OF implementation which always fails.

Fixes 37e13cecaa14 ("mfd: Add support for Device Tree to twl6040")
Fixes ca2cad6ae38e ("mfd: Fix twl6040 build failure")
Cc stable <[email protected]> # 3.5
Cc Peter Ujfalusi <[email protected]>
Cc Samuel Ortiz <[email protected]>
---
 drivers/mfd/twl6040.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/mfd/twl6040.c +8 -4
index d66502d36ba0..dd19f17a1b63 100644
@@ -97,12 +97,16 @@ static struct reg_sequence twl6040_patch[] = {
 };
 
 
-static bool twl6040_has_vibra(struct device_node *node)
+static bool twl6040_has_vibra(struct device_node *parent)
 {
-#ifdef CONFIG_OF
-	if (of_find_node_by_name(node, "vibra"))
+	struct device_node *node;
+
+	node = of_get_child_by_name(parent, "vibra");
+	if (node) {
+		of_node_put(node);
 		return true;
-#endif
+	}
+
 	return false;
 }
 
Signature · 1 line
2.15.0
#5 lore raw
In reply to Johan Hovold
Quoted 8 lines · Johan Hovold

A helper purported to look up a child node based on its name was using the wrong of-helper and ended up prematurely freeing the parent of-node while leaking any matching node.

To make things worse, any matching node would not even necessarily be a child node as the whole device tree was searched depth-first starting at the parent.

Quoted 6 lines
Fixes 019a7e6b7b31 ("mfd: twl4030-audio: Add DT support")
Cc stable <[email protected]> # 3.7
Cc Peter Ujfalusi <[email protected]>
---
 drivers/mfd/twl4030-audio.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

For my own reference:

I'll pick this up later in the cycle.

Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#2 lore raw

Re: [PATCH 2/2] mfd: twl6040: fix child-node lookup

In reply to Johan Hovold
Quoted 11 lines · Johan Hovold

Fix child-node lookup during probe, which ended up searching the whole device tree depth-first starting at the parent rather than just matching on its children.

To make things worse, the parent node was prematurely freed, while the child node was leaked.

Note that the CONFIG_OF compile guard can be removed as of_get_child_by_name() provides a !CONFIG_OF implementation which always fails.

Quoted 8 lines
Fixes 37e13cecaa14 ("mfd: Add support for Device Tree to twl6040")
Fixes ca2cad6ae38e ("mfd: Fix twl6040 build failure")
Cc stable <[email protected]> # 3.5
Cc Peter Ujfalusi <[email protected]>
Cc Samuel Ortiz <[email protected]>
---
 drivers/mfd/twl6040.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

For my own reference:

I'll pick these up later in the cycle.

Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
Acked-by on v1 1/2
#6 lore raw
In reply to Johan Hovold
Quoted 7 lines · Johan Hovold

A helper purported to look up a child node based on its name was using the wrong of-helper and ended up prematurely freeing the parent of-node while leaking any matching node.

To make things worse, any matching node would not even necessarily be a child node as the whole device tree was searched depth-first starting at the parent.

I think it is the same case as with the twl6040, there were no of_get_child_by_name() when this was done...

Thanks for fixing it!

Quoted 34 lines
Fixes 019a7e6b7b31 ("mfd: twl4030-audio: Add DT support")
Cc stable <[email protected]> # 3.7
Cc Peter Ujfalusi <[email protected]>
---
 drivers/mfd/twl4030-audio.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/mfd/twl4030-audio.c +7 -2
index da16bf45fab4..dc94ffc6321a 100644
@@ -159,13 +159,18 @@ unsigned int twl4030_audio_get_mclk(void)
 EXPORT_SYMBOL_GPL(twl4030_audio_get_mclk);
 
 static bool twl4030_audio_has_codec(struct twl4030_audio_data *pdata,
-			      struct device_node *node)
+			      struct device_node *parent)
 {
+	struct device_node *node;
+
 	if (pdata && pdata->codec)
 		return true;
 
-	if (of_find_node_by_name(node, "codec"))
+	node = of_get_child_by_name(parent, "codec");
+	if (node) {
+		of_node_put(node);
 		return true;
+	}
 
 	return false;
 }
Signature · 4 lines
Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
Acked-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] mfd: twl6040: fix child-node lookup

In reply to Johan Hovold
Quoted 10 lines · Johan Hovold

Fix child-node lookup during probe, which ended up searching the whole device tree depth-first starting at the parent rather than just matching on its children.

To make things worse, the parent node was prematurely freed, while the child node was leaked.

Note that the CONFIG_OF compile guard can be removed as of_get_child_by_name() provides a !CONFIG_OF implementation which always fails.

Quoted 36 lines
Fixes 37e13cecaa14 ("mfd: Add support for Device Tree to twl6040")
Fixes ca2cad6ae38e ("mfd: Fix twl6040 build failure")
Cc stable <[email protected]> # 3.5
Cc Peter Ujfalusi <[email protected]>
Cc Samuel Ortiz <[email protected]>
---
 drivers/mfd/twl6040.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/mfd/twl6040.c +8 -4
index d66502d36ba0..dd19f17a1b63 100644
@@ -97,12 +97,16 @@ static struct reg_sequence twl6040_patch[] = {
 };
 
 
-static bool twl6040_has_vibra(struct device_node *node)
+static bool twl6040_has_vibra(struct device_node *parent)
 {
-#ifdef CONFIG_OF
-	if (of_find_node_by_name(node, "vibra"))
+	struct device_node *node;
+
+	node = of_get_child_by_name(parent, "vibra");
+	if (node) {
+		of_node_put(node);
 		return true;
-#endif
+	}
+
 	return false;
 }
 
Signature · 4 lines
Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
#7 lore raw
In reply to Peter Ujfalusi
Quoted 9 lines · Peter Ujfalusi
Quoted 7 lines · Johan Hovold

A helper purported to look up a child node based on its name was using the wrong of-helper and ended up prematurely freeing the parent of-node while leaking any matching node.

To make things worse, any matching node would not even necessarily be a child node as the whole device tree was searched depth-first starting at the parent.

Quoted 6 lines

I think it is the same case as with the twl6040, there were no of_get_child_by_name() when this was done...

Thanks for fixing it!

Thanks for the acks.

Johan

Applied
#8 lore raw
In reply to Johan Hovold
Quoted 8 lines · Johan Hovold

A helper purported to look up a child node based on its name was using the wrong of-helper and ended up prematurely freeing the parent of-node while leaking any matching node.

To make things worse, any matching node would not even necessarily be a child node as the whole device tree was searched depth-first starting at the parent.

Quoted 6 lines
Fixes 019a7e6b7b31 ("mfd: twl4030-audio: Add DT support")
Cc stable <[email protected]> # 3.7
Cc Peter Ujfalusi <[email protected]>
---
 drivers/mfd/twl4030-audio.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Applied, thanks.

Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
Applied
#4 lore raw

Re: [PATCH 2/2] mfd: twl6040: fix child-node lookup

In reply to Johan Hovold
Quoted 11 lines · Johan Hovold

Fix child-node lookup during probe, which ended up searching the whole device tree depth-first starting at the parent rather than just matching on its children.

To make things worse, the parent node was prematurely freed, while the child node was leaked.

Note that the CONFIG_OF compile guard can be removed as of_get_child_by_name() provides a !CONFIG_OF implementation which always fails.

Quoted 8 lines
Fixes 37e13cecaa14 ("mfd: Add support for Device Tree to twl6040")
Fixes ca2cad6ae38e ("mfd: Fix twl6040 build failure")
Cc stable <[email protected]> # 3.5
Cc Peter Ujfalusi <[email protected]>
Cc Samuel Ortiz <[email protected]>
---
 drivers/mfd/twl6040.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Applied, thanks.

Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog