ALSA: timer: minimize open-coded access to hw.resolution
authorOswald Buddenhagen <oswald.buddenhagen@gmx.de>
Mon, 12 Jun 2023 19:13:22 +0000 (21:13 +0200)
committerTakashi Iwai <tiwai@suse.de>
Tue, 13 Jun 2023 05:43:38 +0000 (07:43 +0200)
Some info-querying code still used hw.resolution directly instead of
calling snd_timer_hw_resolution(), thus missing a possible
hw.c_resolution callback. This patch rectifies that.

Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Link: https://lore.kernel.org/r/20230612191325.1315854-7-oswald.buddenhagen@gmx.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/timer.c

index e08a37c..9d0d2a5 100644 (file)
@@ -1246,6 +1246,7 @@ static void snd_timer_proc_read(struct snd_info_entry *entry,
 {
        struct snd_timer *timer;
        struct snd_timer_instance *ti;
+       unsigned long resolution;
 
        mutex_lock(&register_mutex);
        list_for_each_entry(timer, &snd_timer_list, device_list) {
@@ -1269,10 +1270,13 @@ static void snd_timer_proc_read(struct snd_info_entry *entry,
                                    timer->tmr_device, timer->tmr_subdevice);
                }
                snd_iprintf(buffer, "%s :", timer->name);
-               if (timer->hw.resolution)
+               spin_lock_irq(&timer->lock);
+               resolution = snd_timer_hw_resolution(timer);
+               spin_unlock_irq(&timer->lock);
+               if (resolution)
                        snd_iprintf(buffer, " %lu.%03luus (%lu ticks)",
-                                   timer->hw.resolution / 1000,
-                                   timer->hw.resolution % 1000,
+                                   resolution / 1000,
+                                   resolution % 1000,
                                    timer->hw.ticks);
                if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE)
                        snd_iprintf(buffer, " SLAVE");
@@ -1662,7 +1666,9 @@ static int snd_timer_user_ginfo(struct file *file,
                        ginfo->flags |= SNDRV_TIMER_FLG_SLAVE;
                strscpy(ginfo->id, t->id, sizeof(ginfo->id));
                strscpy(ginfo->name, t->name, sizeof(ginfo->name));
-               ginfo->resolution = t->hw.resolution;
+               spin_lock_irq(&t->lock);
+               ginfo->resolution = snd_timer_hw_resolution(t);
+               spin_unlock_irq(&t->lock);
                if (t->hw.resolution_min > 0) {
                        ginfo->resolution_min = t->hw.resolution_min;
                        ginfo->resolution_max = t->hw.resolution_max;
@@ -1817,7 +1823,9 @@ static int snd_timer_user_info(struct file *file,
                info->flags |= SNDRV_TIMER_FLG_SLAVE;
        strscpy(info->id, t->id, sizeof(info->id));
        strscpy(info->name, t->name, sizeof(info->name));
-       info->resolution = t->hw.resolution;
+       spin_lock_irq(&t->lock);
+       info->resolution = snd_timer_hw_resolution(t);
+       spin_unlock_irq(&t->lock);
        if (copy_to_user(_info, info, sizeof(*_info)))
                err = -EFAULT;
        kfree(info);