提交 7c64ec34 编写于 作者: C Clemens Ladisch 提交者: Jaroslav Kysela

[ALSA] timer: check for incorrect device state in non-debug compiles, too

Convert the snd_assert()s to simple if()s to prevent crashes when one of
the timer instance ioctls is called before the file is bound to a timer
device.
Signed-off-by: NClemens Ladisch <clemens@ladisch.de>
Signed-off-by: NJaroslav Kysela <perex@suse.cz>
上级 c28054d4
...@@ -1549,9 +1549,11 @@ static int snd_timer_user_info(struct file *file, ...@@ -1549,9 +1549,11 @@ static int snd_timer_user_info(struct file *file,
int err = 0; int err = 0;
tu = file->private_data; tu = file->private_data;
snd_assert(tu->timeri != NULL, return -ENXIO); if (!tu->timeri)
return -EBADFD;
t = tu->timeri->timer; t = tu->timeri->timer;
snd_assert(t != NULL, return -ENXIO); if (!t)
return -EBADFD;
info = kzalloc(sizeof(*info), GFP_KERNEL); info = kzalloc(sizeof(*info), GFP_KERNEL);
if (! info) if (! info)
...@@ -1579,9 +1581,11 @@ static int snd_timer_user_params(struct file *file, ...@@ -1579,9 +1581,11 @@ static int snd_timer_user_params(struct file *file,
int err; int err;
tu = file->private_data; tu = file->private_data;
snd_assert(tu->timeri != NULL, return -ENXIO); if (!tu->timeri)
return -EBADFD;
t = tu->timeri->timer; t = tu->timeri->timer;
snd_assert(t != NULL, return -ENXIO); if (!t)
return -EBADFD;
if (copy_from_user(&params, _params, sizeof(params))) if (copy_from_user(&params, _params, sizeof(params)))
return -EFAULT; return -EFAULT;
if (!(t->hw.flags & SNDRV_TIMER_HW_SLAVE) && params.ticks < 1) { if (!(t->hw.flags & SNDRV_TIMER_HW_SLAVE) && params.ticks < 1) {
...@@ -1675,7 +1679,8 @@ static int snd_timer_user_status(struct file *file, ...@@ -1675,7 +1679,8 @@ static int snd_timer_user_status(struct file *file,
struct snd_timer_status status; struct snd_timer_status status;
tu = file->private_data; tu = file->private_data;
snd_assert(tu->timeri != NULL, return -ENXIO); if (!tu->timeri)
return -EBADFD;
memset(&status, 0, sizeof(status)); memset(&status, 0, sizeof(status));
status.tstamp = tu->tstamp; status.tstamp = tu->tstamp;
status.resolution = snd_timer_resolution(tu->timeri); status.resolution = snd_timer_resolution(tu->timeri);
...@@ -1695,7 +1700,8 @@ static int snd_timer_user_start(struct file *file) ...@@ -1695,7 +1700,8 @@ static int snd_timer_user_start(struct file *file)
struct snd_timer_user *tu; struct snd_timer_user *tu;
tu = file->private_data; tu = file->private_data;
snd_assert(tu->timeri != NULL, return -ENXIO); if (!tu->timeri)
return -EBADFD;
snd_timer_stop(tu->timeri); snd_timer_stop(tu->timeri);
tu->timeri->lost = 0; tu->timeri->lost = 0;
tu->last_resolution = 0; tu->last_resolution = 0;
...@@ -1708,7 +1714,8 @@ static int snd_timer_user_stop(struct file *file) ...@@ -1708,7 +1714,8 @@ static int snd_timer_user_stop(struct file *file)
struct snd_timer_user *tu; struct snd_timer_user *tu;
tu = file->private_data; tu = file->private_data;
snd_assert(tu->timeri != NULL, return -ENXIO); if (!tu->timeri)
return -EBADFD;
return (err = snd_timer_stop(tu->timeri)) < 0 ? err : 0; return (err = snd_timer_stop(tu->timeri)) < 0 ? err : 0;
} }
...@@ -1718,7 +1725,8 @@ static int snd_timer_user_continue(struct file *file) ...@@ -1718,7 +1725,8 @@ static int snd_timer_user_continue(struct file *file)
struct snd_timer_user *tu; struct snd_timer_user *tu;
tu = file->private_data; tu = file->private_data;
snd_assert(tu->timeri != NULL, return -ENXIO); if (!tu->timeri)
return -EBADFD;
tu->timeri->lost = 0; tu->timeri->lost = 0;
return (err = snd_timer_continue(tu->timeri)) < 0 ? err : 0; return (err = snd_timer_continue(tu->timeri)) < 0 ? err : 0;
} }
...@@ -1729,7 +1737,8 @@ static int snd_timer_user_pause(struct file *file) ...@@ -1729,7 +1737,8 @@ static int snd_timer_user_pause(struct file *file)
struct snd_timer_user *tu; struct snd_timer_user *tu;
tu = file->private_data; tu = file->private_data;
snd_assert(tu->timeri != NULL, return -ENXIO); if (!tu->timeri)
return -EBADFD;
return (err = snd_timer_pause(tu->timeri)) < 0 ? err : 0; return (err = snd_timer_pause(tu->timeri)) < 0 ? err : 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
新手
引导
客服 返回
顶部