From c57fa3a078bcd7cf633b4850b18ebd711ac227bb Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Sat, 6 Sep 2003 00:30:18 -0700 Subject: [PATCH] [PATCH] dmasound kill MOD_{IN,DE}C_USE_COUNT Dmasound: Use try_module_get()/module_put() instead of methods calling MOD_{IN,DE}C_USE_COUNT (from Christoph Hellwig) --- sound/oss/dmasound/dmasound.h | 3 +-- sound/oss/dmasound/dmasound_atari.c | 15 +---------- sound/oss/dmasound/dmasound_awacs.c | 16 +---------- sound/oss/dmasound/dmasound_core.c | 41 ++++++++++++++++------------- sound/oss/dmasound/dmasound_paula.c | 16 +---------- sound/oss/dmasound/dmasound_q40.c | 17 +----------- 6 files changed, 27 insertions(+), 81 deletions(-) diff --git a/sound/oss/dmasound/dmasound.h b/sound/oss/dmasound/dmasound.h index 539072f1375d..9d6ba627ec4d 100644 --- a/sound/oss/dmasound/dmasound.h +++ b/sound/oss/dmasound/dmasound.h @@ -115,8 +115,7 @@ typedef struct { typedef struct { const char *name; const char *name2; - void (*open)(void); - void (*release)(void); + struct module *owner; void *(*dma_alloc)(unsigned int, int); void (*dma_free)(void *, unsigned int); int (*irqinit)(void); diff --git a/sound/oss/dmasound/dmasound_atari.c b/sound/oss/dmasound/dmasound_atari.c index 0727ab4a05e0..da681713e406 100644 --- a/sound/oss/dmasound/dmasound_atari.c +++ b/sound/oss/dmasound/dmasound_atari.c @@ -115,8 +115,6 @@ static ssize_t ata_ctx_u16le(const u_char *userPtr, size_t userCount, /*** Low level stuff *********************************************************/ -static void AtaOpen(void); -static void AtaRelease(void); static void *AtaAlloc(unsigned int size, int flags); static void AtaFree(void *, unsigned int size); static int AtaIrqInit(void); @@ -813,16 +811,6 @@ static TRANS transFalconExpanding = { * Atari (TT/Falcon) */ -static void AtaOpen(void) -{ - MOD_INC_USE_COUNT; -} - -static void AtaRelease(void) -{ - MOD_DEC_USE_COUNT; -} - static void *AtaAlloc(unsigned int size, int flags) { return atari_stram_alloc(size, "dmasound"); @@ -1521,8 +1509,7 @@ static SETTINGS def_soft = { static MACHINE machTT = { .name = "Atari", .name2 = "TT", - .open = AtaOpen, - .release = AtaRelease, + .owner = THIS_MODULE, .dma_alloc = AtaAlloc, .dma_free = AtaFree, .irqinit = AtaIrqInit, diff --git a/sound/oss/dmasound/dmasound_awacs.c b/sound/oss/dmasound/dmasound_awacs.c index a2ae9c70bd82..ae3a2d460135 100644 --- a/sound/oss/dmasound/dmasound_awacs.c +++ b/sound/oss/dmasound/dmasound_awacs.c @@ -252,8 +252,6 @@ int expand_bal; /* Balance factor for expanding (not volume!) */ /*** Low level stuff *********************************************************/ -static void PMacOpen(void); -static void PMacRelease(void); static void *PMacAlloc(unsigned int size, int flags); static void PMacFree(void *ptr, unsigned int size); static int PMacIrqInit(void); @@ -493,17 +491,6 @@ awacs_tumbler_cleanup(void) /* * PCI PowerMac, with AWACS, Screamer, Burgundy, DACA or Tumbler and DBDMA. */ - -static void PMacOpen(void) -{ - MOD_INC_USE_COUNT; -} - -static void PMacRelease(void) -{ - MOD_DEC_USE_COUNT; -} - static void *PMacAlloc(unsigned int size, int flags) { return kmalloc(size, flags); @@ -2428,8 +2415,7 @@ static SETTINGS def_soft = { static MACHINE machPMac = { .name = awacs_name, .name2 = "PowerMac Built-in Sound", - .open = PMacOpen, - .release = PMacRelease, + .owner = THIS_MODULE, .dma_alloc = PMacAlloc, .dma_free = PMacFree, .irqinit = PMacIrqInit, diff --git a/sound/oss/dmasound/dmasound_core.c b/sound/oss/dmasound/dmasound_core.c index 31017235b57c..2dfed71283eb 100644 --- a/sound/oss/dmasound/dmasound_core.c +++ b/sound/oss/dmasound/dmasound_core.c @@ -327,7 +327,8 @@ static struct { static int mixer_open(struct inode *inode, struct file *file) { - dmasound.mach.open(); + if (!try_module_get(dmasound.mach.owner)) + return -ENODEV; mixer.busy = 1; return 0; } @@ -336,7 +337,7 @@ static int mixer_release(struct inode *inode, struct file *file) { lock_kernel(); mixer.busy = 0; - dmasound.mach.release(); + module_put(dmasound.mach.owner); unlock_kernel(); return 0; } @@ -869,31 +870,29 @@ static int sq_open(struct inode *inode, struct file *file) { int rc; - dmasound.mach.open(); + if (!try_module_get(dmasound.mach.owner)) + return -ENODEV; - if ((rc = write_sq_open(file))) { /* checks the f_mode */ - dmasound.mach.release(); - return rc; - } + rc = write_sq_open(file); /* checks the f_mode */ + if (rc) + goto out; #ifdef HAS_RECORD if (dmasound.mach.record) { - if ((rc = read_sq_open(file))) { /* checks the f_mode */ - dmasound.mach.release(); - return rc; - } + rc = read_sq_open(file); /* checks the f_mode */ + if (rc) + goto out; } else { /* no record function installed; in compat mode */ if (file->f_mode & FMODE_READ) { /* TODO: if O_RDWR, release any resources grabbed by write part */ - dmasound.mach.release() ; - /* I think this is what is required by open(2) */ - return -ENXIO ; + rc = -ENXIO; + goto out; } } #else /* !HAS_RECORD */ if (file->f_mode & FMODE_READ) { /* TODO: if O_RDWR, release any resources grabbed by write part */ - dmasound.mach.release() ; - return -ENXIO ; /* I think this is what is required by open(2) */ + rc = -ENXIO ; /* I think this is what is required by open(2) */ + goto out; } #endif /* HAS_RECORD */ @@ -931,6 +930,9 @@ static int sq_open(struct inode *inode, struct file *file) #endif return 0; + out: + module_put(dmasound.mach.owner); + return rc; } static void sq_reset_output(void) @@ -1050,7 +1052,7 @@ static int sq_release(struct inode *inode, struct file *file) dmasound.hard = dmasound.mach.default_hard ; } - dmasound.mach.release(); + module_put(dmasound.mach.owner); #if 0 /* blocking open() */ /* Wake up a process waiting for the queue being released. @@ -1447,7 +1449,8 @@ static int state_open(struct inode *inode, struct file *file) if (state.busy) return -EBUSY; - dmasound.mach.open(); + if (!try_module_get(dmasound.mach.owner)) + return -ENODEV; state.ptr = 0; state.busy = 1; @@ -1529,7 +1532,7 @@ static int state_release(struct inode *inode, struct file *file) { lock_kernel(); state.busy = 0; - dmasound.mach.release(); + module_put(dmasound.mach.owner); unlock_kernel(); return 0; } diff --git a/sound/oss/dmasound/dmasound_paula.c b/sound/oss/dmasound/dmasound_paula.c index 4be7c98ac0f5..b24c42ea695b 100644 --- a/sound/oss/dmasound/dmasound_paula.c +++ b/sound/oss/dmasound/dmasound_paula.c @@ -69,8 +69,6 @@ static int write_sq_block_size_half, write_sq_block_size_quarter; /*** Low level stuff *********************************************************/ -static void AmiOpen(void); -static void AmiRelease(void); static void *AmiAlloc(unsigned int size, int flags); static void AmiFree(void *obj, unsigned int size); static int AmiIrqInit(void); @@ -311,17 +309,6 @@ static TRANS transAmiga = { /*** Low level stuff *********************************************************/ - -static void AmiOpen(void) -{ - MOD_INC_USE_COUNT; -} - -static void AmiRelease(void) -{ - MOD_DEC_USE_COUNT; -} - static inline void StopDMA(void) { custom.aud[0].audvol = custom.aud[1].audvol = 0; @@ -699,8 +686,7 @@ static SETTINGS def_soft = { static MACHINE machAmiga = { .name = "Amiga", .name2 = "AMIGA", - .open = AmiOpen, - .release = AmiRelease, + .owner = THIS_MODULE, .dma_alloc = AmiAlloc, .dma_free = AmiFree, .irqinit = AmiIrqInit, diff --git a/sound/oss/dmasound/dmasound_q40.c b/sound/oss/dmasound/dmasound_q40.c index 920de38d4305..82a5443de4ab 100644 --- a/sound/oss/dmasound/dmasound_q40.c +++ b/sound/oss/dmasound/dmasound_q40.c @@ -36,8 +36,6 @@ static int expand_data; /* Data for expanding */ /*** Low level stuff *********************************************************/ -static void Q40Open(void); -static void Q40Release(void); static void *Q40Alloc(unsigned int size, int flags); static void Q40Free(void *, unsigned int); static int Q40IrqInit(void); @@ -360,18 +358,6 @@ static TRANS transQ40Compressing = { /*** Low level stuff *********************************************************/ - -static void Q40Open(void) -{ - MOD_INC_USE_COUNT; -} - -static void Q40Release(void) -{ - MOD_DEC_USE_COUNT; -} - - static void *Q40Alloc(unsigned int size, int flags) { return kmalloc(size, flags); /* change to vmalloc */ @@ -603,8 +589,7 @@ static SETTINGS def_soft = { static MACHINE machQ40 = { .name = "Q40", .name2 = "Q40", - .open = Q40Open, - .release = Q40Release, + .owner = THIS_MODULE, .dma_alloc = Q40Alloc, .dma_free = Q40Free, .irqinit = Q40IrqInit, -- 2.39.5