]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
Merge branch 'topic/ctl-list-cleanup' into for-linus
authorTakashi Iwai <tiwai@suse.de>
Mon, 23 Mar 2009 23:35:45 +0000 (00:35 +0100)
committerTakashi Iwai <tiwai@suse.de>
Mon, 23 Mar 2009 23:35:45 +0000 (00:35 +0100)
1  2 
include/sound/core.h
sound/core/init.c

diff --combined include/sound/core.h
index 59491f22da9450f9fa159880686c61abdf2d1619,bd4529e0c27e8539c2831357de87ab12281a887a..3dea79829acc0c53673533d421aa9ca15f3b9c06
@@@ -97,9 -97,9 +97,9 @@@ struct snd_device 
  
  struct snd_monitor_file {
        struct file *file;
-       struct snd_monitor_file *next;
        const struct file_operations *disconnected_f_op;
-       struct list_head shutdown_list;
+       struct list_head shutdown_list; /* still need to shutdown */
+       struct list_head list;  /* link of monitor files */
  };
  
  /* main structure for soundcard */
@@@ -134,7 -134,7 +134,7 @@@ struct snd_card 
        struct snd_info_entry *proc_id; /* the card id */
        struct proc_dir_entry *proc_root_link;  /* number link to real id */
  
-       struct snd_monitor_file *files; /* all files associated to this card */
+       struct list_head files_list;    /* all files associated to this card */
        struct snd_shutdown_f_ops *s_f_ops; /* file operations in the shutdown
                                                                state */
        spinlock_t files_lock;          /* lock the files for this card */
@@@ -296,20 -296,8 +296,20 @@@ int snd_card_locked(int card)
  extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd);
  #endif
  
 +int snd_card_create(int idx, const char *id,
 +                  struct module *module, int extra_size,
 +                  struct snd_card **card_ret);
 +
 +static inline __deprecated
  struct snd_card *snd_card_new(int idx, const char *id,
 -                       struct module *module, int extra_size);
 +                            struct module *module, int extra_size)
 +{
 +      struct snd_card *card;
 +      if (snd_card_create(idx, id, module, extra_size, &card) < 0)
 +              return NULL;
 +      return card;
 +}
 +
  int snd_card_disconnect(struct snd_card *card);
  int snd_card_free(struct snd_card *card);
  int snd_card_free_when_closed(struct snd_card *card);
@@@ -458,33 -446,21 +458,33 @@@ static inline int __snd_bug_on(int cond
  struct snd_pci_quirk {
        unsigned short subvendor;       /* PCI subvendor ID */
        unsigned short subdevice;       /* PCI subdevice ID */
 +      unsigned short subdevice_mask;  /* bitmask to match */
        int value;                      /* value */
  #ifdef CONFIG_SND_DEBUG_VERBOSE
        const char *name;               /* name of the device (optional) */
  #endif
  };
  
 -#define _SND_PCI_QUIRK_ID(vend,dev) \
 -      .subvendor = (vend), .subdevice = (dev)
 +#define _SND_PCI_QUIRK_ID_MASK(vend, mask, dev)       \
 +      .subvendor = (vend), .subdevice = (dev), .subdevice_mask = (mask)
 +#define _SND_PCI_QUIRK_ID(vend, dev) \
 +      _SND_PCI_QUIRK_ID_MASK(vend, 0xffff, dev)
  #define SND_PCI_QUIRK_ID(vend,dev) {_SND_PCI_QUIRK_ID(vend, dev)}
  #ifdef CONFIG_SND_DEBUG_VERBOSE
  #define SND_PCI_QUIRK(vend,dev,xname,val) \
        {_SND_PCI_QUIRK_ID(vend, dev), .value = (val), .name = (xname)}
 +#define SND_PCI_QUIRK_VENDOR(vend, xname, val)                        \
 +      {_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val), .name = (xname)}
 +#define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val)                       \
 +      {_SND_PCI_QUIRK_ID_MASK(vend, mask, dev),                       \
 +                      .value = (val), .name = (xname)}
  #else
  #define SND_PCI_QUIRK(vend,dev,xname,val) \
        {_SND_PCI_QUIRK_ID(vend, dev), .value = (val)}
 +#define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val)                       \
 +      {_SND_PCI_QUIRK_ID_MASK(vend, mask, dev), .value = (val)}
 +#define SND_PCI_QUIRK_VENDOR(vend, xname, val)                        \
 +      {_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val)}
  #endif
  
  const struct snd_pci_quirk *
diff --combined sound/core/init.c
index dc4b80c7f311b9fc5e15d30fa96da09a11e81462,05c6da554cbff0a014a98f635581720db5f7c474..fd56afe846ed6321d71e328147a5659423e2bce2
@@@ -121,44 -121,31 +121,44 @@@ static inline int init_info_for_card(st
  #endif
  
  /**
 - *  snd_card_new - create and initialize a soundcard structure
 + *  snd_card_create - create and initialize a soundcard structure
   *  @idx: card index (address) [0 ... (SNDRV_CARDS-1)]
   *  @xid: card identification (ASCII string)
   *  @module: top level module for locking
   *  @extra_size: allocate this extra size after the main soundcard structure
 + *  @card_ret: the pointer to store the created card instance
   *
   *  Creates and initializes a soundcard structure.
   *
 - *  Returns kmallocated snd_card structure. Creates the ALSA control interface
 - *  (which is blocked until snd_card_register function is called).
 + *  The function allocates snd_card instance via kzalloc with the given
 + *  space for the driver to use freely.  The allocated struct is stored
 + *  in the given card_ret pointer.
 + *
 + *  Returns zero if successful or a negative error code.
   */
 -struct snd_card *snd_card_new(int idx, const char *xid,
 -                       struct module *module, int extra_size)
 +int snd_card_create(int idx, const char *xid,
 +                  struct module *module, int extra_size,
 +                  struct snd_card **card_ret)
  {
        struct snd_card *card;
        int err, idx2;
  
 +      if (snd_BUG_ON(!card_ret))
 +              return -EINVAL;
 +      *card_ret = NULL;
 +
        if (extra_size < 0)
                extra_size = 0;
        card = kzalloc(sizeof(*card) + extra_size, GFP_KERNEL);
 -      if (card == NULL)
 -              return NULL;
 +      if (!card)
 +              return -ENOMEM;
        if (xid) {
 -              if (!snd_info_check_reserved_words(xid))
 +              if (!snd_info_check_reserved_words(xid)) {
 +                      snd_printk(KERN_ERR
 +                                 "given id string '%s' is reserved.\n", xid);
 +                      err = -EBUSY;
                        goto __error;
 +              }
                strlcpy(card->id, xid, sizeof(card->id));
        }
        err = 0;
        INIT_LIST_HEAD(&card->controls);
        INIT_LIST_HEAD(&card->ctl_files);
        spin_lock_init(&card->files_lock);
+       INIT_LIST_HEAD(&card->files_list);
        init_waitqueue_head(&card->shutdown_sleep);
  #ifdef CONFIG_PM
        mutex_init(&card->power_lock);
  #endif
        /* the control interface cannot be accessed from the user space until */
        /* snd_cards_bitmask and snd_cards are set with snd_card_register */
 -      if ((err = snd_ctl_create(card)) < 0) {
 -              snd_printd("unable to register control minors\n");
 +      err = snd_ctl_create(card);
 +      if (err < 0) {
 +              snd_printk(KERN_ERR "unable to register control minors\n");
                goto __error;
        }
 -      if ((err = snd_info_card_create(card)) < 0) {
 -              snd_printd("unable to create card info\n");
 +      err = snd_info_card_create(card);
 +      if (err < 0) {
 +              snd_printk(KERN_ERR "unable to create card info\n");
                goto __error_ctl;
        }
        if (extra_size > 0)
                card->private_data = (char *)card + sizeof(struct snd_card);
 -      return card;
 +      *card_ret = card;
 +      return 0;
  
        __error_ctl:
        snd_device_free_all(card, SNDRV_DEV_CMD_PRE);
        __error:
        kfree(card);
 -              return NULL;
 +      return err;
  }
 -
 -EXPORT_SYMBOL(snd_card_new);
 +EXPORT_SYMBOL(snd_card_create);
  
  /* return non-zero if a card is already locked */
  int snd_card_locked(int card)
@@@ -274,6 -260,7 +275,7 @@@ static int snd_disconnect_release(struc
        list_for_each_entry(_df, &shutdown_files, shutdown_list) {
                if (_df->file == file) {
                        df = _df;
+                       list_del_init(&df->shutdown_list);
                        break;
                }
        }
@@@ -362,8 -349,7 +364,7 @@@ int snd_card_disconnect(struct snd_car
        /* phase 2: replace file->f_op with special dummy operations */
        
        spin_lock(&card->files_lock);
-       mfile = card->files;
-       while (mfile) {
+       list_for_each_entry(mfile, &card->files_list, list) {
                file = mfile->file;
  
                /* it's critical part, use endless loop */
  
                mfile->file->f_op = &snd_shutdown_f_ops;
                fops_get(mfile->file->f_op);
-               
-               mfile = mfile->next;
        }
        spin_unlock(&card->files_lock); 
  
@@@ -457,7 -441,7 +456,7 @@@ int snd_card_free_when_closed(struct sn
                return ret;
  
        spin_lock(&card->files_lock);
-       if (card->files == NULL)
+       if (list_empty(&card->files_list))
                free_now = 1;
        else
                card->free_on_last_close = 1;
@@@ -477,7 -461,7 +476,7 @@@ int snd_card_free(struct snd_card *card
                return ret;
  
        /* wait, until all devices are ready for the free operation */
-       wait_event(card->shutdown_sleep, card->files == NULL);
+       wait_event(card->shutdown_sleep, list_empty(&card->files_list));
        snd_card_do_free(card);
        return 0;
  }
@@@ -824,15 -808,13 +823,13 @@@ int snd_card_file_add(struct snd_card *
                return -ENOMEM;
        mfile->file = file;
        mfile->disconnected_f_op = NULL;
-       mfile->next = NULL;
        spin_lock(&card->files_lock);
        if (card->shutdown) {
                spin_unlock(&card->files_lock);
                kfree(mfile);
                return -ENODEV;
        }
-       mfile->next = card->files;
-       card->files = mfile;
+       list_add(&mfile->list, &card->files_list);
        spin_unlock(&card->files_lock);
        return 0;
  }
@@@ -854,29 -836,20 +851,20 @@@ EXPORT_SYMBOL(snd_card_file_add)
   */
  int snd_card_file_remove(struct snd_card *card, struct file *file)
  {
-       struct snd_monitor_file *mfile, *pfile = NULL;
+       struct snd_monitor_file *mfile, *found = NULL;
        int last_close = 0;
  
        spin_lock(&card->files_lock);
-       mfile = card->files;
-       while (mfile) {
+       list_for_each_entry(mfile, &card->files_list, list) {
                if (mfile->file == file) {
-                       if (pfile)
-                               pfile->next = mfile->next;
-                       else
-                               card->files = mfile->next;
+                       list_del(&mfile->list);
+                       if (mfile->disconnected_f_op)
+                               fops_put(mfile->disconnected_f_op);
+                       found = mfile;
                        break;
                }
-               pfile = mfile;
-               mfile = mfile->next;
-       }
-       if (mfile && mfile->disconnected_f_op) {
-               fops_put(mfile->disconnected_f_op);
-               spin_lock(&shutdown_lock);
-               list_del(&mfile->shutdown_list);
-               spin_unlock(&shutdown_lock);
        }
-       if (card->files == NULL)
+       if (list_empty(&card->files_list))
                last_close = 1;
        spin_unlock(&card->files_lock);
        if (last_close) {
                if (card->free_on_last_close)
                        snd_card_do_free(card);
        }
-       if (!mfile) {
+       if (!found) {
                snd_printk(KERN_ERR "ALSA card file remove problem (%p)\n", file);
                return -ENOENT;
        }
-       kfree(mfile);
+       kfree(found);
        return 0;
  }