Commit fdcb5761 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: timer: Simplify timer hw resolution calls

There multiple open-codes to get the hardware timer resolution.
Make a local helper function snd_timer_hw_resolution() and call it
from all relevant places.

There is no functional change by this, just a preliminary work for the
following timer resolution hardening patch.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 3ae18097
...@@ -427,6 +427,14 @@ int snd_timer_close(struct snd_timer_instance *timeri) ...@@ -427,6 +427,14 @@ int snd_timer_close(struct snd_timer_instance *timeri)
} }
EXPORT_SYMBOL(snd_timer_close); EXPORT_SYMBOL(snd_timer_close);
static unsigned long snd_timer_hw_resolution(struct snd_timer *timer)
{
if (timer->hw.c_resolution)
return timer->hw.c_resolution(timer);
else
return timer->hw.resolution;
}
unsigned long snd_timer_resolution(struct snd_timer_instance *timeri) unsigned long snd_timer_resolution(struct snd_timer_instance *timeri)
{ {
struct snd_timer * timer; struct snd_timer * timer;
...@@ -434,11 +442,8 @@ unsigned long snd_timer_resolution(struct snd_timer_instance *timeri) ...@@ -434,11 +442,8 @@ unsigned long snd_timer_resolution(struct snd_timer_instance *timeri)
if (timeri == NULL) if (timeri == NULL)
return 0; return 0;
timer = timeri->timer; timer = timeri->timer;
if (timer) { if (timer)
if (timer->hw.c_resolution) return snd_timer_hw_resolution(timer);
return timer->hw.c_resolution(timer);
return timer->hw.resolution;
}
return 0; return 0;
} }
EXPORT_SYMBOL(snd_timer_resolution); EXPORT_SYMBOL(snd_timer_resolution);
...@@ -771,10 +776,7 @@ void snd_timer_interrupt(struct snd_timer * timer, unsigned long ticks_left) ...@@ -771,10 +776,7 @@ void snd_timer_interrupt(struct snd_timer * timer, unsigned long ticks_left)
spin_lock_irqsave(&timer->lock, flags); spin_lock_irqsave(&timer->lock, flags);
/* remember the current resolution */ /* remember the current resolution */
if (timer->hw.c_resolution) resolution = snd_timer_hw_resolution(timer);
resolution = timer->hw.c_resolution(timer);
else
resolution = timer->hw.resolution;
/* loop for all active instances /* loop for all active instances
* Here we cannot use list_for_each_entry because the active_list of a * Here we cannot use list_for_each_entry because the active_list of a
...@@ -1014,12 +1016,8 @@ void snd_timer_notify(struct snd_timer *timer, int event, struct timespec *tstam ...@@ -1014,12 +1016,8 @@ void snd_timer_notify(struct snd_timer *timer, int event, struct timespec *tstam
spin_lock_irqsave(&timer->lock, flags); spin_lock_irqsave(&timer->lock, flags);
if (event == SNDRV_TIMER_EVENT_MSTART || if (event == SNDRV_TIMER_EVENT_MSTART ||
event == SNDRV_TIMER_EVENT_MCONTINUE || event == SNDRV_TIMER_EVENT_MCONTINUE ||
event == SNDRV_TIMER_EVENT_MRESUME) { event == SNDRV_TIMER_EVENT_MRESUME)
if (timer->hw.c_resolution) resolution = snd_timer_hw_resolution(timer);
resolution = timer->hw.c_resolution(timer);
else
resolution = timer->hw.resolution;
}
list_for_each_entry(ti, &timer->active_list_head, active_list) { list_for_each_entry(ti, &timer->active_list_head, active_list) {
if (ti->ccallback) if (ti->ccallback)
ti->ccallback(ti, event, tstamp, resolution); ti->ccallback(ti, event, tstamp, resolution);
...@@ -1656,10 +1654,7 @@ static int snd_timer_user_gstatus(struct file *file, ...@@ -1656,10 +1654,7 @@ static int snd_timer_user_gstatus(struct file *file,
mutex_lock(&register_mutex); mutex_lock(&register_mutex);
t = snd_timer_find(&tid); t = snd_timer_find(&tid);
if (t != NULL) { if (t != NULL) {
if (t->hw.c_resolution) gstatus.resolution = snd_timer_hw_resolution(t);
gstatus.resolution = t->hw.c_resolution(t);
else
gstatus.resolution = t->hw.resolution;
if (t->hw.precise_resolution) { if (t->hw.precise_resolution) {
t->hw.precise_resolution(t, &gstatus.resolution_num, t->hw.precise_resolution(t, &gstatus.resolution_num,
&gstatus.resolution_den); &gstatus.resolution_den);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment