ALSA: support module on-demand loading for seq and timer
[linux-2.6.git] / sound / core / timer.c
index 0af337e..ed01632 100644 (file)
@@ -34,8 +34,8 @@
 #include <sound/initval.h>
 #include <linux/kmod.h>
 
-#if defined(CONFIG_SND_HPET) || defined(CONFIG_SND_HPET_MODULE)
-#define DEFAULT_TIMER_LIMIT 3
+#if defined(CONFIG_SND_HRTIMER) || defined(CONFIG_SND_HRTIMER_MODULE)
+#define DEFAULT_TIMER_LIMIT 4
 #elif defined(CONFIG_SND_RTCTIMER) || defined(CONFIG_SND_RTCTIMER_MODULE)
 #define DEFAULT_TIMER_LIMIT 2
 #else
@@ -52,6 +52,9 @@ MODULE_PARM_DESC(timer_limit, "Maximum global timers in system.");
 module_param(timer_tstamp_monotonic, int, 0444);
 MODULE_PARM_DESC(timer_tstamp_monotonic, "Use posix monotonic clock source for timestamps (default).");
 
+MODULE_ALIAS_CHARDEV(CONFIG_SND_MAJOR, SNDRV_MINOR_TIMER);
+MODULE_ALIAS("devname:snd/timer");
+
 struct snd_timer_user {
        struct snd_timer_instance *timeri;
        int tread;              /* enhanced read with timestamps and events */
@@ -306,7 +309,8 @@ int snd_timer_close(struct snd_timer_instance *timeri)
        struct snd_timer *timer = NULL;
        struct snd_timer_instance *slave, *tmp;
 
-       snd_assert(timeri != NULL, return -ENXIO);
+       if (snd_BUG_ON(!timeri))
+               return -ENXIO;
 
        /* force to stop the timer */
        snd_timer_stop(timeri);
@@ -385,13 +389,14 @@ static void snd_timer_notify1(struct snd_timer_instance *ti, int event)
                do_posix_clock_monotonic_gettime(&tstamp);
        else
                getnstimeofday(&tstamp);
-       snd_assert(event >= SNDRV_TIMER_EVENT_START &&
-                  event <= SNDRV_TIMER_EVENT_PAUSE, return);
+       if (snd_BUG_ON(event < SNDRV_TIMER_EVENT_START ||
+                      event > SNDRV_TIMER_EVENT_PAUSE))
+               return;
        if (event == SNDRV_TIMER_EVENT_START ||
            event == SNDRV_TIMER_EVENT_CONTINUE)
                resolution = snd_timer_resolution(ti);
        if (ti->ccallback)
-               ti->ccallback(ti, SNDRV_TIMER_EVENT_START, &tstamp, resolution);
+               ti->ccallback(ti, event, &tstamp, resolution);
        if (ti->flags & SNDRV_TIMER_IFLG_SLAVE)
                return;
        timer = ti->timer;
@@ -474,7 +479,8 @@ static int _snd_timer_stop(struct snd_timer_instance * timeri,
        struct snd_timer *timer;
        unsigned long flags;
 
-       snd_assert(timeri != NULL, return -ENXIO);
+       if (snd_BUG_ON(!timeri))
+               return -ENXIO;
 
        if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) {
                if (!keep_flag) {
@@ -740,7 +746,7 @@ void snd_timer_interrupt(struct snd_timer * timer, unsigned long ticks_left)
        spin_unlock_irqrestore(&timer->lock, flags);
 
        if (use_tasklet)
-               tasklet_hi_schedule(&timer->task_queue);
+               tasklet_schedule(&timer->task_queue);
 }
 
 /*
@@ -758,9 +764,10 @@ int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid,
                .dev_disconnect = snd_timer_dev_disconnect,
        };
 
-       snd_assert(tid != NULL, return -EINVAL);
-       snd_assert(rtimer != NULL, return -EINVAL);
-       *rtimer = NULL;
+       if (snd_BUG_ON(!tid))
+               return -EINVAL;
+       if (rtimer)
+               *rtimer = NULL;
        timer = kzalloc(sizeof(*timer), GFP_KERNEL);
        if (timer == NULL) {
                snd_printk(KERN_ERR "timer: cannot allocate\n");
@@ -788,13 +795,15 @@ int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid,
                        return err;
                }
        }
-       *rtimer = timer;
+       if (rtimer)
+               *rtimer = timer;
        return 0;
 }
 
 static int snd_timer_free(struct snd_timer *timer)
 {
-       snd_assert(timer != NULL, return -ENXIO);
+       if (!timer)
+               return 0;
 
        mutex_lock(&register_mutex);
        if (! list_empty(&timer->open_list_head)) {
@@ -827,8 +836,8 @@ static int snd_timer_dev_register(struct snd_device *dev)
        struct snd_timer *timer = dev->device_data;
        struct snd_timer *timer1;
 
-       snd_assert(timer != NULL && timer->hw.start != NULL &&
-                  timer->hw.stop != NULL, return -ENXIO);
+       if (snd_BUG_ON(!timer || !timer->hw.start || !timer->hw.stop))
+               return -ENXIO;
        if (!(timer->hw.flags & SNDRV_TIMER_HW_SLAVE) &&
            !timer->hw.resolution && timer->hw.c_resolution == NULL)
                return -EINVAL;
@@ -879,8 +888,9 @@ void snd_timer_notify(struct snd_timer *timer, int event, struct timespec *tstam
 
        if (! (timer->hw.flags & SNDRV_TIMER_HW_SLAVE))
                return;
-       snd_assert(event >= SNDRV_TIMER_EVENT_MSTART &&
-                  event <= SNDRV_TIMER_EVENT_MRESUME, return);
+       if (snd_BUG_ON(event < SNDRV_TIMER_EVENT_MSTART ||
+                      event > SNDRV_TIMER_EVENT_MRESUME))
+               return;
        spin_lock_irqsave(&timer->lock, flags);
        if (event == SNDRV_TIMER_EVENT_MSTART ||
            event == SNDRV_TIMER_EVENT_MCONTINUE ||
@@ -1153,6 +1163,7 @@ static void snd_timer_user_ccallback(struct snd_timer_instance *timeri,
 {
        struct snd_timer_user *tu = timeri->callback_data;
        struct snd_timer_tread r1;
+       unsigned long flags;
 
        if (event >= SNDRV_TIMER_EVENT_START &&
            event <= SNDRV_TIMER_EVENT_PAUSE)
@@ -1162,9 +1173,9 @@ static void snd_timer_user_ccallback(struct snd_timer_instance *timeri,
        r1.event = event;
        r1.tstamp = *tstamp;
        r1.val = resolution;
-       spin_lock(&tu->qlock);
+       spin_lock_irqsave(&tu->qlock, flags);
        snd_timer_user_append_to_tqueue(tu, &r1);
-       spin_unlock(&tu->qlock);
+       spin_unlock_irqrestore(&tu->qlock, flags);
        kill_fasync(&tu->fasync, SIGIO, POLL_IN);
        wake_up(&tu->qchange_sleep);
 }
@@ -1230,6 +1241,11 @@ static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri,
 static int snd_timer_user_open(struct inode *inode, struct file *file)
 {
        struct snd_timer_user *tu;
+       int err;
+
+       err = nonseekable_open(inode, file);
+       if (err < 0)
+               return err;
 
        tu = kzalloc(sizeof(*tu), GFP_KERNEL);
        if (tu == NULL)
@@ -1256,7 +1272,6 @@ static int snd_timer_user_release(struct inode *inode, struct file *file)
        if (file->private_data) {
                tu = file->private_data;
                file->private_data = NULL;
-               fasync_helper(-1, file, 0, &tu->fasync);
                if (tu->timeri)
                        snd_timer_close(tu->timeri);
                kfree(tu->queue);
@@ -1389,13 +1404,10 @@ static int snd_timer_user_ginfo(struct file *file,
        struct list_head *p;
        int err = 0;
 
-       ginfo = kmalloc(sizeof(*ginfo), GFP_KERNEL);
-       if (! ginfo)
-               return -ENOMEM;
-       if (copy_from_user(ginfo, _ginfo, sizeof(*ginfo))) {
-               kfree(ginfo);
-               return -EFAULT;
-       }
+       ginfo = memdup_user(_ginfo, sizeof(*ginfo));
+       if (IS_ERR(ginfo))
+               return PTR_ERR(ginfo);
+
        tid = ginfo->tid;
        memset(ginfo, 0, sizeof(*ginfo));
        ginfo->tid = tid;
@@ -1819,13 +1831,9 @@ static long snd_timer_user_ioctl(struct file *file, unsigned int cmd,
 static int snd_timer_user_fasync(int fd, struct file * file, int on)
 {
        struct snd_timer_user *tu;
-       int err;
 
        tu = file->private_data;
-       err = fasync_helper(fd, file, on, &tu->fasync);
-        if (err < 0)
-               return err;
-       return 0;
+       return fasync_helper(fd, file, on, &tu->fasync);
 }
 
 static ssize_t snd_timer_user_read(struct file *file, char __user *buffer,
@@ -1922,6 +1930,7 @@ static const struct file_operations snd_timer_f_ops =
        .read =         snd_timer_user_read,
        .open =         snd_timer_user_open,
        .release =      snd_timer_user_release,
+       .llseek =       no_llseek,
        .poll =         snd_timer_user_poll,
        .unlocked_ioctl =       snd_timer_user_ioctl,
        .compat_ioctl = snd_timer_user_ioctl_compat,