Skip to content

Commit 5c33dd7

Browse files
Oliver NeukumJaroslav Kysela
authored andcommitted
[ALSA] cleanup and error reporting for sound/core/init.c
Make the control flow clear with indentation, adds some comments and improves error reporting. Signed-off-by: Oliver Neukum <oneukum@suse.de> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@suse.cz>
1 parent ad4d1de commit 5c33dd7

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

‎sound/core/init.c‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,28 @@ struct snd_card *snd_card_new(int idx, const char *xid,
114114
if (idx < 0) {
115115
int idx2;
116116
for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++)
117+
/* idx == -1 == 0xffff means: take any free slot */
117118
if (~snd_cards_lock & idx & 1<<idx2) {
118119
idx = idx2;
119120
if (idx >= snd_ecards_limit)
120121
snd_ecards_limit = idx + 1;
121122
break;
122123
}
123-
} else if (idx < snd_ecards_limit) {
124-
if (snd_cards_lock & (1 << idx))
125-
err = -ENODEV; /* invalid */
126-
} else if (idx < SNDRV_CARDS)
127-
snd_ecards_limit = idx + 1; /* increase the limit */
128-
else
129-
err = -ENODEV;
124+
} else {
125+
if (idx < snd_ecards_limit) {
126+
if (snd_cards_lock & (1 << idx))
127+
err = -EBUSY; /* invalid */
128+
} else {
129+
if (idx < SNDRV_CARDS)
130+
snd_ecards_limit = idx + 1; /* increase the limit */
131+
else
132+
err = -ENODEV;
133+
}
134+
}
130135
if (idx < 0 || err < 0) {
131136
mutex_unlock(&snd_card_mutex);
132-
snd_printk(KERN_ERR "cannot find the slot for index %d (range 0-%i)\n", idx, snd_ecards_limit - 1);
137+
snd_printk(KERN_ERR "cannot find the slot for index %d (range 0-%i), error: %d\n",
138+
idx, snd_ecards_limit - 1, err);
133139
goto __error;
134140
}
135141
snd_cards_lock |= 1 << idx; /* lock it */

0 commit comments

Comments
 (0)