aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClemens Ladisch <clemens@ladisch.de>2007-07-16 05:01:30 -0400
committerJaroslav Kysela <perex@suse.cz>2007-07-20 05:11:54 -0400
commit7c64ec343a7d7b2d73b19e6bb8d9fd15f0462890 (patch)
tree0066624778782a064a472e959132238c39a59e50
parentc28054d4b31d78272f65c0d11db0796f50fb9569 (diff)
[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: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Jaroslav Kysela <perex@suse.cz>
-rw-r--r--sound/core/timer.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/sound/core/timer.c b/sound/core/timer.c
index 67520b3c0042..f2bbacedd567 100644
--- a/sound/core/timer.c
+++ b/sound/core/timer.c
@@ -1549,9 +1549,11 @@ static int snd_timer_user_info(struct file *file,
1549 int err = 0; 1549 int err = 0;
1550 1550
1551 tu = file->private_data; 1551 tu = file->private_data;
1552 snd_assert(tu->timeri != NULL, return -ENXIO); 1552 if (!tu->timeri)
1553 return -EBADFD;
1553 t = tu->timeri->timer; 1554 t = tu->timeri->timer;
1554 snd_assert(t != NULL, return -ENXIO); 1555 if (!t)
1556 return -EBADFD;
1555 1557
1556 info = kzalloc(sizeof(*info), GFP_KERNEL); 1558 info = kzalloc(sizeof(*info), GFP_KERNEL);
1557 if (! info) 1559 if (! info)
@@ -1579,9 +1581,11 @@ static int snd_timer_user_params(struct file *file,
1579 int err; 1581 int err;
1580 1582
1581 tu = file->private_data; 1583 tu = file->private_data;
1582 snd_assert(tu->timeri != NULL, return -ENXIO); 1584 if (!tu->timeri)
1585 return -EBADFD;
1583 t = tu->timeri->timer; 1586 t = tu->timeri->timer;
1584 snd_assert(t != NULL, return -ENXIO); 1587 if (!t)
1588 return -EBADFD;
1585 if (copy_from_user(&params, _params, sizeof(params))) 1589 if (copy_from_user(&params, _params, sizeof(params)))
1586 return -EFAULT; 1590 return -EFAULT;
1587 if (!(t->hw.flags & SNDRV_TIMER_HW_SLAVE) && params.ticks < 1) { 1591 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 struct snd_timer_status status; 1679 struct snd_timer_status status;
1676 1680
1677 tu = file->private_data; 1681 tu = file->private_data;
1678 snd_assert(tu->timeri != NULL, return -ENXIO); 1682 if (!tu->timeri)
1683 return -EBADFD;
1679 memset(&status, 0, sizeof(status)); 1684 memset(&status, 0, sizeof(status));
1680 status.tstamp = tu->tstamp; 1685 status.tstamp = tu->tstamp;
1681 status.resolution = snd_timer_resolution(tu->timeri); 1686 status.resolution = snd_timer_resolution(tu->timeri);
@@ -1695,7 +1700,8 @@ static int snd_timer_user_start(struct file *file)
1695 struct snd_timer_user *tu; 1700 struct snd_timer_user *tu;
1696 1701
1697 tu = file->private_data; 1702 tu = file->private_data;
1698 snd_assert(tu->timeri != NULL, return -ENXIO); 1703 if (!tu->timeri)
1704 return -EBADFD;
1699 snd_timer_stop(tu->timeri); 1705 snd_timer_stop(tu->timeri);
1700 tu->timeri->lost = 0; 1706 tu->timeri->lost = 0;
1701 tu->last_resolution = 0; 1707 tu->last_resolution = 0;
@@ -1708,7 +1714,8 @@ static int snd_timer_user_stop(struct file *file)
1708 struct snd_timer_user *tu; 1714 struct snd_timer_user *tu;
1709 1715
1710 tu = file->private_data; 1716 tu = file->private_data;
1711 snd_assert(tu->timeri != NULL, return -ENXIO); 1717 if (!tu->timeri)
1718 return -EBADFD;
1712 return (err = snd_timer_stop(tu->timeri)) < 0 ? err : 0; 1719 return (err = snd_timer_stop(tu->timeri)) < 0 ? err : 0;
1713} 1720}
1714 1721
@@ -1718,7 +1725,8 @@ static int snd_timer_user_continue(struct file *file)
1718 struct snd_timer_user *tu; 1725 struct snd_timer_user *tu;
1719 1726
1720 tu = file->private_data; 1727 tu = file->private_data;
1721 snd_assert(tu->timeri != NULL, return -ENXIO); 1728 if (!tu->timeri)
1729 return -EBADFD;
1722 tu->timeri->lost = 0; 1730 tu->timeri->lost = 0;
1723 return (err = snd_timer_continue(tu->timeri)) < 0 ? err : 0; 1731 return (err = snd_timer_continue(tu->timeri)) < 0 ? err : 0;
1724} 1732}
@@ -1729,7 +1737,8 @@ static int snd_timer_user_pause(struct file *file)
1729 struct snd_timer_user *tu; 1737 struct snd_timer_user *tu;
1730 1738
1731 tu = file->private_data; 1739 tu = file->private_data;
1732 snd_assert(tu->timeri != NULL, return -ENXIO); 1740 if (!tu->timeri)
1741 return -EBADFD;
1733 return (err = snd_timer_pause(tu->timeri)) < 0 ? err : 0; 1742 return (err = snd_timer_pause(tu->timeri)) < 0 ? err : 0;
1734} 1743}
1735 1744