Update of /cvsroot/alsa/alsa-kernel/core
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv738/core

Modified Files:
        control.c 
Log Message:
- fixed the oops in OSS mixer when the control elements are dynamically
  changed (e.g. emufx).
  mixer_oss.c handles the numid instead of kcontrol_t pointers.
- snd_ctl_find_id and snd_ctl_find_numid don't issue contros_rwsem.
  the caller has to handle it properly.


Index: control.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/core/control.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- control.c   19 Dec 2003 16:27:21 -0000      1.40
+++ control.c   26 Jan 2004 11:48:40 -0000      1.41
@@ -37,9 +37,6 @@
 
 #define snd_kctl_ioctl(n) list_entry(n, snd_kctl_ioctl_t, list)
 
-/* find id without lock */
-static snd_kcontrol_t *_ctl_find_id(snd_card_t * card, snd_ctl_elem_id_t *id);
-
 static DECLARE_RWSEM(snd_ioctl_rwsem);
 static LIST_HEAD(snd_control_ioctls);
 
@@ -311,7 +308,7 @@
        snd_assert(kcontrol->info != NULL, return -EINVAL);
        id = kcontrol->id;
        down_write(&card->controls_rwsem);
-       if (_ctl_find_id(card, &id)) {
+       if (snd_ctl_find_id(card, &id)) {
                up_write(&card->controls_rwsem);
                snd_ctl_free_one(kcontrol);
                snd_printd(KERN_ERR "control %i:%i:%i:%s:%i is already present\n",
@@ -379,7 +376,7 @@
        int ret;
 
        down_write(&card->controls_rwsem);
-       kctl = _ctl_find_id(card, id);
+       kctl = snd_ctl_find_id(card, id);
        if (kctl == NULL) {
                up_write(&card->controls_rwsem);
                return -ENOENT;
@@ -406,7 +403,7 @@
        int idx, ret;
 
        down_write(&card->controls_rwsem);
-       kctl = _ctl_find_id(card, id);
+       kctl = snd_ctl_find_id(card, id);
        if (kctl == NULL) {
                up_write(&card->controls_rwsem);
                return -ENOENT;
@@ -437,7 +434,7 @@
        snd_kcontrol_t *kctl;
 
        down_write(&card->controls_rwsem);
-       kctl = _ctl_find_id(card, src_id);
+       kctl = snd_ctl_find_id(card, src_id);
        if (kctl == NULL) {
                up_write(&card->controls_rwsem);
                return -ENOENT;
@@ -449,7 +446,19 @@
        return 0;
 }
 
-static snd_kcontrol_t *_ctl_find_numid(snd_card_t * card, unsigned int numid)
+/**
+ * snd_ctl_find_numid - find the control instance with the given number-id
+ * @card: the card instance
+ * @numid: the number-id to search
+ *
+ * Finds the control instance with the given number-id from the card.
+ *
+ * Returns the pointer of the instance if found, or NULL if not.
+ *
+ * The caller must down card->controls_rwsem before calling this function
+ * (if the race condition can happen).
+ */
+snd_kcontrol_t *snd_ctl_find_numid(snd_card_t * card, unsigned int numid)
 {
        struct list_head *list;
        snd_kcontrol_t *kctl;
@@ -463,14 +472,26 @@
        return NULL;
 }
 
-static snd_kcontrol_t *_ctl_find_id(snd_card_t * card, snd_ctl_elem_id_t *id)
+/**
+ * snd_ctl_find_id - find the control instance with the given id
+ * @card: the card instance
+ * @id: the id to search
+ *
+ * Finds the control instance with the given id from the card.
+ *
+ * Returns the pointer of the instance if found, or NULL if not.
+ *
+ * The caller must down card->controls_rwsem before calling this function
+ * (if the race condition can happen).
+ */
+snd_kcontrol_t *snd_ctl_find_id(snd_card_t * card, snd_ctl_elem_id_t *id)
 {
        struct list_head *list;
        snd_kcontrol_t *kctl;
 
        snd_runtime_check(card != NULL && id != NULL, return NULL);
        if (id->numid != 0)
-               return _ctl_find_numid(card, id->numid);
+               return snd_ctl_find_numid(card, id->numid);
        list_for_each(list, &card->controls) {
                kctl = snd_kcontrol(list);
                if (kctl->id.iface != id->iface)
@@ -490,42 +511,6 @@
        return NULL;
 }
 
-/**
- * snd_ctl_find_id - find the control instance with the given id
- * @card: the card instance
- * @id: the id to search
- *
- * Finds the control instance with the given id from the card.
- *
- * Returns the pointer of the instance if found, or NULL if not.
- */
-snd_kcontrol_t *snd_ctl_find_id(snd_card_t * card, snd_ctl_elem_id_t *id)
-{
-       snd_kcontrol_t *kctl;
-       down_read(&card->controls_rwsem);
-       kctl = _ctl_find_id(card, id);
-       up_read(&card->controls_rwsem);
-       return kctl;
-}
-
-/**
- * snd_ctl_find_numid - find the control instance with the given number-id
- * @card: the card instance
- * @numid: the number-id to search
- *
- * Finds the control instance with the given number-id from the card.
- *
- * Returns the pointer of the instance if found, or NULL if not.
- */
-snd_kcontrol_t *snd_ctl_find_numid(snd_card_t * card, unsigned int numid)
-{
-       snd_kcontrol_t *kctl;
-       down_read(&card->controls_rwsem);
-       kctl = _ctl_find_numid(card, numid);
-       up_read(&card->controls_rwsem);
-       return kctl;
-}
-
 static int snd_ctl_card_info(snd_card_t * card, snd_ctl_file_t * ctl,
                             unsigned int cmd, unsigned long arg)
 {
@@ -620,7 +605,7 @@
        if (copy_from_user(&info, _info, sizeof(info)))
                return -EFAULT;
        down_read(&card->controls_rwsem);
-       kctl = _ctl_find_id(card, &info.id);
+       kctl = snd_ctl_find_id(card, &info.id);
        if (kctl == NULL) {
                up_read(&card->controls_rwsem);
                return -ENOENT;
@@ -665,7 +650,7 @@
        if (copy_from_user(control, _control, sizeof(*control)))
                return -EFAULT;
        down_read(&card->controls_rwsem);
-       kctl = _ctl_find_id(card, &control->id);
+       kctl = snd_ctl_find_id(card, &control->id);
        if (kctl == NULL) {
                result = -ENOENT;
        } else {
@@ -706,7 +691,7 @@
        if (copy_from_user(control, _control, sizeof(*control)))
                return -EFAULT;
        down_read(&card->controls_rwsem);
-       kctl = _ctl_find_id(card, &control->id);
+       kctl = snd_ctl_find_id(card, &control->id);
        if (kctl == NULL) {
                result = -ENOENT;
        } else {
@@ -752,7 +737,7 @@
        if (copy_from_user(&id, _id, sizeof(id)))
                return -EFAULT;
        down_write(&card->controls_rwsem);
-       kctl = _ctl_find_id(card, &id);
+       kctl = snd_ctl_find_id(card, &id);
        if (kctl == NULL) {
                result = -ENOENT;
        } else {
@@ -780,7 +765,7 @@
        if (copy_from_user(&id, _id, sizeof(id)))
                return -EFAULT;
        down_write(&card->controls_rwsem);
-       kctl = _ctl_find_id(card, &id);
+       kctl = snd_ctl_find_id(card, &id);
        if (kctl == NULL) {
                result = -ENOENT;
        } else {
@@ -877,7 +862,7 @@
        info.id.numid = 0;
        memset(&kctl, 0, sizeof(kctl));
        down_write(&card->controls_rwsem);
-       if (!!((_kctl = _ctl_find_id(card, &info.id)) != NULL) ^ replace) {
+       if (!!((_kctl = snd_ctl_find_id(card, &info.id)) != NULL) ^ replace) {
                up_write(&card->controls_rwsem);
                return !replace ? -EBUSY : -ENOENT;
        }



-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Alsa-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/alsa-cvslog

Reply via email to