From ca8cc756245265202407bdce5480250a0028ea08 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Thu, 25 Sep 2003 19:16:48 +0200 Subject: [PATCH] ALSA CVS update D:2003/09/04 19:45:26 C:HWDEP Midlevel A:Jaroslav Kysela F:core/hwdep.c:1.19->1.20 L:Use try_module_get() and module_put() to block the toplevel module L:Fixed returned error code in the release() callback --- sound/core/hwdep.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/sound/core/hwdep.c b/sound/core/hwdep.c index 3e94857d1a7e6..355a0a8d794e3 100644 --- a/sound/core/hwdep.c +++ b/sound/core/hwdep.c @@ -97,14 +97,19 @@ static int snd_hwdep_open(struct inode *inode, struct file * file) cardnum %= SNDRV_CARDS; device %= SNDRV_MINOR_HWDEPS; hw = snd_hwdep_devices[(cardnum * SNDRV_MINOR_HWDEPS) + device]; + if (hw == NULL) + return -ENODEV; - snd_assert(hw != NULL, return -ENODEV); if (!hw->ops.open) return -ENXIO; #ifdef CONFIG_SND_OSSEMUL if (major == SOUND_MAJOR && hw->oss_type < 0) return -ENXIO; #endif + + if (!try_module_get(hw->card->module)) + return -EFAULT; + init_waitqueue_entry(&wait, current); add_wait_queue(&hw->open_wait, &wait); down(&hw->open_mutex); @@ -137,9 +142,14 @@ static int snd_hwdep_open(struct inode *inode, struct file * file) if (err >= 0) { file->private_data = hw; hw->used++; + } else { + if (hw->ops.release) + hw->ops.release(hw, file); } } up(&hw->open_mutex); + if (err < 0) + module_put(hw->card->module); return err; } @@ -156,7 +166,8 @@ static int snd_hwdep_release(struct inode *inode, struct file * file) hw->used--; snd_card_file_remove(hw->card, file); up(&hw->open_mutex); - return -ENXIO; + module_put(hw->card->module); + return err; } static unsigned int snd_hwdep_poll(struct file * file, poll_table * wait) -- 2.53.0