ASoC: fix typos in Blackfin headers
[safe/jmp/linux-2.6] / sound / core / hwdep.c
index 9aa9d94..a70ee7f 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Hardware dependent layer
- *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  *
  *
  *   This program is free software; you can redistribute it and/or modify
  *
  */
 
-#include <sound/driver.h>
 #include <linux/major.h>
 #include <linux/init.h>
-#include <linux/smp_lock.h>
 #include <linux/slab.h>
 #include <linux/time.h>
 #include <linux/mutex.h>
@@ -32,7 +30,7 @@
 #include <sound/hwdep.h>
 #include <sound/info.h>
 
-MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
+MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
 MODULE_DESCRIPTION("Hardware dependent layer");
 MODULE_LICENSE("GPL");
 
@@ -47,14 +45,11 @@ static int snd_hwdep_dev_disconnect(struct snd_device *device);
 
 static struct snd_hwdep *snd_hwdep_search(struct snd_card *card, int device)
 {
-       struct list_head *p;
        struct snd_hwdep *hwdep;
 
-       list_for_each(p, &snd_hwdep_devices) {
-               hwdep = list_entry(p, struct snd_hwdep, list);
+       list_for_each_entry(hwdep, &snd_hwdep_devices, list)
                if (hwdep->card == card && hwdep->device == device)
                        return hwdep;
-       }
        return NULL;
 }
 
@@ -104,9 +99,6 @@ static int snd_hwdep_open(struct inode *inode, struct file * file)
        if (hw == NULL)
                return -ENODEV;
 
-       if (!hw->ops.open)
-               return -ENXIO;
-
        if (!try_module_get(hw->card->module))
                return -EFAULT;
 
@@ -118,6 +110,10 @@ static int snd_hwdep_open(struct inode *inode, struct file * file)
                        err = -EBUSY;
                        break;
                }
+               if (!hw->ops.open) {
+                       err = 0;
+                       break;
+               }
                err = hw->ops.open(hw, file);
                if (err >= 0)
                        break;
@@ -156,18 +152,20 @@ static int snd_hwdep_open(struct inode *inode, struct file * file)
 
 static int snd_hwdep_release(struct inode *inode, struct file * file)
 {
-       int err = -ENXIO;
+       int err = 0;
        struct snd_hwdep *hw = file->private_data;
+       struct module *mod = hw->card->module;
+
        mutex_lock(&hw->open_mutex);
-       if (hw->ops.release) {
+       if (hw->ops.release)
                err = hw->ops.release(hw, file);
-               wake_up(&hw->open_wait);
-       }
        if (hw->used > 0)
                hw->used--;
-       snd_card_file_remove(hw->card, file);
        mutex_unlock(&hw->open_mutex);
-       module_put(hw->card->module);
+       wake_up(&hw->open_wait);
+
+       snd_card_file_remove(hw->card, file);
+       module_put(mod);
        return err;
 }
 
@@ -318,7 +316,7 @@ static int snd_hwdep_control_ioctl(struct snd_card *card,
 
  */
 
-static struct file_operations snd_hwdep_f_ops =
+static const struct file_operations snd_hwdep_f_ops =
 {
        .owner =        THIS_MODULE,
        .llseek =       snd_hwdep_llseek,
@@ -356,9 +354,10 @@ int snd_hwdep_new(struct snd_card *card, char *id, int device,
                .dev_disconnect = snd_hwdep_dev_disconnect,
        };
 
-       snd_assert(rhwdep != NULL, return -EINVAL);
-       *rhwdep = NULL;
-       snd_assert(card != NULL, return -ENXIO);
+       if (snd_BUG_ON(!card))
+               return -ENXIO;
+       if (rhwdep)
+               *rhwdep = NULL;
        hwdep = kzalloc(sizeof(*hwdep), GFP_KERNEL);
        if (hwdep == NULL) {
                snd_printk(KERN_ERR "hwdep: cannot allocate\n");
@@ -377,13 +376,15 @@ int snd_hwdep_new(struct snd_card *card, char *id, int device,
        }
        init_waitqueue_head(&hwdep->open_wait);
        mutex_init(&hwdep->open_mutex);
-       *rhwdep = hwdep;
+       if (rhwdep)
+               *rhwdep = hwdep;
        return 0;
 }
 
 static int snd_hwdep_free(struct snd_hwdep *hwdep)
 {
-       snd_assert(hwdep != NULL, return -ENXIO);
+       if (!hwdep)
+               return 0;
        if (hwdep->private_free)
                hwdep->private_free(hwdep);
        kfree(hwdep);
@@ -443,7 +444,8 @@ static int snd_hwdep_dev_disconnect(struct snd_device *device)
 {
        struct snd_hwdep *hwdep = device->device_data;
 
-       snd_assert(hwdep != NULL, return -ENXIO);
+       if (snd_BUG_ON(!hwdep))
+               return -ENXIO;
        mutex_lock(&register_mutex);
        if (snd_hwdep_search(hwdep->card, hwdep->device) != hwdep) {
                mutex_unlock(&register_mutex);
@@ -467,15 +469,12 @@ static int snd_hwdep_dev_disconnect(struct snd_device *device)
 static void snd_hwdep_proc_read(struct snd_info_entry *entry,
                                struct snd_info_buffer *buffer)
 {
-       struct list_head *p;
        struct snd_hwdep *hwdep;
 
        mutex_lock(&register_mutex);
-       list_for_each(p, &snd_hwdep_devices) {
-               hwdep = list_entry(p, struct snd_hwdep, list);
+       list_for_each_entry(hwdep, &snd_hwdep_devices, list)
                snd_iprintf(buffer, "%02i-%02i: %s\n",
                            hwdep->card->number, hwdep->device, hwdep->name);
-       }
        mutex_unlock(&register_mutex);
 }