diff -urN -X dontdiff linux-vanilla/drivers/sound/audio.c linux-2.4.0/drivers/sound/audio.c --- linux-vanilla/drivers/sound/audio.c Fri Aug 11 16:26:43 2000 +++ linux-2.4.0/drivers/sound/audio.c Tue Jan 2 15:16:54 2001 @@ -21,6 +21,7 @@ * Daniel Rodriksson: reworked the use of the device specific copy_user * still generic * Horst von Brand: Add missing #include + * Chris Rankin : Update the module-usage counter for the coprocessor */ #include @@ -71,6 +72,7 @@ int bits; int dev_type = dev & 0x0f; int mode = translate_mode(file); + struct coproc_operations *coprocessor; dev = dev >> 4; @@ -88,9 +90,12 @@ if ((ret = DMAbuf_open(dev, mode)) < 0) return ret; - if (audio_devs[dev]->coproc) { - if ((ret = audio_devs[dev]->coproc-> - open(audio_devs[dev]->coproc->devc, COPR_PCM)) < 0) { + if ( (coprocessor = audio_devs[dev]->coproc) != NULL ) { + struct module *coproc_owner = coprocessor->owner; + if (coproc_owner) + __MOD_INC_USE_COUNT(coproc_owner); + + if ((ret = coprocessor->open(coprocessor->devc, COPR_PCM)) < 0) { audio_release(dev, file); printk(KERN_WARNING "Sound: Can't access coprocessor device\n"); return ret; @@ -156,7 +161,8 @@ void audio_release(int dev, struct file *file) { - int mode = translate_mode(file); + struct coproc_operations *coprocessor; + int mode = translate_mode(file); dev = dev >> 4; @@ -176,8 +182,14 @@ if (mode & OPEN_WRITE) sync_output(dev); - if (audio_devs[dev]->coproc) - audio_devs[dev]->coproc->close(audio_devs[dev]->coproc->devc, COPR_PCM); + if ( (coprocessor = audio_devs[dev]->coproc) != NULL ) { + struct module *coproc_owner; + + coprocessor->close(coprocessor->devc, COPR_PCM); + + if ( (coproc_owner = coprocessor->owner) != NULL ) + __MOD_DEC_USE_COUNT(coproc_owner); + } DMAbuf_release(dev, mode); if (audio_devs[dev]->d->owner) diff -urN -X dontdiff linux-vanilla/drivers/sound/dev_table.h linux-2.4.0/drivers/sound/dev_table.h --- linux-vanilla/drivers/sound/dev_table.h Fri Aug 11 16:26:43 2000 +++ linux-2.4.0/drivers/sound/dev_table.h Tue Jan 2 14:24:46 2001 @@ -150,6 +150,7 @@ typedef struct coproc_operations { char name[64]; + struct module *owner; int (*open) (void *devc, int sub_device); void (*close) (void *devc, int sub_device); int (*ioctl) (void *devc, unsigned int cmd, caddr_t arg, int local); diff -urN -X dontdiff linux-vanilla/drivers/sound/mpu401.c linux-2.4.0/drivers/sound/mpu401.c --- linux-vanilla/drivers/sound/mpu401.c Sun Nov 12 02:32:01 2000 +++ linux-2.4.0/drivers/sound/mpu401.c Tue Jan 2 15:25:12 2001 @@ -14,6 +14,7 @@ * Thomas Sailer ioctl code reworked (vmalloc/vfree removed) * Alan Cox modularisation, use normal request_irq, use dev_id * Bartlomiej Zolnierkiewicz removed some __init to allow using many drivers + * Chris Rankin Update the module-usage counter for the coprocessor */ #include @@ -73,6 +74,9 @@ #define COMDPORT(base) (base+1) #define STATPORT(base) (base+1) + +static void mpu401_close(int dev); + static int mpu401_status(struct mpu_config *devc) { return inb(STATPORT(devc->base)); @@ -465,6 +469,7 @@ { int err; struct mpu_config *devc; + struct coproc_operations *coprocessor; if (dev < 0 || dev >= num_midis || midi_devs[dev] == NULL) return -ENXIO; @@ -490,12 +495,16 @@ reset_mpu401(devc); } - if (midi_devs[dev]->coproc) + if ( (coprocessor = midi_devs[dev]->coproc) != NULL ) { - if ((err = midi_devs[dev]->coproc-> - open(midi_devs[dev]->coproc->devc, COPR_MIDI)) < 0) + struct module *coproc_owner = coprocessor->owner; + if (coproc_owner) + __MOD_INC_USE_COUNT(coproc_owner); + + if ((err = coprocessor->open(coprocessor->devc, COPR_MIDI)) < 0) { - printk("MPU-401: Can't access coprocessor device\n"); + printk(KERN_ERR "MPU-401: Can't access coprocessor device\n"); + mpu401_close(dev); return err; } } @@ -515,6 +524,7 @@ static void mpu401_close(int dev) { struct mpu_config *devc; + struct coproc_operations *coprocessor; devc = &dev_conf[dev]; if (devc->uart_mode) @@ -524,8 +534,14 @@ devc->mode = 0; devc->inputintr = NULL; - if (midi_devs[dev]->coproc) - midi_devs[dev]->coproc->close(midi_devs[dev]->coproc->devc, COPR_MIDI); + coprocessor = midi_devs[dev]->coproc; + if (coprocessor) { + struct module *coproc_owner; + coprocessor->close(coprocessor->devc, COPR_MIDI); + + if ( (coproc_owner = coprocessor->owner) != NULL ) + __MOD_DEC_USE_COUNT(coproc_owner); + } devc->opened = 0; } diff -urN -X dontdiff linux-vanilla/drivers/sound/pss.c linux-2.4.0/drivers/sound/pss.c --- linux-vanilla/drivers/sound/pss.c Sun Nov 12 02:33:14 2000 +++ linux-2.4.0/drivers/sound/pss.c Tue Jan 2 15:21:38 2001 @@ -52,6 +52,8 @@ * Adapted to module_init/module_exit * 11-10-2000: Bartlomiej Zolnierkiewicz * Added __init to probe_pss(), attach_pss() and probe_pss_mpu() + * 02-Jan-2001: Chris Rankin + * Specify that this module owns the coprocessor */ @@ -979,6 +981,7 @@ static coproc_operations pss_coproc_operations = { "ADSP-2115", + THIS_MODULE, pss_coproc_open, pss_coproc_close, pss_coproc_ioctl, diff -urN -X dontdiff linux-vanilla/drivers/sound/sscape.c linux-2.4.0/drivers/sound/sscape.c --- linux-vanilla/drivers/sound/sscape.c Sun Nov 12 02:33:14 2000 +++ linux-2.4.0/drivers/sound/sscape.c Tue Jan 2 15:22:02 2001 @@ -15,6 +15,7 @@ * Sergey Smitienko : ensoniq p'n'p support * Christoph Hellwig : adapted to module_init/module_exit * Bartlomiej Zolnierkiewicz : added __init to attach_sscape() + * Chris Rankin : Specify that this module owns the coprocessor */ #include @@ -600,6 +601,7 @@ static coproc_operations sscape_coproc_operations = { "SoundScape M68K", + THIS_MODULE, sscape_coproc_open, sscape_coproc_close, sscape_coproc_ioctl,