alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: sudarshan.bisht@nokia.com
To: alsa-devel@alsa-project.org
Subject: [PATCH 1/3 v3] alsa-lib: fixed coverity reported issues under "FORWARD_NULL" checker.
Date: Mon,  4 Apr 2011 11:53:57 +0300	[thread overview]
Message-ID: <1301907239-1873-1-git-send-email-sudarshan.bisht@nokia.com> (raw)

From: Sudarshan Bisht <sudarshan.bisht@nokia.com>

Coverity Static Analysis helps developers find hard-to-spot,
yet potentially crash-causing defects early in the development phase,
reducing the cost,time, and risk of software errors.

This patch has fix for situations where variable can be NULL 
but not been checked beforehand.

---
 modules/mixer/simple/sbasedl.c |    2 +-
 src/conf.c                     |    1 +
 src/hwdep/hwdep.c              |    1 +
 src/pcm/pcm_hooks.c            |    1 +
 src/pcm/pcm_simple.c           |    2 +-
 src/rawmidi/rawmidi.c          |    1 +
 src/rawmidi/rawmidi_virt.c     |    8 +++++---
 7 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/modules/mixer/simple/sbasedl.c b/modules/mixer/simple/sbasedl.c
index 0137586..494802f 100644
--- a/modules/mixer/simple/sbasedl.c
+++ b/modules/mixer/simple/sbasedl.c
@@ -99,7 +99,7 @@ int mixer_simple_basic_dlopen(snd_mixer_class_t *class,
       __error:
       	if (initflag)
       		free(priv);
-	if (h == NULL)
+	if (h)
 		snd_dlclose(h);
 	free(xlib);
 	return -ENXIO;
diff --git a/src/conf.c b/src/conf.c
index 8939d62..ddefff6 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -3268,6 +3268,7 @@ static int snd_config_hooks_call(snd_config_t *root, snd_config_t *config, snd_c
 		snd_config_iterator_t i, next;
 		if (snd_config_get_type(func_conf) != SND_CONFIG_TYPE_COMPOUND) {
 			SNDERR("Invalid type for func %s definition", str);
+			err = -EINVAL;
 			goto _err;
 		}
 		snd_config_for_each(i, next, func_conf) {
diff --git a/src/hwdep/hwdep.c b/src/hwdep/hwdep.c
index b882b35..5dc791c 100644
--- a/src/hwdep/hwdep.c
+++ b/src/hwdep/hwdep.c
@@ -78,6 +78,7 @@ static int snd_hwdep_open_conf(snd_hwdep_t **hwdep,
 	if (err >= 0) {
 		if (snd_config_get_type(type_conf) != SND_CONFIG_TYPE_COMPOUND) {
 			SNDERR("Invalid type for HWDEP type %s definition", str);
+			err = -EINVAL;
 			goto _err;
 		}
 		snd_config_for_each(i, next, type_conf) {
diff --git a/src/pcm/pcm_hooks.c b/src/pcm/pcm_hooks.c
index 3a99d55..404d51e 100644
--- a/src/pcm/pcm_hooks.c
+++ b/src/pcm/pcm_hooks.c
@@ -385,6 +385,7 @@ static int snd_pcm_hook_add_conf(snd_pcm_t *pcm, snd_config_t *root, snd_config_
 	if (err >= 0) {
 		if (snd_config_get_type(type) != SND_CONFIG_TYPE_COMPOUND) {
 			SNDERR("Invalid type for PCM type %s definition", str);
+			err = -EINVAL;
 			goto _err;
 		}
 		snd_config_for_each(i, next, type) {
diff --git a/src/pcm/pcm_simple.c b/src/pcm/pcm_simple.c
index 975f699..f943ec0 100644
--- a/src/pcm/pcm_simple.c
+++ b/src/pcm/pcm_simple.c
@@ -89,7 +89,7 @@ static int set_hw_params(snd_pcm_t *pcm,
 			return err;
 		if (periods == 1)
 			return -EINVAL;
-		if (*period_time == 0) {
+		if (period_time) {
 			err = INTERNAL(snd_pcm_hw_params_get_period_time)(hw_params, period_time, NULL);
 			if (err < 0)
 				return err;
diff --git a/src/rawmidi/rawmidi.c b/src/rawmidi/rawmidi.c
index b28488a..0bd6b96 100644
--- a/src/rawmidi/rawmidi.c
+++ b/src/rawmidi/rawmidi.c
@@ -201,6 +201,7 @@ static int snd_rawmidi_open_conf(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp
 	if (err >= 0) {
 		if (snd_config_get_type(type_conf) != SND_CONFIG_TYPE_COMPOUND) {
 			SNDERR("Invalid type for RAWMIDI type %s definition", str);
+			err = -EINVAL;
 			goto _err;
 		}
 		snd_config_for_each(i, next, type_conf) {
diff --git a/src/rawmidi/rawmidi_virt.c b/src/rawmidi/rawmidi_virt.c
index 52b8984..e5b17e4 100644
--- a/src/rawmidi/rawmidi_virt.c
+++ b/src/rawmidi/rawmidi_virt.c
@@ -383,9 +383,11 @@ int snd_rawmidi_virtual_open(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp,
  _err:
 	if (seq_handle)
 		snd_seq_close(seq_handle);
-	if (virt->midi_event)
-		snd_midi_event_free(virt->midi_event);
-	free(virt);
+	if (virt) {
+		if (virt->midi_event)
+			snd_midi_event_free(virt->midi_event);
+		free(virt);
+	}
 	if (inputp)
 		free(*inputp);
 	if (outputp)
-- 
1.7.0.4

             reply	other threads:[~2011-04-04  8:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-04  8:53 sudarshan.bisht [this message]
2011-04-04  8:53 ` [PATCH 2/3 v3] alsa-lib: fixed coverity reported issues under "RESOURCE_LEAK" checker sudarshan.bisht
2011-04-04 17:30   ` Steve Calfee
2011-04-05  7:45     ` Sudarshan Bisht
2011-04-04  8:53 ` [PATCH 3/3 v3] alsa-lib: fixed coverity reported issues under "USE_AFTER_FREE" checker sudarshan.bisht
2011-04-04  9:12   ` Paul Menzel
2011-04-04 10:02     ` Sudarshan Bisht
2011-04-04  9:18 ` [PATCH 1/3 v3] alsa-lib: fixed coverity reported issues under "FORWARD_NULL" checker Mark Brown
2011-04-04 10:35   ` Takashi Iwai
2011-04-04 11:49     ` Mark Brown
2011-04-05  7:29   ` Sudarshan Bisht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1301907239-1873-1-git-send-email-sudarshan.bisht@nokia.com \
    --to=sudarshan.bisht@nokia.com \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).