Skip to contentSkip to conversation

ALSA: Fix of-node refcount unbalance

PATCH In review Takashi Iwai 3 participants 7 messages Feb 19, 2019 – Feb 20, 2019

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

cover ALSA: Fix of-node refcount unbalance

Hi,

here is a few patches to address the unbalanced OF-node refcount on powerpc and ac97 driver code. Another patchset for ASoC will follow later.

Takashi

===

Takashi Iwai (3):
ALSA: ac97: Fix of-node refcount unbalance
ALSA: aoa: Fix of-node refcount unbalance
ALSA: ppc: Fix of-node refcount unbalance

 sound/ac97/bus.c              | 2 +-
 sound/aoa/core/gpio-feature.c | 1 +
 sound/ppc/tumbler.c           | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)
Signature · 1 line
2.16.4
#1 lore raw

PATCH 1/3 ALSA: ac97: Fix of-node refcount unbalance

ac97_of_get_child_device() take the refcount of the node explicitly via of_node_get(), but this leads to an unbalance. The for_each_child_of_node() loop itself takes the refcount for each iteration node, hence you don't need to take the extra refcount again.

Fixes 2225a3e6af78 ("ALSA: ac97: add codecs devicetree binding")

---

Only compile-tested. Please review carefully. Thanks!

 sound/ac97/bus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/ac97/bus.c +1 -1
index 9f0c480489ef..9cbf6927abe9 100644
@@ -84,7 +84,7 @@ ac97_of_get_child_device(struct ac97_controller *ac97_ctrl, int idx,
 		if ((idx != of_property_read_u32(node, "reg", &reg)) ||
 		    !of_device_is_compatible(node, compat))
 			continue;
-		return of_node_get(node);
+		return node;
 	}
 
 	return NULL;
Signature · 1 line
2.16.4
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] ALSA: ac97: Fix of-node refcount unbalance

Quoted 11 lines · Takashi Iwai

ac97_of_get_child_device() take the refcount of the node explicitly via of_node_get(), but this leads to an unbalance. The for_each_child_of_node() loop itself takes the refcount for each iteration node, hence you don't need to take the extra refcount again.

Fixes 2225a3e6af78 ("ALSA: ac97: add codecs devicetree binding")

---

Only compile-tested. Please review carefully. Thanks!

Hi Takashi,

Cheers.

--
Robert

#3 lore raw

PATCH 2/3 ALSA: aoa: Fix of-node refcount unbalance

In reply to Takashi Iwai

We forgot to unreference a node obtained via of_find_node_by_name() after its usage.

---

Only compile-tested. Please review carefully. Thanks!

 sound/aoa/core/gpio-feature.c | 1 +
 1 file changed, 1 insertion(+)
sound/aoa/core/gpio-feature.c +1 -0
index 65557421fe0b..c3ff721e4660 100644
@@ -82,6 +82,7 @@ static struct device_node *get_gpio(char *name,
 			if (altname && (strcmp(audio_gpio, altname) == 0))
 				break;
 		}
+		of_node_put(gpio);
 		/* still not found, assume not there */
 		if (!np)
 			return NULL;
Signature · 1 line
2.16.4
maintainer Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] ALSA: aoa: Fix of-node refcount unbalance

Quoted 2 lines · Takashi Iwai

We forgot to unreference a node obtained via of_find_node_by_name() after its usage.

How did you find this now?! Though I guess something like smatch could find it, or even coccinelle?

Quoted 1 line

Only compile-tested. Please review carefully. Thanks!

Yes, looks right

I still have, but no longer run, the machine that uses this driver ... anyone need a Powermac G5 quad? ;-)

johannes

#5 lore raw

Re: [PATCH 2/3] ALSA: aoa: Fix of-node refcount unbalance

Quoted 7 lines · Johannes Berg
Quoted 2 lines · Takashi Iwai

We forgot to unreference a node obtained via of_find_node_by_name() after its usage.

How did you find this now?! Though I guess something like smatch could find it, or even coccinelle?

I'm old-fashioned, just did manual reviews casually after the discussion about the recent regression regarding OF node refcount in an ASoC driver :)

A coccinelle or such would be smarter, yeah :)

Quoted 8 lines
Quoted 1 line

Only compile-tested. Please review carefully. Thanks!

Yes, looks right

I still have, but no longer run, the machine that uses this driver ... anyone need a Powermac G5 quad? ;-)

Let's seek for museums :)

thanks,

Takashi

#6 lore raw

PATCH 3/3 ALSA: ppc: Fix of-node refcount unbalance

In reply to Takashi Iwai

We forgot to unreference the node when aborting from the loop of for_each_child_of_node() in snd_pmac_tumbler_init(). This leads to unbalanced node refcount. Fix it by adding the missing of_node_put() call.

---

Only compile-tested. Please review carefully. Thanks!

 sound/ppc/tumbler.c | 1 +
 1 file changed, 1 insertion(+)
sound/ppc/tumbler.c +1 -0
index 6d7ffffcce95..78e5798ae967 100644
@@ -1371,6 +1371,7 @@ int snd_pmac_tumbler_init(struct snd_pmac *chip)
 				mix->anded_reset = 1;
 			if (of_get_property(np, "layout-id", NULL))
 				mix->reset_on_sleep = 0;
+			of_node_put(np);
 			break;
 		}
 	}
Signature · 1 line
2.16.4