[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 08/27] audio/audio_template: use g_malloc0() to replace audio_call
From: |
marcandre . lureau |
Subject: |
[PULL 08/27] audio/audio_template: use g_malloc0() to replace audio_calloc() |
Date: |
Mon, 6 Mar 2023 10:51:43 +0400 |
From: Volker Rümelin <vr_qemu@t-online.de>
Use g_malloc0() as a direct replacement for audio_calloc().
Since the type of the parameter n_bytes of the function g_malloc0()
is unsigned, the type of the variables voice_size_out and
voice_size_in has been changed to size_t. This means that the
function argument no longer has to be checked for negative values.
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20230121094735.11644-7-vr_qemu@t-online.de>
---
audio/audio_int.h | 4 ++--
audio/audio_template.h | 18 ++++++++----------
2 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/audio/audio_int.h b/audio/audio_int.h
index 4632cdf9cc..ce2d6bf92c 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -151,8 +151,8 @@ struct audio_driver {
int can_be_default;
int max_voices_out;
int max_voices_in;
- int voice_size_out;
- int voice_size_in;
+ size_t voice_size_out;
+ size_t voice_size_in;
QLIST_ENTRY(audio_driver) next;
};
diff --git a/audio/audio_template.h b/audio/audio_template.h
index dfa440f778..592866f14a 100644
--- a/audio/audio_template.h
+++ b/audio/audio_template.h
@@ -40,7 +40,7 @@ static void glue(audio_init_nb_voices_, TYPE)(AudioState *s,
struct audio_driver *drv)
{
int max_voices = glue (drv->max_voices_, TYPE);
- int voice_size = glue (drv->voice_size_, TYPE);
+ size_t voice_size = glue(drv->voice_size_, TYPE);
if (glue (s->nb_hw_voices_, TYPE) > max_voices) {
if (!max_voices) {
@@ -63,8 +63,8 @@ static void glue(audio_init_nb_voices_, TYPE)(AudioState *s,
}
if (audio_bug(__func__, voice_size && !max_voices)) {
- dolog ("drv=`%s' voice_size=%d max_voices=0\n",
- drv->name, voice_size);
+ dolog("drv=`%s' voice_size=%zu max_voices=0\n",
+ drv->name, voice_size);
}
}
@@ -273,13 +273,11 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState
*s,
return NULL;
}
- hw = audio_calloc(__func__, 1, glue(drv->voice_size_, TYPE));
- if (!hw) {
- dolog ("Can not allocate voice `%s' size %d\n",
- drv->name, glue (drv->voice_size_, TYPE));
- return NULL;
- }
-
+ /*
+ * Since glue(s->nb_hw_voices_, TYPE) is != 0, glue(drv->voice_size_, TYPE)
+ * is guaranteed to be != 0. See the audio_init_nb_voices_* functions.
+ */
+ hw = g_malloc0(glue(drv->voice_size_, TYPE));
hw->s = s;
hw->pcm_ops = drv->pcm_ops;
--
2.39.2
- [PULL 00/27] Audio patches, marcandre . lureau, 2023/03/06
- [PULL 03/27] audio: don't show unnecessary error messages, marcandre . lureau, 2023/03/06
- [PULL 02/27] audio: log unimplemented audio device sample rates, marcandre . lureau, 2023/03/06
- [PULL 01/27] MAINTAINERS: add myself to ui/ and audio/, marcandre . lureau, 2023/03/06
- [PULL 04/27] audio: rename hardware store to backend, marcandre . lureau, 2023/03/06
- [PULL 05/27] audio: remove unused #define AUDIO_STRINGIFY, marcandre . lureau, 2023/03/06
- [PULL 06/27] audio/mixeng: use g_new0() instead of audio_calloc(), marcandre . lureau, 2023/03/06
- [PULL 09/27] audio/audio_template: use g_new0() to replace audio_calloc(), marcandre . lureau, 2023/03/06
- [PULL 07/27] audio/alsaaudio: use g_new0() instead of audio_calloc(), marcandre . lureau, 2023/03/06
- [PULL 10/27] audio: remove audio_calloc() function, marcandre . lureau, 2023/03/06
- [PULL 08/27] audio/audio_template: use g_malloc0() to replace audio_calloc(),
marcandre . lureau <=
- [PULL 11/27] alsaaudio: change default playback settings, marcandre . lureau, 2023/03/06
- [PULL 12/27] alsaaudio: reintroduce default recording settings, marcandre . lureau, 2023/03/06
- [PULL 13/27] audio: change type of mix_buf and conv_buf, marcandre . lureau, 2023/03/06
- [PULL 14/27] audio: change type and name of the resample buffer, marcandre . lureau, 2023/03/06
- [PULL 15/27] audio: make the resampling code greedy, marcandre . lureau, 2023/03/06
- [PULL 16/27] audio: replace the resampling loop in audio_pcm_sw_write(), marcandre . lureau, 2023/03/06
- [PULL 17/27] audio: remove sw == NULL check, marcandre . lureau, 2023/03/06
- [PULL 18/27] audio: rename variables in audio_pcm_sw_write(), marcandre . lureau, 2023/03/06
- [PULL 19/27] audio: don't misuse audio_pcm_sw_write(), marcandre . lureau, 2023/03/06
- [PULL 20/27] audio: remove unused noop_conv() function, marcandre . lureau, 2023/03/06