All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] ASoC: small fixes for bugs reported by Coverity
@ 2013-10-28 13:21 Takashi Iwai
  2013-10-28 13:21 ` [PATCH 1/5] ASoC: Use strlcpy() for copying in snd_soc_info_enum_double() Takashi Iwai
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Takashi Iwai @ 2013-10-28 13:21 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Liam Girdwood

Hi,

this is another series of small fixes for bugs reported by Coverity,
this time about ASoC core codes.


Takashi

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/5] ASoC: Use strlcpy() for copying in snd_soc_info_enum_double()
  2013-10-28 13:21 [PATCH 0/5] ASoC: small fixes for bugs reported by Coverity Takashi Iwai
@ 2013-10-28 13:21 ` Takashi Iwai
  2013-10-28 16:25   ` Mark Brown
  2013-10-28 13:21 ` [PATCH 2/5] ASoC: DAPM: Fix use after free in error path Takashi Iwai
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Takashi Iwai @ 2013-10-28 13:21 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Liam Girdwood

The provided texts aren't guaranteed to be in the fixed size.
Spotted by coverity CID 139318.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/soc/soc-core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index afc3fa8..bdc1d74 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2551,8 +2551,9 @@ int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
 
 	if (uinfo->value.enumerated.item > e->max - 1)
 		uinfo->value.enumerated.item = e->max - 1;
-	strcpy(uinfo->value.enumerated.name,
-		e->texts[uinfo->value.enumerated.item]);
+	strlcpy(uinfo->value.enumerated.name,
+		e->texts[uinfo->value.enumerated.item],
+		sizeof(uinfo->value.enumerated.name));
 	return 0;
 }
 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
-- 
1.8.4.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/5] ASoC: DAPM: Fix use after free in error path
  2013-10-28 13:21 [PATCH 0/5] ASoC: small fixes for bugs reported by Coverity Takashi Iwai
  2013-10-28 13:21 ` [PATCH 1/5] ASoC: Use strlcpy() for copying in snd_soc_info_enum_double() Takashi Iwai
@ 2013-10-28 13:21 ` Takashi Iwai
  2013-10-28 16:35   ` Mark Brown
  2013-10-28 13:21 ` [PATCH 3/5] ASoC: DAPM: Fix uninitialized return value from snd_soc_dai_link_event() Takashi Iwai
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Takashi Iwai @ 2013-10-28 13:21 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Liam Girdwood

The error message in dapm_create_or_share_mixmux_kcontrol() refers to
the string "name", which may be "long_name" that has been already
freed.  Delay the release of long_name to the place just before return.

Spotted by coverity CID 1042678.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/soc/soc-dapm.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 2fb0b72..d2ff080 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -687,7 +687,7 @@ static int dapm_create_or_share_mixmux_kcontrol(struct snd_soc_dapm_widget *w,
 	int shared;
 	struct snd_kcontrol *kcontrol;
 	bool wname_in_long_name, kcname_in_long_name;
-	char *long_name;
+	char *long_name = NULL;
 	const char *name;
 	int ret;
 
@@ -745,24 +745,23 @@ static int dapm_create_or_share_mixmux_kcontrol(struct snd_soc_dapm_widget *w,
 
 			name = long_name;
 		} else if (wname_in_long_name) {
-			long_name = NULL;
 			name = w->name + prefix_len;
 		} else {
-			long_name = NULL;
 			name = w->kcontrol_news[kci].name;
 		}
 
 		kcontrol = snd_soc_cnew(&w->kcontrol_news[kci], NULL, name,
 					prefix);
-		kfree(long_name);
-		if (!kcontrol)
-			return -ENOMEM;
+		if (!kcontrol) {
+			ret = -ENOMEM;
+			goto error;
+		}
 		kcontrol->private_free = dapm_kcontrol_free;
 
 		ret = dapm_kcontrol_data_alloc(w, kcontrol);
 		if (ret) {
 			snd_ctl_free_one(kcontrol);
-			return ret;
+			goto error;
 		}
 
 		ret = snd_ctl_add(card, kcontrol);
@@ -770,16 +769,18 @@ static int dapm_create_or_share_mixmux_kcontrol(struct snd_soc_dapm_widget *w,
 			dev_err(dapm->dev,
 				"ASoC: failed to add widget %s dapm kcontrol %s: %d\n",
 				w->name, name, ret);
-			return ret;
+			goto error;
 		}
 	}
 
 	ret = dapm_kcontrol_add_widget(kcontrol, w);
 	if (ret)
-		return ret;
+		goto error;
 
 	w->kcontrols[kci] = kcontrol;
 
+ error:
+	kfree(long_name);
 	return 0;
 }
 
-- 
1.8.4.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/5] ASoC: DAPM: Fix uninitialized return value from snd_soc_dai_link_event()
  2013-10-28 13:21 [PATCH 0/5] ASoC: small fixes for bugs reported by Coverity Takashi Iwai
  2013-10-28 13:21 ` [PATCH 1/5] ASoC: Use strlcpy() for copying in snd_soc_info_enum_double() Takashi Iwai
  2013-10-28 13:21 ` [PATCH 2/5] ASoC: DAPM: Fix use after free in error path Takashi Iwai
@ 2013-10-28 13:21 ` Takashi Iwai
  2013-10-28 16:35   ` Mark Brown
  2013-10-28 13:21 ` [PATCH 4/5] ASoC: DAPM: Fix source list debugfs outputs Takashi Iwai
  2013-10-28 13:21 ` [PATCH 5/5] ASoC: DAPM: Return -ENOMEM in snd_soc_dapm_new_dai_widgets() Takashi Iwai
  4 siblings, 1 reply; 11+ messages in thread
From: Takashi Iwai @ 2013-10-28 13:21 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Liam Girdwood

In a slightest path (both source and sink hw_params are NULL), the
function may return an uninitialized value.

Spotted by coverity CID 703453.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/soc/soc-dapm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index d2ff080..c21c8e7 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -3428,6 +3428,8 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
 				goto out;
 			}
 		}
+
+		ret = 0;
 		break;
 
 	case SND_SOC_DAPM_POST_PMU:
-- 
1.8.4.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/5] ASoC: DAPM: Fix source list debugfs outputs
  2013-10-28 13:21 [PATCH 0/5] ASoC: small fixes for bugs reported by Coverity Takashi Iwai
                   ` (2 preceding siblings ...)
  2013-10-28 13:21 ` [PATCH 3/5] ASoC: DAPM: Fix uninitialized return value from snd_soc_dai_link_event() Takashi Iwai
@ 2013-10-28 13:21 ` Takashi Iwai
  2013-10-28 16:35   ` Mark Brown
  2013-10-28 13:21 ` [PATCH 5/5] ASoC: DAPM: Return -ENOMEM in snd_soc_dapm_new_dai_widgets() Takashi Iwai
  4 siblings, 1 reply; 11+ messages in thread
From: Takashi Iwai @ 2013-10-28 13:21 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Liam Girdwood

... due to a copy & paste error.

Spotted by coverity CID 710923.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/soc/soc-dapm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index c21c8e7..8ab2b35 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -1975,7 +1975,7 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
 				w->active ? "active" : "inactive");
 
 	list_for_each_entry(p, &w->sources, list_sink) {
-		if (p->connected && !p->connected(w, p->sink))
+		if (p->connected && !p->connected(w, p->source))
 			continue;
 
 		if (p->connect)
-- 
1.8.4.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 5/5] ASoC: DAPM: Return -ENOMEM in snd_soc_dapm_new_dai_widgets()
  2013-10-28 13:21 [PATCH 0/5] ASoC: small fixes for bugs reported by Coverity Takashi Iwai
                   ` (3 preceding siblings ...)
  2013-10-28 13:21 ` [PATCH 4/5] ASoC: DAPM: Fix source list debugfs outputs Takashi Iwai
@ 2013-10-28 13:21 ` Takashi Iwai
  2013-10-28 16:35   ` Mark Brown
  4 siblings, 1 reply; 11+ messages in thread
From: Takashi Iwai @ 2013-10-28 13:21 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Liam Girdwood

... instead of NULL dereferences.

Spotted by coverity CID 402004.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/soc/soc-dapm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 8ab2b35..458c672 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -3528,6 +3528,7 @@ int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
 		if (!w) {
 			dev_err(dapm->dev, "ASoC: Failed to create %s widget\n",
 				dai->driver->playback.stream_name);
+			return -ENOMEM;
 		}
 
 		w->priv = dai;
@@ -3546,6 +3547,7 @@ int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
 		if (!w) {
 			dev_err(dapm->dev, "ASoC: Failed to create %s widget\n",
 				dai->driver->capture.stream_name);
+			return -ENOMEM;
 		}
 
 		w->priv = dai;
-- 
1.8.4.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/5] ASoC: Use strlcpy() for copying in snd_soc_info_enum_double()
  2013-10-28 13:21 ` [PATCH 1/5] ASoC: Use strlcpy() for copying in snd_soc_info_enum_double() Takashi Iwai
@ 2013-10-28 16:25   ` Mark Brown
  0 siblings, 0 replies; 11+ messages in thread
From: Mark Brown @ 2013-10-28 16:25 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, Liam Girdwood


[-- Attachment #1.1: Type: text/plain, Size: 178 bytes --]

On Mon, Oct 28, 2013 at 02:21:46PM +0100, Takashi Iwai wrote:
> The provided texts aren't guaranteed to be in the fixed size.
> Spotted by coverity CID 139318.

Applied, thanks.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/5] ASoC: DAPM: Fix use after free in error path
  2013-10-28 13:21 ` [PATCH 2/5] ASoC: DAPM: Fix use after free in error path Takashi Iwai
@ 2013-10-28 16:35   ` Mark Brown
  0 siblings, 0 replies; 11+ messages in thread
From: Mark Brown @ 2013-10-28 16:35 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, Liam Girdwood


[-- Attachment #1.1: Type: text/plain, Size: 340 bytes --]

On Mon, Oct 28, 2013 at 02:21:47PM +0100, Takashi Iwai wrote:
> The error message in dapm_create_or_share_mixmux_kcontrol() refers to
> the string "name", which may be "long_name" that has been already
> freed.  Delay the release of long_name to the place just before return.

Applied, thanks.  Please use "dapm" not "DAPM" in the subject.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/5] ASoC: DAPM: Fix uninitialized return value from snd_soc_dai_link_event()
  2013-10-28 13:21 ` [PATCH 3/5] ASoC: DAPM: Fix uninitialized return value from snd_soc_dai_link_event() Takashi Iwai
@ 2013-10-28 16:35   ` Mark Brown
  0 siblings, 0 replies; 11+ messages in thread
From: Mark Brown @ 2013-10-28 16:35 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, Liam Girdwood


[-- Attachment #1.1: Type: text/plain, Size: 195 bytes --]

On Mon, Oct 28, 2013 at 02:21:48PM +0100, Takashi Iwai wrote:
> In a slightest path (both source and sink hw_params are NULL), the
> function may return an uninitialized value.

Applied, thanks.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/5] ASoC: DAPM: Fix source list debugfs outputs
  2013-10-28 13:21 ` [PATCH 4/5] ASoC: DAPM: Fix source list debugfs outputs Takashi Iwai
@ 2013-10-28 16:35   ` Mark Brown
  0 siblings, 0 replies; 11+ messages in thread
From: Mark Brown @ 2013-10-28 16:35 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, Liam Girdwood


[-- Attachment #1.1: Type: text/plain, Size: 115 bytes --]

On Mon, Oct 28, 2013 at 02:21:49PM +0100, Takashi Iwai wrote:
> ... due to a copy & paste error.

Applied, thanks.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 5/5] ASoC: DAPM: Return -ENOMEM in snd_soc_dapm_new_dai_widgets()
  2013-10-28 13:21 ` [PATCH 5/5] ASoC: DAPM: Return -ENOMEM in snd_soc_dapm_new_dai_widgets() Takashi Iwai
@ 2013-10-28 16:35   ` Mark Brown
  0 siblings, 0 replies; 11+ messages in thread
From: Mark Brown @ 2013-10-28 16:35 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, Liam Girdwood


[-- Attachment #1.1: Type: text/plain, Size: 116 bytes --]

On Mon, Oct 28, 2013 at 02:21:50PM +0100, Takashi Iwai wrote:
> ... instead of NULL dereferences.

Applied, thanks.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-10-28 16:36 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-28 13:21 [PATCH 0/5] ASoC: small fixes for bugs reported by Coverity Takashi Iwai
2013-10-28 13:21 ` [PATCH 1/5] ASoC: Use strlcpy() for copying in snd_soc_info_enum_double() Takashi Iwai
2013-10-28 16:25   ` Mark Brown
2013-10-28 13:21 ` [PATCH 2/5] ASoC: DAPM: Fix use after free in error path Takashi Iwai
2013-10-28 16:35   ` Mark Brown
2013-10-28 13:21 ` [PATCH 3/5] ASoC: DAPM: Fix uninitialized return value from snd_soc_dai_link_event() Takashi Iwai
2013-10-28 16:35   ` Mark Brown
2013-10-28 13:21 ` [PATCH 4/5] ASoC: DAPM: Fix source list debugfs outputs Takashi Iwai
2013-10-28 16:35   ` Mark Brown
2013-10-28 13:21 ` [PATCH 5/5] ASoC: DAPM: Return -ENOMEM in snd_soc_dapm_new_dai_widgets() Takashi Iwai
2013-10-28 16:35   ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.