[PATCH] alsa: Silence some Valgrind warnings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I don't know if there's some bug in alsa-lib or not, but reading dB
values seems to irritate Valgrind a lot. These changes remove all
warnings that can be removed within our own code, but reading dB
values still causes warnings within alsa-lib code.
---
 src/modules/alsa/alsa-mixer.c | 59 ++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 52 insertions(+), 7 deletions(-)

diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index 99de0ec..b6e2fd8 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -653,7 +653,10 @@ static int element_get_volume(pa_alsa_element *e, snd_mixer_t *m, const pa_chann
                 continue;
 
 #ifdef HAVE_VALGRIND_MEMCHECK_H
-                VALGRIND_MAKE_MEM_DEFINED(&value, sizeof(value));
+            /* snd_mixer_selem_get_playback_dB() and
+             * snd_mixer_selem_get_capture_dB() do something dubious that makes
+             * Valgrind complain that value depends on uninitialized values. */
+            VALGRIND_MAKE_MEM_DEFINED(&value, sizeof(value));
 #endif
 
             f = from_alsa_dB(value);
@@ -858,6 +861,13 @@ static int element_get_nearest_alsa_dB(snd_mixer_elem_t *me, snd_mixer_selem_cha
         if (r < 0)
             return r;
 
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+        /* snd_mixer_selem_ask_playback_vol_dB() does something dubious that
+         * makes Valgrind complain that value_high depends on uninitialized
+         * values. */
+        VALGRIND_MAKE_MEM_DEFINED(&value_high, sizeof(value_high));
+#endif
+
         if (value_high == *value_dB)
             return r;
 
@@ -870,6 +880,13 @@ static int element_get_nearest_alsa_dB(snd_mixer_elem_t *me, snd_mixer_selem_cha
         if (r < 0)
             return r;
 
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+        /* snd_mixer_selem_ask_capture_vol_dB() does something dubious that
+         * makes Valgrind complain that value_high depends on uninitialized
+         * values. */
+        VALGRIND_MAKE_MEM_DEFINED(&value_high, sizeof(value_high));
+#endif
+
         if (value_high == *value_dB)
             return r;
 
@@ -880,6 +897,13 @@ static int element_get_nearest_alsa_dB(snd_mixer_elem_t *me, snd_mixer_selem_cha
     if (r < 0)
         return r;
 
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+    /* snd_mixer_selem_ask_playback_vol_dB() and
+     * snd_mixer_selem_ask_capture_vol_dB() do something dubious that makes
+     * Valgrind complain that value_low depends on unitialized values. */
+    VALGRIND_MAKE_MEM_DEFINED(&value_low, sizeof(value_low));
+#endif
+
     if (labs(value_high - *value_dB) < labs(value_low - *value_dB))
         *value_dB = value_high;
     else
@@ -1002,6 +1026,12 @@ static int element_set_volume(pa_alsa_element *e, snd_mixer_t *m, const pa_chann
                 continue;
 
 #ifdef HAVE_VALGRIND_MEMCHECK_H
+            /* snd_mixer_selem_get_playback_dB(),
+             * snd_mixer_selem_ask_playback_vol_dB(),
+             * snd_mixer_selem_get_capture_dB() and
+             * snd_mixer_selem_ask_capture_vol_dB() do something dubious that
+             * makes Valgrind complain that value depends on unitialized
+             * values. */
             VALGRIND_MAKE_MEM_DEFINED(&value, sizeof(value));
 #endif
 
@@ -1427,7 +1457,6 @@ static int element_probe(pa_alsa_element *e, snd_mixer_t *m) {
         }
 
         if (e->volume_use != PA_ALSA_VOLUME_IGNORE) {
-            long min_dB = 0, max_dB = 0;
             int r;
 
             e->direction_try_other = false;
@@ -1453,6 +1482,7 @@ static int element_probe(pa_alsa_element *e, snd_mixer_t *m) {
                 e->volume_use = PA_ALSA_VOLUME_IGNORE;
 
             } else {
+                long min_dB = 0, max_dB = 0;
                 bool is_mono;
                 pa_channel_position_t p;
 
@@ -1479,6 +1509,17 @@ static int element_probe(pa_alsa_element *e, snd_mixer_t *m) {
                 else
                     e->has_dB = snd_mixer_selem_get_capture_dB_range(me, &min_dB, &max_dB) >= 0;
 
+                if (e->has_dB) {
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+                    /* snd_mixer_selem_get_playback_dB_range() and
+                     * snd_mixer_selem_get_capture_dB_range() do something
+                     * dubious that makes Valgrind complain that min_dB and
+                     * max_dB depend on uninitialized values. */
+                    VALGRIND_MAKE_MEM_DEFINED(&min_dB, sizeof(min_dB));
+                    VALGRIND_MAKE_MEM_DEFINED(&max_dB, sizeof(max_dB));
+#endif
+                }
+
                 /* Check that the kernel driver returns consistent limits with
                  * both _get_*_dB_range() and _ask_*_vol_dB(). */
                 if (e->has_dB && !e->db_fix) {
@@ -1505,6 +1546,15 @@ static int element_probe(pa_alsa_element *e, snd_mixer_t *m) {
                         return -1;
                     }
 
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+                    /* snd_mixer_selem_ask_playback_vol_dB() and
+                     * snd_mixer_selem_ask_capture_vol_dB() do something
+                     * dubious that makes Valgrind complain that min_dB_checked
+                     * and max_dB_checked depend on uninitialized values. */
+                    VALGRIND_MAKE_MEM_DEFINED(&min_dB_checked, sizeof(min_dB_checked));
+                    VALGRIND_MAKE_MEM_DEFINED(&max_dB_checked, sizeof(max_dB_checked));
+#endif
+
                     if (min_dB != min_dB_checked || max_dB != max_dB_checked) {
                         pa_log_warn("Your kernel driver is broken: the reported dB range for %s (from %0.2f dB to %0.2f dB) "
                                     "doesn't match the dB values at minimum and maximum volume levels: %0.2f dB at level %li, "
@@ -1517,11 +1567,6 @@ static int element_probe(pa_alsa_element *e, snd_mixer_t *m) {
                 }
 
                 if (e->has_dB) {
-#ifdef HAVE_VALGRIND_MEMCHECK_H
-                    VALGRIND_MAKE_MEM_DEFINED(&min_dB, sizeof(min_dB));
-                    VALGRIND_MAKE_MEM_DEFINED(&max_dB, sizeof(max_dB));
-#endif
-
                     e->min_dB = ((double) min_dB) / 100.0;
                     e->max_dB = ((double) max_dB) / 100.0;
 
-- 
1.8.3.1



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux