Skip to contentSkip to conversation

audio: Drop superfluous conditionals around g_free()

PATCH In review Markus Armbruster 3 participants 5 messages Jun 6, 2014 – Jun 12, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 audio: Drop superfluous conditionals around g_free()

---
 audio/alsaaudio.c      | 12 ++++--------
 audio/audio_template.h | 15 ++++-----------
 audio/ossaudio.c       |  6 ++----
 hw/audio/adlib.c       |  4 +---
 4 files changed, 11 insertions(+), 26 deletions(-)
audio/alsaaudio.c +4 -8
index e4e5442..74ead97 100644
@@ -815,10 +815,8 @@ static void alsa_fini_out (HWVoiceOut *hw)
     ldebug ("alsa_fini\n");
     alsa_anal_close (&alsa->handle, &alsa->pollhlp);
 
-    if (alsa->pcm_buf) {
-        g_free (alsa->pcm_buf);
-        alsa->pcm_buf = NULL;
-    }
+    g_free(alsa->pcm_buf);
+    alsa->pcm_buf = NULL;
 }
 
 static int alsa_init_out (HWVoiceOut *hw, struct audsettings *as)
@@ -978,10 +976,8 @@ static void alsa_fini_in (HWVoiceIn *hw)
 
     alsa_anal_close (&alsa->handle, &alsa->pollhlp);
 
-    if (alsa->pcm_buf) {
-        g_free (alsa->pcm_buf);
-        alsa->pcm_buf = NULL;
-    }
+    g_free(alsa->pcm_buf);
+    alsa->pcm_buf = NULL;
 }
 
 static int alsa_run_in (HWVoiceIn *hw)
audio/audio_template.h +4 -11
index 16f7880..8173188 100644
@@ -71,10 +71,7 @@ static void glue (audio_init_nb_voices_, TYPE) (struct audio_driver *drv)
 
 static void glue (audio_pcm_hw_free_resources_, TYPE) (HW *hw)
 {
-    if (HWBUF) {
-        g_free (HWBUF);
-    }
-
+    g_free (HWBUF);
     HWBUF = NULL;
 }
 
@@ -92,9 +89,7 @@ static int glue (audio_pcm_hw_alloc_resources_, TYPE) (HW *hw)
 
 static void glue (audio_pcm_sw_free_resources_, TYPE) (SW *sw)
 {
-    if (sw->buf) {
-        g_free (sw->buf);
-    }
+    g_free (sw->buf);
 
     if (sw->rate) {
         st_rate_stop (sw->rate);
@@ -172,10 +167,8 @@ static int glue (audio_pcm_sw_init_, TYPE) (
 static void glue (audio_pcm_sw_fini_, TYPE) (SW *sw)
 {
     glue (audio_pcm_sw_free_resources_, TYPE) (sw);
-    if (sw->name) {
-        g_free (sw->name);
-        sw->name = NULL;
-    }
+    g_free (sw->name);
+    sw->name = NULL;
 }
 
 static void glue (audio_pcm_hw_add_sw_, TYPE) (HW *hw, SW *sw)
audio/ossaudio.c +2 -4
index 5a73716..4db2ca6 100644
@@ -736,10 +736,8 @@ static void oss_fini_in (HWVoiceIn *hw)
 
     oss_anal_close (&oss->fd);
 
-    if (oss->pcm_buf) {
-        g_free (oss->pcm_buf);
-        oss->pcm_buf = NULL;
-    }
+    g_free(oss->pcm_buf);
+    oss->pcm_buf = NULL;
 }
 
 static int oss_run_in (HWVoiceIn *hw)
hw/audio/adlib.c +1 -3
index 5dd739e..656eb37 100644
@@ -275,9 +275,7 @@ static void Adlib_fini (AdlibState *s)
     }
 #endif
 
-    if (s->mixbuf) {
-        g_free (s->mixbuf);
-    }
+    g_free(s->mixbuf);
 
     s->active = 0;
     s->enabled = 0;
Signature · 1 line
1.9.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Markus Armbruster
---
 audio/alsaaudio.c      | 12 ++++--------
 audio/audio_template.h | 15 ++++-----------
 audio/ossaudio.c       |  6 ++----
 hw/audio/adlib.c       |  4 +---
 4 files changed, 11 insertions(+), 26 deletions(-)

+++ b/audio/audio_template.h

audio/audio_template.h static void glue (audio_init_nb_voices_, TYPE) (struct audio_driver *drv) · line 74

Quoted 8 lines
audio/audio_template.h +1 -4
@@ -71,10 +71,7 @@ static void glue (audio_init_nb_voices_, TYPE) (struct audio_driver *drv)
 
 static void glue (audio_pcm_hw_free_resources_, TYPE) (HW *hw)
 {
-    if (HWBUF) {
-        g_free (HWBUF);
-    }
-
+    g_free (HWBUF);

While touching this, you may want to drop the space.

audio/audio_template.h static int glue (audio_pcm_hw_alloc_resources_, TYPE) (HW *hw) · line 92

Quoted 8 lines
audio/audio_template.h +1 -3
@@ -92,9 +89,7 @@ static int glue (audio_pcm_hw_alloc_resources_, TYPE) (HW *hw)
 
 static void glue (audio_pcm_sw_free_resources_, TYPE) (SW *sw)
 {
-    if (sw->buf) {
-        g_free (sw->buf);
-    }
+    g_free (sw->buf);

here too.

audio/audio_template.h static int glue (audio_pcm_sw_init_, TYPE) ( · line 171

Quoted 10 lines
audio/audio_template.h +2 -4
@@ -172,10 +167,8 @@ static int glue (audio_pcm_sw_init_, TYPE) (
 static void glue (audio_pcm_sw_fini_, TYPE) (SW *sw)
 {
     glue (audio_pcm_sw_free_resources_, TYPE) (sw);
-    if (sw->name) {
-        g_free (sw->name);
-        sw->name = NULL;
-    }
+    g_free (sw->name);
+    sw->name = NULL;

hmm, it looks like that style is pervasive in this file.

audio/ossaudio.c static void oss_fini_in (HWVoiceIn *hw) · line 740

Quoted 11 lines
audio/ossaudio.c +3 -4
+++ b/audio/ossaudio.c
@@ -736,10 +736,8 @@ static void oss_fini_in (HWVoiceIn *hw)
 
     oss_anal_close (&oss->fd);
 
-    if (oss->pcm_buf) {
-        g_free (oss->pcm_buf);
-        oss->pcm_buf = NULL;
-    }
+    g_free(oss->pcm_buf);
+    oss->pcm_buf = NULL;

Here, you DID trim the space. Be consistent - either preserve the original spacing, or clean it up everywhere.

At any rate, whitespace is trivial, so either way:

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
Quoted 35 lines · Eric Blake
Quoted 11 lines · Markus Armbruster
---
 audio/alsaaudio.c      | 12 ++++--------
 audio/audio_template.h | 15 ++++-----------
 audio/ossaudio.c       |  6 ++----
 hw/audio/adlib.c       |  4 +---
 4 files changed, 11 insertions(+), 26 deletions(-)

+++ b/audio/audio_template.h

audio/audio_template.h static void glue (audio_init_nb_voices_, TYPE) (struct audio_driver *drv) · line 74

Quoted 8 lines
audio/audio_template.h +1 -4
@@ -71,10 +71,7 @@ static void glue (audio_init_nb_voices_, TYPE) (struct audio_driver *drv)
 
 static void glue (audio_pcm_hw_free_resources_, TYPE) (HW *hw)
 {
-    if (HWBUF) {
-        g_free (HWBUF);
-    }
-
+    g_free (HWBUF);

While touching this, you may want to drop the space.

audio/audio_template.h static int glue (audio_pcm_hw_alloc_resources_, · line 93

Quoted 9 lines
audio/audio_template.h +1 -3
@@ -92,9 +89,7 @@ static int glue (audio_pcm_hw_alloc_resources_,
 TYPE) (HW *hw)
 
 static void glue (audio_pcm_sw_free_resources_, TYPE) (SW *sw)
 {
-    if (sw->buf) {
-        g_free (sw->buf);
-    }
+    g_free (sw->buf);

here too.

Quoted 12 lines

audio/audio_template.h static int glue (audio_pcm_sw_init_, TYPE) ( · line 171

Quoted 10 lines
audio/audio_template.h +2 -4
@@ -172,10 +167,8 @@ static int glue (audio_pcm_sw_init_, TYPE) (
 static void glue (audio_pcm_sw_fini_, TYPE) (SW *sw)
 {
     glue (audio_pcm_sw_free_resources_, TYPE) (sw);
-    if (sw->name) {
-        g_free (sw->name);
-        sw->name = NULL;
-    }
+    g_free (sw->name);
+    sw->name = NULL;

hmm, it looks like that style is pervasive in this file.

All files are equal in coding style, but some files are more equal than others.

Specifically, audio/ and hw/audio/.

Quoted 5 lines
Quoted 5 lines
audio/ossaudio.c +1 -0
+++ b/audio/ossaudio.c
@@ -736,10 +736,8 @@ static void oss_fini_in (HWVoiceIn *hw)
 
     oss_anal_close (&oss->fd);
 
Quoted 9 lines

audio/ossaudio.c static void oss_fini_in (HWVoiceIn *hw) · line 740

Quoted 6 lines
audio/ossaudio.c +2 -4
-    if (oss->pcm_buf) {
-        g_free (oss->pcm_buf);
-        oss->pcm_buf = NULL;
-    }
+    g_free(oss->pcm_buf);
+    oss->pcm_buf = NULL;

Here, you DID trim the space. Be consistent - either preserve the original spacing, or clean it up everywhere.

I meant to stick to the audio style, but fingers overruled brain here.

Quoted 3 lines

At any rate, whitespace is trivial, so either way:

Gerd, should patches for audio/ conform to the usual style now, or are they still special?

#3 lore raw

Hi,

Quoted 2 lines

Gerd, should patches for audio/ conform to the usual style now, or are they still special?

I don't consider them special. If you use usual qemu style in patches that is fine with me. But I don't feel like doing a conversion pass, that simply isn't worth the trouble IMO.

cheers,
Gerd