diff options
author | Julia Lawall <julia@diku.dk> | 2009-10-17 02:33:22 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2009-10-30 07:01:27 -0400 |
commit | 4b3be6afa4ab8b3fdce39df68bad71f8b85164de (patch) | |
tree | 9022bd2b563fabc987e31277782076db42946bb7 /sound | |
parent | b71207e9dc044b30d8b5d7f1c2290ba14563f05c (diff) |
ALSA: sound: Move dereference after NULL test and drop unnecessary NULL tests
In pcm.c, if the NULL test on pcm is needed, then the dereference should be
after the NULL test.
In dummy.c and ali5451.c, the context of the calls to
snd_card_dummy_new_mixer and snd_ali_free_voice show that dummy and pvoice,
respectively cannot be NULL.
A simplified version of the semantic match that detects this problem is as
follows (http://coccinelle.lip6.fr/):
// <smpl>
@match exists@
expression x, E;
identifier fld;
@@
* x->fld
... when != \(x = E\|&x\)
* x == NULL
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound')
-rw-r--r-- | sound/core/pcm.c | 5 | ||||
-rw-r--r-- | sound/drivers/dummy.c | 2 | ||||
-rw-r--r-- | sound/pci/ali5451/ali5451.c | 2 |
3 files changed, 4 insertions, 5 deletions
diff --git a/sound/core/pcm.c b/sound/core/pcm.c index 0c1440121c22..c69c60b2a48a 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c | |||
@@ -953,11 +953,12 @@ static int snd_pcm_dev_register(struct snd_device *device) | |||
953 | struct snd_pcm_substream *substream; | 953 | struct snd_pcm_substream *substream; |
954 | struct snd_pcm_notify *notify; | 954 | struct snd_pcm_notify *notify; |
955 | char str[16]; | 955 | char str[16]; |
956 | struct snd_pcm *pcm = device->device_data; | 956 | struct snd_pcm *pcm; |
957 | struct device *dev; | 957 | struct device *dev; |
958 | 958 | ||
959 | if (snd_BUG_ON(!pcm || !device)) | 959 | if (snd_BUG_ON(!device || !device->device_data)) |
960 | return -ENXIO; | 960 | return -ENXIO; |
961 | pcm = device->device_data; | ||
961 | mutex_lock(®ister_mutex); | 962 | mutex_lock(®ister_mutex); |
962 | err = snd_pcm_add(pcm); | 963 | err = snd_pcm_add(pcm); |
963 | if (err) { | 964 | if (err) { |
diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c index 6ba066c41d2e..146ef00f94a3 100644 --- a/sound/drivers/dummy.c +++ b/sound/drivers/dummy.c | |||
@@ -808,8 +808,6 @@ static int __devinit snd_card_dummy_new_mixer(struct snd_dummy *dummy) | |||
808 | unsigned int idx; | 808 | unsigned int idx; |
809 | int err; | 809 | int err; |
810 | 810 | ||
811 | if (snd_BUG_ON(!dummy)) | ||
812 | return -EINVAL; | ||
813 | spin_lock_init(&dummy->mixer_lock); | 811 | spin_lock_init(&dummy->mixer_lock); |
814 | strcpy(card->mixername, "Dummy Mixer"); | 812 | strcpy(card->mixername, "Dummy Mixer"); |
815 | 813 | ||
diff --git a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c index b458d208720b..aaf4da68969c 100644 --- a/sound/pci/ali5451/ali5451.c +++ b/sound/pci/ali5451/ali5451.c | |||
@@ -973,7 +973,7 @@ static void snd_ali_free_voice(struct snd_ali * codec, | |||
973 | void *private_data; | 973 | void *private_data; |
974 | 974 | ||
975 | snd_ali_printk("free_voice: channel=%d\n",pvoice->number); | 975 | snd_ali_printk("free_voice: channel=%d\n",pvoice->number); |
976 | if (pvoice == NULL || !pvoice->use) | 976 | if (!pvoice->use) |
977 | return; | 977 | return; |
978 | snd_ali_clear_voices(codec, pvoice->number, pvoice->number); | 978 | snd_ali_clear_voices(codec, pvoice->number, pvoice->number); |
979 | spin_lock_irq(&codec->voice_alloc); | 979 | spin_lock_irq(&codec->voice_alloc); |