From e1fad17bb4084dc7c435360185417aed55656ec8 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 17 Nov 2005 14:12:45 +0100 Subject: [ALSA] Remove xxx_t typedefs: MPU401 Modules: MPU401 UART Remove xxx_t typedefs from the MPU401-UART and MPU401 drivers Signed-off-by: Takashi Iwai --- sound/drivers/mpu401/mpu401_uart.c | 72 +++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 36 deletions(-) (limited to 'sound/drivers/mpu401/mpu401_uart.c') diff --git a/sound/drivers/mpu401/mpu401_uart.c b/sound/drivers/mpu401/mpu401_uart.c index bdeb2c00dac5..16e87f31788c 100644 --- a/sound/drivers/mpu401/mpu401_uart.c +++ b/sound/drivers/mpu401/mpu401_uart.c @@ -43,8 +43,8 @@ MODULE_AUTHOR("Jaroslav Kysela "); MODULE_DESCRIPTION("Routines for control of MPU-401 in UART mode"); MODULE_LICENSE("GPL"); -static void snd_mpu401_uart_input_read(mpu401_t * mpu); -static void snd_mpu401_uart_output_write(mpu401_t * mpu); +static void snd_mpu401_uart_input_read(struct snd_mpu401 * mpu); +static void snd_mpu401_uart_output_write(struct snd_mpu401 * mpu); /* @@ -58,28 +58,28 @@ static void snd_mpu401_uart_output_write(mpu401_t * mpu); #define MPU401_ACK 0xfe /* Build in lowlevel io */ -static void mpu401_write_port(mpu401_t *mpu, unsigned char data, unsigned long addr) +static void mpu401_write_port(struct snd_mpu401 *mpu, unsigned char data, unsigned long addr) { outb(data, addr); } -static unsigned char mpu401_read_port(mpu401_t *mpu, unsigned long addr) +static unsigned char mpu401_read_port(struct snd_mpu401 *mpu, unsigned long addr) { return inb(addr); } -static void mpu401_write_mmio(mpu401_t *mpu, unsigned char data, unsigned long addr) +static void mpu401_write_mmio(struct snd_mpu401 *mpu, unsigned char data, unsigned long addr) { writeb(data, (void __iomem *)addr); } -static unsigned char mpu401_read_mmio(mpu401_t *mpu, unsigned long addr) +static unsigned char mpu401_read_mmio(struct snd_mpu401 *mpu, unsigned long addr) { return readb((void __iomem *)addr); } /* */ -static void snd_mpu401_uart_clear_rx(mpu401_t *mpu) +static void snd_mpu401_uart_clear_rx(struct snd_mpu401 *mpu) { int timeout = 100000; for (; timeout > 0 && snd_mpu401_input_avail(mpu); timeout--) @@ -90,7 +90,7 @@ static void snd_mpu401_uart_clear_rx(mpu401_t *mpu) #endif } -static void _snd_mpu401_uart_interrupt(mpu401_t *mpu) +static void _snd_mpu401_uart_interrupt(struct snd_mpu401 *mpu) { spin_lock(&mpu->input_lock); if (test_bit(MPU401_MODE_BIT_INPUT, &mpu->mode)) { @@ -118,7 +118,7 @@ static void _snd_mpu401_uart_interrupt(mpu401_t *mpu) */ irqreturn_t snd_mpu401_uart_interrupt(int irq, void *dev_id, struct pt_regs *regs) { - mpu401_t *mpu = dev_id; + struct snd_mpu401 *mpu = dev_id; if (mpu == NULL) return IRQ_NONE; @@ -132,7 +132,7 @@ irqreturn_t snd_mpu401_uart_interrupt(int irq, void *dev_id, struct pt_regs *reg */ static void snd_mpu401_uart_timer(unsigned long data) { - mpu401_t *mpu = (mpu401_t *)data; + struct snd_mpu401 *mpu = (struct snd_mpu401 *)data; spin_lock(&mpu->timer_lock); /*mpu->mode |= MPU401_MODE_TIMER;*/ @@ -146,7 +146,7 @@ static void snd_mpu401_uart_timer(unsigned long data) /* * initialize the timer callback if not programmed yet */ -static void snd_mpu401_uart_add_timer (mpu401_t *mpu, int input) +static void snd_mpu401_uart_add_timer (struct snd_mpu401 *mpu, int input) { unsigned long flags; @@ -165,7 +165,7 @@ static void snd_mpu401_uart_add_timer (mpu401_t *mpu, int input) /* * remove the timer callback if still active */ -static void snd_mpu401_uart_remove_timer (mpu401_t *mpu, int input) +static void snd_mpu401_uart_remove_timer (struct snd_mpu401 *mpu, int input) { unsigned long flags; @@ -182,7 +182,7 @@ static void snd_mpu401_uart_remove_timer (mpu401_t *mpu, int input) */ -static void snd_mpu401_uart_cmd(mpu401_t * mpu, unsigned char cmd, int ack) +static void snd_mpu401_uart_cmd(struct snd_mpu401 * mpu, unsigned char cmd, int ack) { unsigned long flags; int timeout, ok; @@ -225,9 +225,9 @@ static void snd_mpu401_uart_cmd(mpu401_t * mpu, unsigned char cmd, int ack) /* * input/output open/close - protected by open_mutex in rawmidi.c */ -static int snd_mpu401_uart_input_open(snd_rawmidi_substream_t * substream) +static int snd_mpu401_uart_input_open(struct snd_rawmidi_substream *substream) { - mpu401_t *mpu; + struct snd_mpu401 *mpu; int err; mpu = substream->rmidi->private_data; @@ -242,9 +242,9 @@ static int snd_mpu401_uart_input_open(snd_rawmidi_substream_t * substream) return 0; } -static int snd_mpu401_uart_output_open(snd_rawmidi_substream_t * substream) +static int snd_mpu401_uart_output_open(struct snd_rawmidi_substream *substream) { - mpu401_t *mpu; + struct snd_mpu401 *mpu; int err; mpu = substream->rmidi->private_data; @@ -259,9 +259,9 @@ static int snd_mpu401_uart_output_open(snd_rawmidi_substream_t * substream) return 0; } -static int snd_mpu401_uart_input_close(snd_rawmidi_substream_t * substream) +static int snd_mpu401_uart_input_close(struct snd_rawmidi_substream *substream) { - mpu401_t *mpu; + struct snd_mpu401 *mpu; mpu = substream->rmidi->private_data; clear_bit(MPU401_MODE_BIT_INPUT, &mpu->mode); @@ -273,9 +273,9 @@ static int snd_mpu401_uart_input_close(snd_rawmidi_substream_t * substream) return 0; } -static int snd_mpu401_uart_output_close(snd_rawmidi_substream_t * substream) +static int snd_mpu401_uart_output_close(struct snd_rawmidi_substream *substream) { - mpu401_t *mpu; + struct snd_mpu401 *mpu; mpu = substream->rmidi->private_data; clear_bit(MPU401_MODE_BIT_OUTPUT, &mpu->mode); @@ -290,10 +290,10 @@ static int snd_mpu401_uart_output_close(snd_rawmidi_substream_t * substream) /* * trigger input callback */ -static void snd_mpu401_uart_input_trigger(snd_rawmidi_substream_t * substream, int up) +static void snd_mpu401_uart_input_trigger(struct snd_rawmidi_substream *substream, int up) { unsigned long flags; - mpu401_t *mpu; + struct snd_mpu401 *mpu; int max = 64; mpu = substream->rmidi->private_data; @@ -321,7 +321,7 @@ static void snd_mpu401_uart_input_trigger(snd_rawmidi_substream_t * substream, i * transfer input pending data * call with input_lock spinlock held */ -static void snd_mpu401_uart_input_read(mpu401_t * mpu) +static void snd_mpu401_uart_input_read(struct snd_mpu401 * mpu) { int max = 128; unsigned char byte; @@ -349,7 +349,7 @@ static void snd_mpu401_uart_input_read(mpu401_t * mpu) * write output pending bytes * call with output_lock spinlock held */ -static void snd_mpu401_uart_output_write(mpu401_t * mpu) +static void snd_mpu401_uart_output_write(struct snd_mpu401 * mpu) { unsigned char byte; int max = 256, timeout; @@ -375,10 +375,10 @@ static void snd_mpu401_uart_output_write(mpu401_t * mpu) /* * output trigger callback */ -static void snd_mpu401_uart_output_trigger(snd_rawmidi_substream_t * substream, int up) +static void snd_mpu401_uart_output_trigger(struct snd_rawmidi_substream *substream, int up) { unsigned long flags; - mpu401_t *mpu; + struct snd_mpu401 *mpu; mpu = substream->rmidi->private_data; if (up) { @@ -404,23 +404,23 @@ static void snd_mpu401_uart_output_trigger(snd_rawmidi_substream_t * substream, */ -static snd_rawmidi_ops_t snd_mpu401_uart_output = +static struct snd_rawmidi_ops snd_mpu401_uart_output = { .open = snd_mpu401_uart_output_open, .close = snd_mpu401_uart_output_close, .trigger = snd_mpu401_uart_output_trigger, }; -static snd_rawmidi_ops_t snd_mpu401_uart_input = +static struct snd_rawmidi_ops snd_mpu401_uart_input = { .open = snd_mpu401_uart_input_open, .close = snd_mpu401_uart_input_close, .trigger = snd_mpu401_uart_input_trigger, }; -static void snd_mpu401_uart_free(snd_rawmidi_t *rmidi) +static void snd_mpu401_uart_free(struct snd_rawmidi *rmidi) { - mpu401_t *mpu = rmidi->private_data; + struct snd_mpu401 *mpu = rmidi->private_data; if (mpu->irq_flags && mpu->irq >= 0) free_irq(mpu->irq, (void *) mpu); release_and_free_resource(mpu->res); @@ -442,18 +442,18 @@ static void snd_mpu401_uart_free(snd_rawmidi_t *rmidi) * * Note that the rawmidi instance is returned on the rrawmidi argument, * not the mpu401 instance itself. To access to the mpu401 instance, - * cast from rawmidi->private_data (with mpu401_t magic-cast). + * cast from rawmidi->private_data (with struct snd_mpu401 magic-cast). * * Returns zero if successful, or a negative error code. */ -int snd_mpu401_uart_new(snd_card_t * card, int device, +int snd_mpu401_uart_new(struct snd_card *card, int device, unsigned short hardware, unsigned long port, int integrated, int irq, int irq_flags, - snd_rawmidi_t ** rrawmidi) + struct snd_rawmidi ** rrawmidi) { - mpu401_t *mpu; - snd_rawmidi_t *rmidi; + struct snd_mpu401 *mpu; + struct snd_rawmidi *rmidi; int err; if (rrawmidi) -- cgit v1.2.3-59-g8ed1b From 73e77ba0235532bd7523ba90883d325f6e095acf Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 17 Nov 2005 17:44:01 +0100 Subject: [ALSA] Add error messages Add error messages in the critial error path to be more verbose. Signed-off-by: Takashi Iwai --- sound/core/control.c | 8 ++++++-- sound/core/device.c | 5 ++++- sound/core/hwdep.c | 7 ++++--- sound/core/pcm.c | 16 +++++++++++----- sound/core/rawmidi.c | 18 ++++++++++++++---- sound/core/timer.c | 4 +++- sound/drivers/mpu401/mpu401_uart.c | 1 + sound/drivers/opl3/opl3_lib.c | 4 +++- sound/isa/opl3sa2.c | 27 ++++++++++++++++++++------- 9 files changed, 66 insertions(+), 24 deletions(-) (limited to 'sound/drivers/mpu401/mpu401_uart.c') diff --git a/sound/core/control.c b/sound/core/control.c index 03ae9bb7d38e..f8f98cc52417 100644 --- a/sound/core/control.c +++ b/sound/core/control.c @@ -195,8 +195,10 @@ struct snd_kcontrol *snd_ctl_new(struct snd_kcontrol *control, unsigned int acce snd_assert(control != NULL, return NULL); snd_assert(control->count > 0, return NULL); kctl = kzalloc(sizeof(*kctl) + sizeof(struct snd_kcontrol_volatile) * control->count, GFP_KERNEL); - if (kctl == NULL) + if (kctl == NULL) { + snd_printk(KERN_ERR "Cannot allocate control instance\n"); return NULL; + } *kctl = *control; for (idx = 0; idx < kctl->count; idx++) kctl->vd[idx].access = access; @@ -309,7 +311,9 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol) struct snd_ctl_elem_id id; unsigned int idx; - snd_assert(card != NULL && kcontrol != NULL, return -EINVAL); + snd_assert(card != NULL, return -EINVAL); + if (! kcontrol) + return -EINVAL; snd_assert(kcontrol->info != NULL, return -EINVAL); id = kcontrol->id; down_write(&card->controls_rwsem); diff --git a/sound/core/device.c b/sound/core/device.c index afa8cc7fb05e..b1cf6ec56784 100644 --- a/sound/core/device.c +++ b/sound/core/device.c @@ -50,8 +50,10 @@ int snd_device_new(struct snd_card *card, snd_device_type_t type, snd_assert(device_data != NULL, return -ENXIO); snd_assert(ops != NULL, return -ENXIO); dev = kzalloc(sizeof(*dev), GFP_KERNEL); - if (dev == NULL) + if (dev == NULL) { + snd_printk(KERN_ERR "Cannot allocate device\n"); return -ENOMEM; + } dev->card = card; dev->type = type; dev->state = SNDRV_DEV_BUILD; @@ -173,6 +175,7 @@ int snd_device_register(struct snd_card *card, void *device_data) dev->state = SNDRV_DEV_REGISTERED; return 0; } + snd_printd("snd_device_register busy\n"); return -EBUSY; } snd_BUG(); diff --git a/sound/core/hwdep.c b/sound/core/hwdep.c index da0fb9f08413..444e266e7c48 100644 --- a/sound/core/hwdep.c +++ b/sound/core/hwdep.c @@ -364,13 +364,14 @@ int snd_hwdep_new(struct snd_card *card, char *id, int device, *rhwdep = NULL; snd_assert(card != NULL, return -ENXIO); hwdep = kzalloc(sizeof(*hwdep), GFP_KERNEL); - if (hwdep == NULL) + if (hwdep == NULL) { + snd_printk(KERN_ERR "hwdep: cannot allocate\n"); return -ENOMEM; + } hwdep->card = card; hwdep->device = device; - if (id) { + if (id) strlcpy(hwdep->id, id, sizeof(hwdep->id)); - } #ifdef CONFIG_SND_OSSEMUL hwdep->oss_type = -1; #endif diff --git a/sound/core/pcm.c b/sound/core/pcm.c index 59c995bbf15b..9305ac357a3e 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c @@ -600,14 +600,18 @@ int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count) pstr->reg = &snd_pcm_reg[stream]; if (substream_count > 0) { err = snd_pcm_stream_proc_init(pstr); - if (err < 0) + if (err < 0) { + snd_printk(KERN_ERR "Error in snd_pcm_stream_proc_init\n"); return err; + } } prev = NULL; for (idx = 0, prev = NULL; idx < substream_count; idx++) { substream = kzalloc(sizeof(*substream), GFP_KERNEL); - if (substream == NULL) + if (substream == NULL) { + snd_printk(KERN_ERR "Cannot allocate PCM substream\n"); return -ENOMEM; + } substream->pcm = pcm; substream->pstr = pstr; substream->number = idx; @@ -620,6 +624,7 @@ int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count) prev->next = substream; err = snd_pcm_substream_proc_init(substream); if (err < 0) { + snd_printk(KERN_ERR "Error in snd_pcm_stream_proc_init\n"); kfree(substream); return err; } @@ -666,13 +671,14 @@ int snd_pcm_new(struct snd_card *card, char *id, int device, *rpcm = NULL; snd_assert(card != NULL, return -ENXIO); pcm = kzalloc(sizeof(*pcm), GFP_KERNEL); - if (pcm == NULL) + if (pcm == NULL) { + snd_printk(KERN_ERR "Cannot allocate PCM\n"); return -ENOMEM; + } pcm->card = card; pcm->device = device; - if (id) { + if (id) strlcpy(pcm->id, id, sizeof(pcm->id)); - } if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK, playback_count)) < 0) { snd_pcm_free(pcm); return err; diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c index ede0a6083d29..7a86a9a08a15 100644 --- a/sound/core/rawmidi.c +++ b/sound/core/rawmidi.c @@ -1382,8 +1382,10 @@ static int snd_rawmidi_alloc_substreams(struct snd_rawmidi *rmidi, INIT_LIST_HEAD(&stream->substreams); for (idx = 0; idx < count; idx++) { substream = kzalloc(sizeof(*substream), GFP_KERNEL); - if (substream == NULL) + if (substream == NULL) { + snd_printk(KERN_ERR "rawmidi: cannot allocate substream\n"); return -ENOMEM; + } substream->stream = direction; substream->number = idx; substream->rmidi = rmidi; @@ -1425,19 +1427,27 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device, *rrawmidi = NULL; snd_assert(card != NULL, return -ENXIO); rmidi = kzalloc(sizeof(*rmidi), GFP_KERNEL); - if (rmidi == NULL) + if (rmidi == NULL) { + snd_printk(KERN_ERR "rawmidi: cannot allocate\n"); return -ENOMEM; + } rmidi->card = card; rmidi->device = device; init_MUTEX(&rmidi->open_mutex); init_waitqueue_head(&rmidi->open_wait); if (id != NULL) strlcpy(rmidi->id, id, sizeof(rmidi->id)); - if ((err = snd_rawmidi_alloc_substreams(rmidi, &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT], SNDRV_RAWMIDI_STREAM_INPUT, input_count)) < 0) { + if ((err = snd_rawmidi_alloc_substreams(rmidi, + &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT], + SNDRV_RAWMIDI_STREAM_INPUT, + input_count)) < 0) { snd_rawmidi_free(rmidi); return err; } - if ((err = snd_rawmidi_alloc_substreams(rmidi, &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT], SNDRV_RAWMIDI_STREAM_OUTPUT, output_count)) < 0) { + if ((err = snd_rawmidi_alloc_substreams(rmidi, + &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT], + SNDRV_RAWMIDI_STREAM_OUTPUT, + output_count)) < 0) { snd_rawmidi_free(rmidi); return err; } diff --git a/sound/core/timer.c b/sound/core/timer.c index 18d43a037850..74637cef6d2c 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -777,8 +777,10 @@ int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid, snd_assert(rtimer != NULL, return -EINVAL); *rtimer = NULL; timer = kzalloc(sizeof(*timer), GFP_KERNEL); - if (timer == NULL) + if (timer == NULL) { + snd_printk(KERN_ERR "timer: cannot allocate\n"); return -ENOMEM; + } timer->tmr_class = tid->dev_class; timer->card = card; timer->tmr_device = tid->device; diff --git a/sound/drivers/mpu401/mpu401_uart.c b/sound/drivers/mpu401/mpu401_uart.c index 16e87f31788c..ee67b522d259 100644 --- a/sound/drivers/mpu401/mpu401_uart.c +++ b/sound/drivers/mpu401/mpu401_uart.c @@ -462,6 +462,7 @@ int snd_mpu401_uart_new(struct snd_card *card, int device, return err; mpu = kzalloc(sizeof(*mpu), GFP_KERNEL); if (mpu == NULL) { + snd_printk(KERN_ERR "mpu401_uart: cannot allocate\n"); snd_device_free(card, rmidi); return -ENOMEM; } diff --git a/sound/drivers/opl3/opl3_lib.c b/sound/drivers/opl3/opl3_lib.c index cbd37e919601..650f3b8e60e0 100644 --- a/sound/drivers/opl3/opl3_lib.c +++ b/sound/drivers/opl3/opl3_lib.c @@ -349,8 +349,10 @@ int snd_opl3_new(struct snd_card *card, *ropl3 = NULL; opl3 = kzalloc(sizeof(*opl3), GFP_KERNEL); - if (opl3 == NULL) + if (opl3 == NULL) { + snd_printk(KERN_ERR "opl3: cannot allocate\n"); return -ENOMEM; + } opl3->card = card; opl3->hardware = hardware; diff --git a/sound/isa/opl3sa2.c b/sound/isa/opl3sa2.c index b923de9b321d..aafe5565b6e5 100644 --- a/sound/isa/opl3sa2.c +++ b/sound/isa/opl3sa2.c @@ -496,21 +496,29 @@ static int __init snd_opl3sa2_mixer(struct snd_opl3sa2 *chip) /* reassign AUX0 to CD */ strcpy(id1.name, "Aux Playback Switch"); strcpy(id2.name, "CD Playback Switch"); - if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) + if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) { + snd_printk(KERN_ERR "Cannot rename opl3sa2 control\n"); return err; + } strcpy(id1.name, "Aux Playback Volume"); strcpy(id2.name, "CD Playback Volume"); - if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) + if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) { + snd_printk(KERN_ERR "Cannot rename opl3sa2 control\n"); return err; + } /* reassign AUX1 to FM */ strcpy(id1.name, "Aux Playback Switch"); id1.index = 1; strcpy(id2.name, "FM Playback Switch"); - if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) + if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) { + snd_printk(KERN_ERR "Cannot rename opl3sa2 control\n"); return err; + } strcpy(id1.name, "Aux Playback Volume"); strcpy(id2.name, "FM Playback Volume"); - if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) + if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) { + snd_printk(KERN_ERR "Cannot rename opl3sa2 control\n"); return err; + } /* add OPL3SA2 controls */ for (idx = 0; idx < ARRAY_SIZE(snd_opl3sa2_controls); idx++) { if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_opl3sa2_controls[idx], chip))) < 0) @@ -575,8 +583,10 @@ static int __init snd_opl3sa2_pnp(int dev, struct snd_opl3sa2 *chip, int err; cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL); - if (!cfg) + if (!cfg) { + snd_printk(KERN_ERR PFX "cannot allocate pnp cfg\n"); return -ENOMEM; + } /* PnP initialization */ pnp_init_resource_table(cfg); if (sb_port[dev] != SNDRV_AUTO_PORT) @@ -597,7 +607,7 @@ static int __init snd_opl3sa2_pnp(int dev, struct snd_opl3sa2 *chip, pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1); err = pnp_manual_config_dev(pdev, cfg, 0); if (err < 0) - snd_printk(KERN_ERR "PnP manual resources are invalid, using auto config\n"); + snd_printk(KERN_WARNING "PnP manual resources are invalid, using auto config\n"); err = pnp_activate_dev(pdev); if (err < 0) { kfree(cfg); @@ -784,8 +794,11 @@ static int __devinit snd_opl3sa2_pnp_cdetect(struct pnp_card_link *pcard, struct snd_card *card; pdev = pnp_request_card_device(pcard, id->devs[0].id, NULL); - if (pdev == NULL) + if (pdev == NULL) { + snd_printk(KERN_ERR PFX "can't get pnp device from id '%s'\n", + id->devs[0].id); return -EBUSY; + } for (; dev < SNDRV_CARDS; dev++) { if (enable[dev] && isapnp[dev]) break; -- cgit v1.2.3-59-g8ed1b From b32425ac93370e1ba5556110e662f896b2e143b3 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 18 Nov 2005 18:52:14 +0100 Subject: [ALSA] Fix possible races in timer callbacks Fix possible races in timer callbacks. Signed-off-by: Takashi Iwai --- sound/core/timer.c | 5 +++-- sound/drivers/dummy.c | 10 +++++----- sound/drivers/mpu401/mpu401_uart.c | 5 +++-- sound/drivers/opl3/opl3_midi.c | 5 +++-- sound/pci/korg1212/korg1212.c | 5 +++-- sound/synth/emux/emux_synth.c | 5 +++-- 6 files changed, 20 insertions(+), 15 deletions(-) (limited to 'sound/drivers/mpu401/mpu401_uart.c') diff --git a/sound/core/timer.c b/sound/core/timer.c index 74637cef6d2c..6aad411dd7b8 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -662,12 +662,13 @@ void snd_timer_interrupt(struct snd_timer * timer, unsigned long ticks_left) struct snd_timer_instance *ti, *ts; unsigned long resolution, ticks; struct list_head *p, *q, *n, *ack_list_head; + unsigned long flags; int use_tasklet = 0; if (timer == NULL) return; - spin_lock(&timer->lock); + spin_lock_irqsave(&timer->lock, flags); /* remember the current resolution */ if (timer->hw.c_resolution) @@ -752,7 +753,7 @@ void snd_timer_interrupt(struct snd_timer * timer, unsigned long ticks_left) /* do we have any slow callbacks? */ use_tasklet = !list_empty(&timer->sack_list_head); - spin_unlock(&timer->lock); + spin_unlock_irqrestore(&timer->lock, flags); if (use_tasklet) tasklet_hi_schedule(&timer->task_queue); diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c index a276f7c80360..186117571745 100644 --- a/sound/drivers/dummy.c +++ b/sound/drivers/dummy.c @@ -231,8 +231,9 @@ static int snd_card_dummy_pcm_prepare(struct snd_pcm_substream *substream) static void snd_card_dummy_pcm_timer_function(unsigned long data) { struct snd_dummy_pcm *dpcm = (struct snd_dummy_pcm *)data; + unsigned long flags; - spin_lock(&dpcm->lock); + spin_lock_irqsave(&dpcm->lock, flags); dpcm->timer.expires = 1 + jiffies; add_timer(&dpcm->timer); dpcm->pcm_irq_pos += dpcm->pcm_jiffie; @@ -240,11 +241,10 @@ static void snd_card_dummy_pcm_timer_function(unsigned long data) dpcm->pcm_buf_pos %= dpcm->pcm_size; if (dpcm->pcm_irq_pos >= dpcm->pcm_count) { dpcm->pcm_irq_pos %= dpcm->pcm_count; - spin_unlock(&dpcm->lock); + spin_unlock_irqrestore(&dpcm->lock, flags); snd_pcm_period_elapsed(dpcm->substream); - spin_lock(&dpcm->lock); - } - spin_unlock(&dpcm->lock); + } else + spin_unlock_irqrestore(&dpcm->lock, flags); } static snd_pcm_uframes_t snd_card_dummy_pcm_pointer(struct snd_pcm_substream *substream) diff --git a/sound/drivers/mpu401/mpu401_uart.c b/sound/drivers/mpu401/mpu401_uart.c index ee67b522d259..8687ae3c66b8 100644 --- a/sound/drivers/mpu401/mpu401_uart.c +++ b/sound/drivers/mpu401/mpu401_uart.c @@ -133,12 +133,13 @@ irqreturn_t snd_mpu401_uart_interrupt(int irq, void *dev_id, struct pt_regs *reg static void snd_mpu401_uart_timer(unsigned long data) { struct snd_mpu401 *mpu = (struct snd_mpu401 *)data; + unsigned long flags; - spin_lock(&mpu->timer_lock); + spin_lock_irqsave(&mpu->timer_lock, flags); /*mpu->mode |= MPU401_MODE_TIMER;*/ mpu->timer.expires = 1 + jiffies; add_timer(&mpu->timer); - spin_unlock(&mpu->timer_lock); + spin_unlock_irqrestore(&mpu->timer_lock, flags); if (mpu->rmidi) _snd_mpu401_uart_interrupt(mpu); } diff --git a/sound/drivers/opl3/opl3_midi.c b/sound/drivers/opl3/opl3_midi.c index 48c480e050ce..1b6f227af370 100644 --- a/sound/drivers/opl3/opl3_midi.c +++ b/sound/drivers/opl3/opl3_midi.c @@ -238,10 +238,11 @@ void snd_opl3_timer_func(unsigned long data) { struct snd_opl3 *opl3 = (struct snd_opl3 *)data; + unsigned long flags; int again = 0; int i; - spin_lock(&opl3->sys_timer_lock); + spin_lock_irqsave(&opl3->sys_timer_lock, flags); for (i = 0; i < opl3->max_voices; i++) { struct snd_opl3_voice *vp = &opl3->voices[i]; if (vp->state > 0 && vp->note_off_check) { @@ -257,7 +258,7 @@ void snd_opl3_timer_func(unsigned long data) } else { opl3->sys_timer_status = 0; } - spin_unlock(&opl3->sys_timer_lock); + spin_unlock_irqrestore(&opl3->sys_timer_lock, flags); } /* diff --git a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c index a8a6a5c41a7f..4eddb512c12f 100644 --- a/sound/pci/korg1212/korg1212.c +++ b/sound/pci/korg1212/korg1212.c @@ -609,8 +609,9 @@ static void snd_korg1212_SendStopAndWait(struct snd_korg1212 *korg1212) static void snd_korg1212_timer_func(unsigned long data) { struct snd_korg1212 *korg1212 = (struct snd_korg1212 *) data; + unsigned long flags; - spin_lock(&korg1212->lock); + spin_lock_irqsave(&korg1212->lock, flags); if (korg1212->sharedBufferPtr->cardCommand == 0) { /* ack'ed */ korg1212->stop_pending_cnt = 0; @@ -632,7 +633,7 @@ static void snd_korg1212_timer_func(unsigned long data) stateName[korg1212->cardState]); } } - spin_unlock(&korg1212->lock); + spin_unlock_irqrestore(&korg1212->lock, flags); } static int snd_korg1212_TurnOnIdleMonitor(struct snd_korg1212 *korg1212) diff --git a/sound/synth/emux/emux_synth.c b/sound/synth/emux/emux_synth.c index c387a83a655e..24705d15ebd8 100644 --- a/sound/synth/emux/emux_synth.c +++ b/sound/synth/emux/emux_synth.c @@ -205,9 +205,10 @@ void snd_emux_timer_callback(unsigned long data) { struct snd_emux *emu = (struct snd_emux *) data; struct snd_emux_voice *vp; + unsigned long flags; int ch, do_again = 0; - spin_lock(&emu->voice_lock); + spin_lock_irqsave(&emu->voice_lock, flags); for (ch = 0; ch < emu->max_voices; ch++) { vp = &emu->voices[ch]; if (vp->state == SNDRV_EMUX_ST_PENDING) { @@ -225,7 +226,7 @@ void snd_emux_timer_callback(unsigned long data) emu->timer_active = 1; } else emu->timer_active = 0; - spin_unlock(&emu->voice_lock); + spin_unlock_irqrestore(&emu->voice_lock, flags); } /* -- cgit v1.2.3-59-g8ed1b