Skip to contentSkip to conversation

ASoC trivial fixes

PATCH Applied Takashi Iwai 2 participants 23 messages Oct 7, 2014 – Oct 8, 2014

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

cover ASoC trivial fixes

Hi,

this is a series of fixes for the bugs I pointed yesterday. Since no fix action was seen yet, I quickly put band-aid over them.

thanks,

Takashi

#1 lore raw

PATCH 1/4 ASoC: mc13783: Fix of_node_put() call with uninitialized object

The commit [a28d167fbbef: ASoC: mc13783: Add missing of_node_put]
fixed the leak of OF node, but it calls of_node_put() unconditionally
at error path where the passed pointer might be uninitialized. It was
caught by a compiler warning:
sound/soc/codecs/mc13783.c:787:13: warning: 'np' may be used uninitialized in this function [-Wuninitialized]

This patch adds the NULL initialization properly for fixing this.

Fixes a28d167fbbef ('ASoC: mc13783: Add missing of_node_put')
---
 sound/soc/codecs/mc13783.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/mc13783.c +1 -1
index 388f90a597fa..f54fdf6fc20d 100644
@@ -749,7 +749,7 @@ static int __init mc13783_codec_probe(struct platform_device *pdev)
 {
 	struct mc13783_priv *priv;
 	struct mc13xxx_codec_platform_data *pdata = pdev->dev.platform_data;
-	struct device_node *np;
+	struct device_node *np = NULL;
 	int ret;
 
 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
Signature · 1 line
2.1.2
maintainer
#2 lore raw

Re: [PATCH 1/4] ASoC: mc13783: Fix of_node_put() call with uninitialized object

sound/soc/codecs/mc13783.c static int __init mc13783_codec_probe(struct platform_device *pdev) · line 752

Quoted 2 lines · Takashi Iwai
sound/soc/codecs/mc13783.c +1 -1
-	struct device_node *np;
+	struct device_node *np = NULL;

No, unconditional initialisations like this are worse than the problem they're trying to fix.

#3 lore raw

Re: [PATCH 1/4] ASoC: mc13783: Fix of_node_put() call with uninitialized object

At Tue, 7 Oct 2014 18:09:38 +0100,

Quoted 8 lines · Mark Brown

sound/soc/codecs/mc13783.c static int __init mc13783_codec_probe(struct platform_device *pdev) · line 752

Quoted 2 lines · Takashi Iwai
sound/soc/codecs/mc13783.c +1 -1
-	struct device_node *np;
+	struct device_node *np = NULL;

No, unconditional initialisations like this are worse than the problem they're trying to fix.

Which problem they're trying to fix...?

Initializing with NULL for the of_node_put() at error path is a standard idiom. An alternative fix would be to add "if (!pdata)" before of_node_put(np). But this isn't really intuitive, either (and even more error-prone, IMO).

Takashi

maintainer
#4 lore raw

Re: [PATCH 1/4] ASoC: mc13783: Fix of_node_put() call with uninitialized object

Quoted 11 lines · Takashi Iwai
Quoted 7 lines · Mark Brown

sound/soc/codecs/mc13783.c static int __init mc13783_codec_probe(struct platform_device *pdev) · line 752

Quoted 2 lines · Takashi Iwai
sound/soc/codecs/mc13783.c +1 -1
-	struct device_node *np;
+	struct device_node *np = NULL;

No, unconditional initialisations like this are worse than the problem they're trying to fix.

Which problem they're trying to fix...?

Shutting up warnings - because they just brute forcing they mean that if there's anything else we've missed the compiler won't be able to tell us about it.

Quoted 4 lines

Initializing with NULL for the of_node_put() at error path is a standard idiom. An alternative fix would be to add "if (!pdata)" before of_node_put(np). But this isn't really intuitive, either (and even more error-prone, IMO).

Well, in this case I'd just move the of_node_put() into the existing check for pdata since we don't ever reference np outside of that anyway.

#5 lore raw

Re: [PATCH 1/4] ASoC: mc13783: Fix of_node_put() call with uninitialized object

At Tue, 7 Oct 2014 18:23:37 +0100,

Quoted 18 lines · Mark Brown
Quoted 11 lines · Takashi Iwai
Quoted 7 lines · Mark Brown

sound/soc/codecs/mc13783.c static int __init mc13783_codec_probe(struct platform_device *pdev) · line 752

Quoted 2 lines · Takashi Iwai
sound/soc/codecs/mc13783.c +1 -1
-	struct device_node *np;
+	struct device_node *np = NULL;

No, unconditional initialisations like this are worse than the problem they're trying to fix.

Which problem they're trying to fix...?

Shutting up warnings - because they just brute forcing they mean that if there's anything else we've missed the compiler won't be able to tell us about it.

Quoted 7 lines
Quoted 4 lines

Initializing with NULL for the of_node_put() at error path is a standard idiom. An alternative fix would be to add "if (!pdata)" before of_node_put(np). But this isn't really intuitive, either (and even more error-prone, IMO).

Well, in this case I'd just move the of_node_put() into the existing check for pdata since we don't ever reference np outside of that anyway.

Yeah, that's an option, too, but it'd make the code less readable. So I chose the straightforward way.

Takashi

maintainer
#6 lore raw

Re: [PATCH 1/4] ASoC: mc13783: Fix of_node_put() call with uninitialized object

Quoted 7 lines · Takashi Iwai
Quoted 2 lines · Mark Brown

Well, in this case I'd just move the of_node_put() into the existing check for pdata since we don't ever reference np outside of that anyway.

Yeah, that's an option, too, but it'd make the code less readable. So I chose the straightforward way.

I don't actually see it as a readability concern - to me having the get and release close to each other and especially having them at the same level of indentation helps.

#7 lore raw

Re: [PATCH 1/4] ASoC: mc13783: Fix of_node_put() call with uninitialized object

At Tue, 7 Oct 2014 19:04:34 +0100,

Quoted 7 lines · Mark Brown
Quoted 4 lines · Takashi Iwai
Quoted 2 lines · Mark Brown

Well, in this case I'd just move the of_node_put() into the existing check for pdata since we don't ever reference np outside of that anyway.

Quoted 6 lines
Quoted 2 lines

Yeah, that's an option, too, but it'd make the code less readable. So I chose the straightforward way.

I don't actually see it as a readability concern - to me having the get and release close to each other and especially having them at the same level of indentation helps.

I do understand the merit, but it looks uglier to my taste. The success path goes again with if (ret). (Or we'd need two goto's or deeper if-else blocks.)

Takashi

sound/soc/codecs/mc13783.c +6 -3
index 388f90a597fa..cffbf09ba67c 100644
@@ -749,7 +749,6 @@ static int __init mc13783_codec_probe(struct platform_device *pdev)
 {
 	struct mc13783_priv *priv;
 	struct mc13xxx_codec_platform_data *pdata = pdev->dev.platform_data;
-	struct device_node *np;
 	int ret;
 
 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
@@ -760,6 +759,8 @@ static int __init mc13783_codec_probe(struct platform_device *pdev)
 		priv->adc_ssi_port = pdata->adc_ssi_port;
 		priv->dac_ssi_port = pdata->dac_ssi_port;
 	} else {
+		struct device_node *np;
+
 		np = of_get_child_by_name(pdev->dev.parent->of_node, "codec");
 		if (!np)
 			return -ENOSYS;
@@ -771,6 +772,10 @@ static int __init mc13783_codec_probe(struct platform_device *pdev)
 		ret = of_property_read_u32(np, "dac-port", &priv->dac_ssi_port);
 		if (ret)
 			goto out;
+	out:
+		of_node_put(np);
+		if (ret)
+			return ret;
 	}
 
 	dev_set_drvdata(&pdev->dev, priv);
@@ -783,8 +788,6 @@ static int __init mc13783_codec_probe(struct platform_device *pdev)
 		ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_mc13783,
 			mc13783_dai_async, ARRAY_SIZE(mc13783_dai_async));
 
-out:
-	of_node_put(np);
 	return ret;
 }
 
maintainer
#8 lore raw

Re: [PATCH 1/4] ASoC: mc13783: Fix of_node_put() call with uninitialized object

Quoted 9 lines · Takashi Iwai
Quoted 3 lines · Mark Brown

I don't actually see it as a readability concern - to me having the get and release close to each other and especially having them at the same level of indentation helps.

I do understand the merit, but it looks uglier to my taste. The success path goes again with if (ret). (Or we'd need two goto's or deeper if-else blocks.)

That looks ugly, yes - I'd be doing a check for ret before the second property call or something. Or just put the pdata check in the existing error path.

#9 lore raw

Re: [PATCH 1/4] ASoC: mc13783: Fix of_node_put() call with uninitialized object

At Tue, 7 Oct 2014 19:54:43 +0100,

Quoted 8 lines · Mark Brown
Quoted 5 lines · Takashi Iwai
Quoted 3 lines · Mark Brown

I don't actually see it as a readability concern - to me having the get and release close to each other and especially having them at the same level of indentation helps.

Quoted 7 lines
Quoted 3 lines

I do understand the merit, but it looks uglier to my taste. The success path goes again with if (ret). (Or we'd need two goto's or deeper if-else blocks.)

That looks ugly, yes - I'd be doing a check for ret before the second property call or something. Or just put the pdata check in the existing error path.

Well, I don't mind much how it'll be fixed, so I rather toss this fix to you. Feel free to cook :)

Takashi

maintainer
#10 lore raw

Re: [PATCH 1/4] ASoC: mc13783: Fix of_node_put() call with uninitialized object

Quoted 8 lines · Takashi Iwai
Quoted 3 lines · Mark Brown

That looks ugly, yes - I'd be doing a check for ret before the second property call or something. Or just put the pdata check in the existing error path.

Well, I don't mind much how it'll be fixed, so I rather toss this fix to you. Feel free to cook :)

Well, I can't even see the warning so as far as I can tell it's all fixed!

#11 lore raw

Re: [PATCH 1/4] ASoC: mc13783: Fix of_node_put() call with uninitialized object

At Wed, 8 Oct 2014 00:01:50 +0100,

Quoted 8 lines · Mark Brown
Quoted 5 lines · Takashi Iwai
Quoted 3 lines · Mark Brown

That looks ugly, yes - I'd be doing a check for ret before the second property call or something. Or just put the pdata check in the existing error path.

Quoted 5 lines
Quoted 2 lines

Well, I don't mind much how it'll be fixed, so I rather toss this fix to you. Feel free to cook :)

Well, I can't even see the warning so as far as I can tell it's all fixed!

Oh, rather trust your eyes, the fault is there obviously. It's a real bug that can be easily triggered, not in an exceptional error path.

BTW, putting pdata check in the exit path is more error-prone, as already mentioned. If anyone puts a new code with "goto out" before assignment of np, it hits again. So, a NULL initialization would be safer in the end.

Takashi

#12 lore raw

PATCH 2/4 ASoC: eukrea-tlv320: Fix of_node_put() call with uninitialized object

In reply to Takashi Iwai

The of_node_put() call in eukrea_tlv320_probe() may take an
uninitialized pointer, as compiler spotted out:
sound/soc/codecs/mc13783.c:787:13: warning: 'np' may be used uninitialized in this function [-Wuninitialized]

This patch adds the proper NULL initialization as a fix.

Fixes 66f232908de2 ('ASoC: eukrea-tlv320: Add DT support')
---
 sound/soc/fsl/eukrea-tlv320.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/fsl/eukrea-tlv320.c +1 -1
index eb093d5b85c4..d53b002595b6 100644
@@ -105,7 +105,7 @@ static int eukrea_tlv320_probe(struct platform_device *pdev)
 	int ret;
 	int int_port = 0, ext_port;
 	struct device_node *np = pdev->dev.of_node;
-	struct device_node *ssi_np, *codec_np;
+	struct device_node *ssi_np = NULL, *codec_np;
 
 	eukrea_tlv320.dev = &pdev->dev;
 	if (np) {
Signature · 1 line
2.1.2
maintainer
#13 lore raw

Re: [PATCH 2/4] ASoC: eukrea-tlv320: Fix of_node_put() call with uninitialized object

sound/soc/fsl/eukrea-tlv320.c static int eukrea_tlv320_probe(struct platform_device *pdev) · line 108

Quoted 2 lines · Takashi Iwai
sound/soc/fsl/eukrea-tlv320.c +1 -1
-	struct device_node *ssi_np, *codec_np;
+	struct device_node *ssi_np = NULL, *codec_np;

As well as the NULL thing mixing initialized and unintialized things in one declaration is something that's normally avoided.

#14 lore raw

Re: [PATCH 2/4] ASoC: eukrea-tlv320: Fix of_node_put() call with uninitialized object

At Tue, 7 Oct 2014 18:18:00 +0100,

Quoted 8 lines · Mark Brown

sound/soc/fsl/eukrea-tlv320.c static int eukrea_tlv320_probe(struct platform_device *pdev) · line 108

Quoted 2 lines · Takashi Iwai
sound/soc/fsl/eukrea-tlv320.c +1 -1
-	struct device_node *ssi_np, *codec_np;
+	struct device_node *ssi_np = NULL, *codec_np;

As well as the NULL thing mixing initialized and unintialized things in one declaration is something that's normally avoided.

I thought of that, too. For simplicity, we can do NULL initializations for both, of course, if you prefer.

Takashi

#15 lore raw

PATCH v2 2/4 ASoC: eukrea-tlv320: Fix of_node_put() call with uninitialized object

The of_node_put() call in eukrea_tlv320_probe() may take an
uninitialized pointer, as compiler spotted out:
sound/soc/fsl/eukrea-tlv320.c:221:14: warning: 'ssi_np' may be used uninitialized in this function [-Wuninitialized]

This patch adds the proper NULL initializations as a fix. (codec_np is also NULL initialized just for consistency.)

Fixes 66f232908de2 ('ASoC: eukrea-tlv320: Add DT support')
---
 sound/soc/fsl/eukrea-tlv320.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/fsl/eukrea-tlv320.c +1 -1
index eb093d5b85c4..d53b002595b6 100644
@@ -105,7 +105,7 @@ static int eukrea_tlv320_probe(struct platform_device *pdev)
 	int ret;
 	int int_port = 0, ext_port;
 	struct device_node *np = pdev->dev.of_node;
-	struct device_node *ssi_np, *codec_np;
+	struct device_node *ssi_np = NULL, *codec_np = NULL;
 
 	eukrea_tlv320.dev = &pdev->dev;
 	if (np) {
Signature · 1 line
2.1.2
maintainer Applied
#16 lore raw

Re: [PATCH v2 2/4] ASoC: eukrea-tlv320: Fix of_node_put() call with uninitialized object

Quoted 3 lines · Takashi Iwai

The of_node_put() call in eukrea_tlv320_probe() may take an
uninitialized pointer, as compiler spotted out:
sound/soc/fsl/eukrea-tlv320.c:221:14: warning: 'ssi_np' may be used uninitialized in this function [-Wuninitialized]

Applied, but please don't send new patches in the middle of e-mail threads - it can get really confusing trying to work out what the current version of the series looks like.

#17 lore raw

PATCH 3/4 ASoC: imx-es8328: Fix of_node_put() call with uninitialized object

In reply to Takashi Iwai

The of_node_put() calls in imx_es8328_probe() may take uninitialized pointers when reached though the early error path. This patch adds the proper NULL initialization for fixing these.

---
 sound/soc/fsl/imx-es8328.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/fsl/imx-es8328.c +1 -1
index 653e66d150c8..d6c55c88a069 100644
@@ -78,7 +78,7 @@ static const struct snd_soc_dapm_widget imx_es8328_dapm_widgets[] = {
 static int imx_es8328_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
-	struct device_node *ssi_np, *codec_np;
+	struct device_node *ssi_np = NULL, *codec_np = NULL;
 	struct platform_device *ssi_pdev;
 	struct imx_es8328_data *data;
 	u32 int_port, ext_port;
Signature · 1 line
2.1.2
maintainer Applied
#18 lore raw

Re: [PATCH 3/4] ASoC: imx-es8328: Fix of_node_put() call with uninitialized object

Quoted 3 lines · Takashi Iwai

The of_node_put() calls in imx_es8328_probe() may take uninitialized pointers when reached though the early error path. This patch adds the proper NULL initialization for fixing these.

Applied, thanks.

#19 lore raw

PATCH 4/4 ASoC: imx-es8328: Fix missing return code in imx_es8328_probe()

In reply to Takashi Iwai

An error code was forgotten to be passed in the error path of imx_es8328_probe().

---
 sound/soc/fsl/imx-es8328.c | 1 +
 1 file changed, 1 insertion(+)
sound/soc/fsl/imx-es8328.c +1 -0
index d6c55c88a069..f8cf10e16ce9 100644
@@ -104,6 +104,7 @@ static int imx_es8328_probe(struct platform_device *pdev)
 	if (ext_port > MUX_PORT_MAX || ext_port == 0) {
 		dev_err(dev, "mux-ext-port: hardware only has %d mux ports\n",
 			MUX_PORT_MAX);
+		ret = -EINVAL;
 		goto fail;
 	}
 
Signature · 1 line
2.1.2
maintainer Applied
#20 lore raw

Re: [PATCH 4/4] ASoC: imx-es8328: Fix missing return code in imx_es8328_probe()

Quoted 2 lines · Takashi Iwai

An error code was forgotten to be passed in the error path of imx_es8328_probe().

Applied, thanks.

maintainer
#21 lore raw
In reply to Takashi Iwai
Quoted 2 lines · Takashi Iwai

this is a series of fixes for the bugs I pointed yesterday. Since no fix action was seen yet, I quickly put band-aid over them.

So, I now checked who you'd Cced - you didn't CC the Freescale guys so I'm not surprised you got no reply...

#22 lore raw

At Tue, 7 Oct 2014 18:11:34 +0100,

Quoted 8 lines · Mark Brown
Quoted 2 lines · Takashi Iwai

this is a series of fixes for the bugs I pointed yesterday. Since no fix action was seen yet, I quickly put band-aid over them.

So, I now checked who you'd Cced - you didn't CC the Freescale guys so I'm not surprised you got no reply...

Ah, right, I missed them for these parts.

Takashi