[pulseaudio-discuss] [PATCH] alsa: Don't access pa_sink/source_new_data after done() has been called

Tanu Kaskinen tanu.kaskinen at linux.intel.com
Wed Feb 4 13:50:24 PST 2015


This change doesn't affect behaviour, because accessing boolean fields
in the new data was safe even after the done() call, but it was still
bad style.
---

This was originally sent as part of the patch set that tried to fix
a volume issue on Terratec Aureon Dual USB, but since that patch set
didn't get applied, and this patch is not directly related to the
Aureon issue, I'm resending this as an independent patch.


 src/modules/alsa/alsa-sink.c   | 10 +++++++---
 src/modules/alsa/alsa-source.c | 10 +++++++---
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index fbf74aa..7c21a68 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -2011,6 +2011,8 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
     size_t frame_size;
     bool use_mmap = true, b, use_tsched = true, d, ignore_dB = false, namereg_fail = false, deferred_volume = false, set_formats = false, fixed_latency_range = false;
     pa_sink_new_data data;
+    bool volume_is_set;
+    bool mute_is_set;
     pa_alsa_profile_set *profile_set = NULL;
     void *state = NULL;
 
@@ -2292,6 +2294,8 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
 
     u->sink = pa_sink_new(m->core, &data, PA_SINK_HARDWARE | PA_SINK_LATENCY | (u->use_tsched ? PA_SINK_DYNAMIC_LATENCY : 0) |
                           (set_formats ? PA_SINK_SET_FORMATS : 0));
+    volume_is_set = data.volume_is_set;
+    mute_is_set = data.muted_is_set;
     pa_sink_new_data_done(&data);
 
     if (!u->sink) {
@@ -2375,7 +2379,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
     thread_name = NULL;
 
     /* Get initial mixer settings */
-    if (data.volume_is_set) {
+    if (volume_is_set) {
         if (u->sink->set_volume)
             u->sink->set_volume(u->sink);
     } else {
@@ -2383,7 +2387,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
             u->sink->get_volume(u->sink);
     }
 
-    if (data.muted_is_set) {
+    if (mute_is_set) {
         if (u->sink->set_mute)
             u->sink->set_mute(u->sink);
     } else {
@@ -2395,7 +2399,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
         }
     }
 
-    if ((data.volume_is_set || data.muted_is_set) && u->sink->write_volume)
+    if ((volume_is_set || mute_is_set) && u->sink->write_volume)
         u->sink->write_volume(u->sink);
 
     if (set_formats) {
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index 564a8fe..1e6d668 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -1728,6 +1728,8 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
     size_t frame_size;
     bool use_mmap = true, b, use_tsched = true, d, ignore_dB = false, namereg_fail = false, deferred_volume = false, fixed_latency_range = false;
     pa_source_new_data data;
+    bool volume_is_set;
+    bool mute_is_set;
     pa_alsa_profile_set *profile_set = NULL;
     void *state = NULL;
 
@@ -1997,6 +1999,8 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
         pa_alsa_add_ports(&data, u->mixer_path_set, card);
 
     u->source = pa_source_new(m->core, &data, PA_SOURCE_HARDWARE|PA_SOURCE_LATENCY|(u->use_tsched ? PA_SOURCE_DYNAMIC_LATENCY : 0));
+    volume_is_set = data.volume_is_set;
+    mute_is_set = data.muted_is_set;
     pa_source_new_data_done(&data);
 
     if (!u->source) {
@@ -2073,7 +2077,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
     thread_name = NULL;
 
     /* Get initial mixer settings */
-    if (data.volume_is_set) {
+    if (volume_is_set) {
         if (u->source->set_volume)
             u->source->set_volume(u->source);
     } else {
@@ -2081,7 +2085,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
             u->source->get_volume(u->source);
     }
 
-    if (data.muted_is_set) {
+    if (mute_is_set) {
         if (u->source->set_mute)
             u->source->set_mute(u->source);
     } else {
@@ -2093,7 +2097,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
         }
     }
 
-    if ((data.volume_is_set || data.muted_is_set) && u->source->write_volume)
+    if ((volume_is_set || mute_is_set) && u->source->write_volume)
         u->source->write_volume(u->source);
 
     pa_source_put(u->source);
-- 
1.9.3



More information about the pulseaudio-discuss mailing list