ALSA: control: clean up snd_ctl_hole_check()
authorClemens Ladisch <clemens@ladisch.de>
Mon, 7 Mar 2011 12:24:30 +0000 (13:24 +0100)
committerTakashi Iwai <tiwai@suse.de>
Tue, 8 Mar 2011 12:00:09 +0000 (13:00 +0100)
The return value of snd_ctl_hole_check() is used only to detect whether
to continue the loop in snd_ctl_find_hole() or not, so we can simplify
the code by changing this return type to a boolean.  Also rename this
function to better show what it actually does.

Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/control.c

index d1b5ce818a4ff7bb970b1e15e3b7214cb0224bf1..dc4afa6f99b15f64ef5c3bb3250f5eeaa7297e37 100644 (file)
@@ -279,31 +279,31 @@ void snd_ctl_free_one(struct snd_kcontrol *kcontrol)
 
 EXPORT_SYMBOL(snd_ctl_free_one);
 
-static unsigned int snd_ctl_hole_check(struct snd_card *card,
-                                      unsigned int count)
+static bool snd_ctl_remove_numid_conflict(struct snd_card *card,
+                                         unsigned int count)
 {
        struct snd_kcontrol *kctl;
 
        list_for_each_entry(kctl, &card->controls, list) {
                if (kctl->id.numid < card->last_numid + 1 + count &&
-                   kctl->id.numid + kctl->count > card->last_numid + 1)
-                       return card->last_numid = kctl->id.numid + kctl->count - 1;
+                   kctl->id.numid + kctl->count > card->last_numid + 1) {
+                       card->last_numid = kctl->id.numid + kctl->count - 1;
+                       return true;
+               }
        }
-       return card->last_numid;
+       return false;
 }
 
 static int snd_ctl_find_hole(struct snd_card *card, unsigned int count)
 {
-       unsigned int last_numid, iter = 100000;
+       unsigned int iter = 100000;
 
-       last_numid = card->last_numid;
-       while (last_numid != snd_ctl_hole_check(card, count)) {
+       while (snd_ctl_remove_numid_conflict(card, count)) {
                if (--iter == 0) {
                        /* this situation is very unlikely */
                        snd_printk(KERN_ERR "unable to allocate new control numid\n");
                        return -ENOMEM;
                }
-               last_numid = card->last_numid;
        }
        return 0;
 }