audio: remove deprecated QEMU_AUDIO env support
PATCH 1/9 audio: don't check qemu_add_vm_change_state_handler failure
In reply to Daniel P. BerrangéThis function cannot fail since g_malloc0 aborts on OOM.
--- audio/audio.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
audio/audio.c +1 -6
@@ -1712,7 +1712,6 @@ static AudioState *audio_init(Audiodev *dev, const char *name)size_t i;int done =0 ;const char *drvname =NULL ; -VMChangeStateEntry *e;AudioState *s;struct audio_driver *driver;/* silence gcc warning about uninitialized variable */
@@ -1830,11 +1829,7 @@ static AudioState *audio_init(Audiodev *dev, const char *name) s->period_ticks = dev->timer_period * (int64_t )SCALE_US ; } - e =qemu_add_vm_change_state_handler (audio_vm_change_state_handler, s); -if (!e) { -dolog ("warning: Could not register change state handler\n" -"(Audio can continue looping even after stopping the VM)\n" ); - } +qemu_add_vm_change_state_handler (audio_vm_change_state_handler, s);QTAILQ_INSERT_TAIL (&audio_states, s, list);QLIST_INIT (&s->card_head);
Signature · 1 line
2.38.1
PATCH 6/9 docs: split the deprecation warning for soundcards vs VNC
In reply to Daniel P. BerrangéBoth soundcards and VNC will require the audiodev= property but lets split the deprecation message since these are distinct functional areas.
--- docs/about/deprecated.rst | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
docs/about/deprecated.rst +9 -5
@@ -31,13 +31,17 @@ backend settings instead of environment variables. To ease migration to the new format, the ``-audiodev-help`` option can be used to convert the current values of the environment variables to ``-audiodev`` options. -Creating sound card devices and vnc without ``audiodev=`` property (since 4.2) -'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +Creating sound card devices without ``audiodev=`` property (since 4.2) +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' When not using the deprecated legacy audio config, each sound card -should specify an ``audiodev=`` property. Additionally, when using -vnc, you should specify an ``audiodev=`` property if you plan to -transmit audio through the VNC protocol. +should specify an ``audiodev=`` property. + +Supporting audio transfer over vnc without ``audiodev=`` property (since 4.2) +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +When using vnc, you should specify an ``audiodev=`` property if you +intend to allow clients to request audio transfer through the VNC protocol. Short-form boolean options (since 6.0) ''''''''''''''''''''''''''''''''''''''
Signature · 1 line
2.38.1
PATCH 2/9 audio: remove special audio_calloc function
In reply to Daniel P. BerrangéThe audio_calloc function does various checks on the size and nmembers parameters to detect various error conditions. There are only 5 callers
* alsa_poll_helper: the pollfd count is small and bounded,
* audio_pcm_create_voice_pair_: allocating a single fixed size struct
* audio_pcm_sw_alloc_resources_: samples could be negative zero, or overflow, so needs a check
* audio_pcm_hw_add_new_: voice size could be zero for backends that don't support audio input
* st_rate_start: allocating a single fixed size struct
IOW, only two of the callers need special error checks and it is clearer if their respective checks are inlined. Thus audio_calloc can be eliminated.
--- audio/alsaaudio.c | 6 +----- audio/audio.c | 20 -------------------- audio/audio_int.h | 1 - audio/audio_template.h | 28 ++++++++++++++-------------- audio/mixeng.c | 7 +------ tests/qtest/fuzz-sb16-test.c | 6 ++++-- 6 files changed, 20 insertions(+), 48 deletions(-)
audio/alsaaudio.c +1 -5
@@ -222,11 +222,7 @@ static int alsa_poll_helper (snd_pcm_t *handle, struct pollhlp *hlp, int mask)return -1 ; } - pfds =audio_calloc ("alsa_poll_helper" , count,sizeof (*pfds)); -if (!pfds) { -dolog ("Could not initialize poll mode\n" ); -return -1 ; - } + pfds = g_new0(struct pollfd, count); err =snd_pcm_poll_descriptors (handle, pfds, count);if (err <0 ) {
audio/audio.c +0 -20
@@ -146,26 +146,6 @@ static inline int audio_bits_to_index (int bits) } } -void *audio_calloc (const char *funcname,int nmemb,size_t size) -{ -int cond; -size_t len; - - len = nmemb * size; - cond = !nmemb || !size; - cond |= nmemb <0 ; - cond |= len < size; - -if (audio_bug ("audio_calloc" , cond)) { -AUD_log (NULL ,"%s passed invalid arguments to audio_calloc\n" , - funcname); -AUD_log (NULL ,"nmemb=%d size=%zu (len=%zu)\n" , nmemb, size, len); -return NULL ; - } - -return g_malloc0 (len); -} -void AUD_vlog (const char *cap,const char *fmt,va_list ap) {if (cap) {
audio/audio_int.h +0 -1
@@ -251,7 +251,6 @@ void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as);void audio_pcm_info_clear_buf (struct audio_pcm_info *info,void *buf,int len);int audio_bug (const char *funcname,int cond); -void *audio_calloc (const char *funcname,int nmemb,size_t size);void audio_run (AudioState *s,const char *msg);
audio/audio_template.h +14 -14
@@ -116,13 +116,20 @@ static int glue (audio_pcm_sw_alloc_resources_, TYPE) (SW *sw) samples = (int64_t )sw->HWBUF->size * sw->ratio >>32 ;#endif - sw->buf =audio_calloc (__func__, samples,sizeof (struct st_sample )); -if (!sw->buf) { -dolog ("Could not allocate buffer for `%s' (%d samples)\n" , +if (audio_bug (__func__, samples <=0 )) { +dolog ("Could not allocate buffer for '%s', samples %d <= 0\n" ,SW_NAME (sw), samples);return -1 ; } +if (audio_bug (__func__, (SIZE_MAX /sizeof (struct st_sample ) < samples))) { +dolog ("Could not allocate buffer for '%s', samples %d overflows\n" , +SW_NAME (sw), samples); +return -1 ; + } + + sw->buf = g_new0(struct st_sample, samples); +#ifdef DAC sw->rate =st_rate_start (sw->info.freq, sw->hw->info.freq);#else
@@ -264,13 +271,12 @@ 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 )); +if (audio_bug (__func__,glue (drv->voice_size_,TYPE ) ==0 )) { +dolog ("Voice size is zero" );return NULL ; } + hw =g_malloc0 (glue (drv->voice_size_,TYPE )); hw->s = s; hw->pcm_ops = drv->pcm_ops;
@@ -398,12 +404,7 @@ static SW *glue(audio_pcm_create_voice_pair_, TYPE)( hw_as = *as; } - sw =audio_calloc (__func__,1 ,sizeof (*sw)); -if (!sw) { -dolog ("Could not allocate soft voice `%s' (%zu bytes)\n" , - sw_name ? sw_name :"unknown" ,sizeof (*sw)); - goto err1; - } + sw =g_new0 (SW ,1 ); sw->s = s; hw =glue (audio_pcm_hw_add_,TYPE )(s, &hw_as);
@@ -424,7 +425,6 @@ err3:glue (audio_pcm_hw_gc_,TYPE ) (&hw); err2:g_free (sw); -err1:return NULL ; }
audio/mixeng.c +1 -6
@@ -414,12 +414,7 @@ struct rate {*/ void *st_rate_start (int inrate,int outrate) { -struct rate *rate =audio_calloc (__func__,1 ,sizeof (*rate)); - -if (!rate) { -dolog ("Could not allocate resampler (%zu bytes)\n" ,sizeof (*rate)); -return NULL ; - } + struct rate *rate = g_new0(struct rate, 1); rate->opos =0 ;
tests/qtest/fuzz-sb16-test.c +4 -2
@@ -10,7 +10,8 @@#include "libqtest.h" /* -* This used to trigger the assert in audio_calloc +* This used to trigger the audio_bug calls in +* audio_pcm_sw_alloc_resources * https://bugs.launchpad.net/qemu/+bug/1910603 */ static void test_fuzz_sb16_0x1c (void )
@@ -38,7 +39,8 @@ static void test_fuzz_sb16_0x91(void) }/* -* This used to trigger the assert in audio_calloc +* This used to trigger the audio_bug calls in +* audio_pcm_sw_alloc_resources * through command 0xd4 */ static void test_fuzz_sb16_0xd4 (void )
Signature · 1 line
2.38.1
PATCH 3/9 audio: remove unused 'name' in QEMUSoundCard struct
In reply to Daniel P. Berrangé--- audio/audio.c | 2 -- audio/audio.h | 1 - 2 files changed, 3 deletions(-)
audio/audio.c +0 -2
@@ -1833,7 +1833,6 @@ void AUD_register_card (const char *name, QEMUSoundCard *card) card->state =audio_init (NULL , name); } - card->name =g_strdup (name);memset (&card->entries,0 ,sizeof (card->entries));QLIST_INSERT_HEAD (&card->state->card_head, card, entries); }
@@ -1841,7 +1840,6 @@ void AUD_register_card (const char *name, QEMUSoundCard *card)void AUD_remove_card (QEMUSoundCard *card) {QLIST_REMOVE (card, entries); -g_free (card->name); }static struct audio_pcm_ops capture_pcm_ops;
audio/audio.h +0 -1
@@ -82,7 +82,6 @@ typedef struct SWVoiceIn SWVoiceIn;typedef struct AudioState AudioState ;typedef struct QEMUSoundCard { -char *name;AudioState *state;QLIST_ENTRY (QEMUSoundCard) entries; }QEMUSoundCard ;
Signature · 1 line
2.38.1
PATCH 4/9 audio: remove QEMUSoundCard linked list
In reply to Daniel P. BerrangéNo code ever iterates over the list
--- audio/audio.c | 5 ----- audio/audio.h | 1 - audio/audio_int.h | 1 - 3 files changed, 7 deletions(-)
audio/audio.c +0 -5
@@ -1812,7 +1812,6 @@ static AudioState *audio_init(Audiodev *dev, const char *name)qemu_add_vm_change_state_handler (audio_vm_change_state_handler, s);QTAILQ_INSERT_TAIL (&audio_states, s, list); -QLIST_INIT (&s->card_head);vmstate_register (NULL ,0 , &vmstate_audio, s);return s; }
@@ -1832,14 +1831,10 @@ void AUD_register_card (const char *name, QEMUSoundCard *card)if (!card->state) { card->state =audio_init (NULL , name); } - -memset (&card->entries,0 ,sizeof (card->entries)); -QLIST_INSERT_HEAD (&card->state->card_head, card, entries); }void AUD_remove_card (QEMUSoundCard *card) { -QLIST_REMOVE (card, entries); }static struct audio_pcm_ops capture_pcm_ops;
audio/audio.h +0 -1
@@ -83,7 +83,6 @@ typedef struct SWVoiceIn SWVoiceIn;typedef struct AudioState AudioState ;typedef struct QEMUSoundCard {AudioState *state; -QLIST_ENTRY (QEMUSoundCard) entries; }QEMUSoundCard ; typedef struct QEMUAudioTimeStamp {
audio/audio_int.h +0 -1
@@ -225,7 +225,6 @@ typedef struct AudioState {void *drv_opaque;QEMUTimer *ts; - QLIST_HEAD (card_listhead, QEMUSoundCard) card_head; QLIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in; QLIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out; QLIST_HEAD (cap_listhead, CaptureVoiceOut) cap_head;
Signature · 1 line
2.38.1
PATCH 8/9 audio: audio state is now mandatory for capture
In reply to Daniel P. BerrangéBoth callers of AUD_add_capture will now ensure that the audio state is non-NULL.
--- audio/audio.c | 7 ------- 1 file changed, 7 deletions(-)
audio/audio.c +0 -7
@@ -1845,13 +1845,6 @@ CaptureVoiceOut *AUD_add_capture(CaptureVoiceOut *cap;struct capture_callback *cb; -if (!s) { -if (!legacy_config) { -dolog ("Capturing without setting an audiodev is deprecated\n" ); - } - s =audio_init (NULL ,NULL ); - } -if (!audio_get_pdo_out (s->dev)->mixing_engine) {dolog ("Can't capture with mixeng disabled\n" );return NULL ;
Signature · 1 line
2.38.1
cover audio: remove deprecated QEMU_AUDIO env support
This removes much of the deprecated audio code, most notably the QEMU_AUDIO env variables. The VNC server will also stop accepting client requests for audio streaming unless an audiodev is set.
I tried to make the use of 'audiodev' mandatory for devices but that turned out to not be practical. Our test suite assumes it can create any device type without setting any properties. This is not possible if 'audiodev' setting is enforced at realize() time. Also there are several machihe boards with embedded soundcards that provide no way to set audiodev AFAICT
Daniel P. Berrangé (9):
audio: don't check qemu_add_vm_change_state_handler failure
audio: remove special audio_calloc function
audio: remove unused 'name' in QEMUSoundCard struct
audio: remove QEMUSoundCard linked list
audio: remove empty AUD_remove_card method
docs: split the deprecation warning for soundcards vs VNC ui/vnc: don't accept VNC_ENCODING_AUDIO without audiodev
audio: audio state is now mandatory for capture
audio: remove support for QEMU_AUDIO_ env variables
audio/alsaaudio.c | 6 +- audio/audio.c | 71 +--- audio/audio.h | 4 - audio/audio_int.h | 2 - audio/audio_legacy.c | 552 -------------------------------- audio/audio_template.h | 28 +- audio/meson.build | 1 - audio/mixeng.c | 7 +- docs/about/deprecated.rst | 16 +- docs/about/removed-features.rst | 14 + hw/audio/ac97.c | 1 - hw/audio/adlib.c | 1 - hw/audio/es1370.c | 1 - hw/audio/gus.c | 1 - hw/audio/hda-codec.c | 1 - hw/audio/wm8750.c | 1 - hw/usb/dev-audio.c | 1 - softmmu/vl.c | 4 - tests/qtest/fuzz-sb16-test.c | 6 +- tests/qtest/libqtest.c | 3 - ui/vnc.c | 10 +- 21 files changed, 53 insertions(+), 678 deletions(-) delete mode 100644 audio/audio_legacy.c
Signature · 1 line
2.38.1
PATCH 9/9 audio: remove support for QEMU_AUDIO_ env variables
All user created devices and the builtin pcspk can be given a audiodev property. A few devices using audiodevs though cannot be configured directly as they are built-in devices created programmatically by the machine type.
To enable those to continue to be used we leave in the logic that picks the first audiodev if none is set explicitly. Ideally this will be removed once there is a way to configure all built-in devices.
Even for devices which can be configured explicitly, though, if the 'audiodev' property is mandated to be set to a valid ID at time of realize(), it will break several of our test suites which expect to be able to instantiate any device without setting any properties.
So as a final fallback, we have logic that creates an audiodev with the 'none' backend type, which will be used in no -audiodev devices are present at all.
--- audio/audio.c | 26 +- audio/audio.h | 1 - audio/audio_legacy.c | 552 -------------------------------- audio/meson.build | 1 - docs/about/deprecated.rst | 8 - docs/about/removed-features.rst | 8 + softmmu/vl.c | 4 - tests/qtest/libqtest.c | 3 - 8 files changed, 14 insertions(+), 589 deletions(-) delete mode 100644 audio/audio_legacy.c
audio/audio.c +6 -20
@@ -108,8 +108,6 @@ const struct mixeng_volume nominal_volume = {#endif }; -static bool legacy_config = true; -int audio_bug (const char *funcname,int cond) {if (cond) {
@@ -1684,7 +1682,7 @@ static AudiodevListEntry *audiodev_find(* if we have dev, this function was called because of an -audiodev argument => * initialize a new state with it * if dev == NULL => legacy implicit initialization, return the already created -* state or create a new one +* state or create a new no-op one. */ static AudioState *audio_init (Audiodev *dev,const char *name) {
@@ -1716,27 +1714,15 @@ static AudioState *audio_init(Audiodev *dev, const char *name)if (dev) {/* -audiodev option */ - legacy_config = false; drvname =AudiodevDriver_str (dev->driver); }else if (!QTAILQ_EMPTY (&audio_states)) { -if (!legacy_config) { -dolog ("Device %s: audiodev default parameter is deprecated, please " -"specify audiodev=%s\n" , name, -QTAILQ_FIRST (&audio_states)->dev->id); - }return QTAILQ_FIRST (&audio_states); }else { -/* legacy implicit initialization */ - head =audio_handle_legacy_opts (); -/* -* In case of legacy initialization, all Audiodevs in the list will have -* the same configuration (except the driver), so it doesn't matter which -* one we chose. We need an Audiodev to set up AudioState before we can -* init a driver. Also note that dev at this point is still in the -* list. -*/ - dev =QSIMPLEQ_FIRST (&head)->dev; -audio_validate_opts (dev, &error_abort); + dev =g_new0 (Audiodev,1 ); + dev->id =g_strdup ("none" ); + dev->driver =AUDIODEV_DRIVER_NONE ; + +audio_create_pdos (dev); } s =g_new0 (AudioState,1 );
audio/audio.h +0 -1
@@ -169,7 +169,6 @@ void audio_define(Audiodev *audio);void audio_parse_option (const char *opt);bool audio_init_audiodevs (void );void audio_help (void ); -void audio_legacy_help (void );AudioState *audio_state_by_name (const char *name);const char *audio_get_id (QEMUSoundCard *card);
audio/audio_legacy.c deleted +0 -552
552 lines not on this page · raw message
audio/meson.build +0 -1
@@ -1,6 +1,5 @@ softmmu_ss.add([spice_headers, files('audio.c')]) softmmu_ss.add(files( - 'audio_legacy.c', 'mixeng.c', 'noaudio.c', 'wavaudio.c',
docs/about/deprecated.rst +0 -8
@@ -23,14 +23,6 @@ deprecated. System emulator command line arguments -------------------------------------- -``QEMU_AUDIO_`` environment variables and ``-audio-help`` (since 4.0) -''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' - -The ``-audiodev`` argument is now the preferred way to specify audio -backend settings instead of environment variables. To ease migration to -the new format, the ``-audiodev-help`` option can be used to convert -the current values of the environment variables to ``-audiodev`` options. - Creating sound card devices without ``audiodev=`` property (since 4.2) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
docs/about/removed-features.rst +8 -0
@@ -428,6 +428,14 @@ Supporting audio transfer over vnc without ``audiodev=`` property (removed in 8. When using vnc, you should specify an ``audiodev=`` property if you intend to allow clients to request audio transfer through the VNC protocol. +``QEMU_AUDIO_`` environment variables and ``-audio-help`` (rwemoved in 8.0) +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +The ``-audiodev`` argument is now the preferred way to specify audio +backend settings instead of environment variables. To ease migration to +the new format, the ``-audiodev-help`` option can be used to convert +the current values of the environment variables to ``-audiodev`` options. + QEMU Machine Protocol (QMP) commands ------------------------------------
softmmu/vl.c +0 -4
@@ -2852,10 +2852,6 @@ void qemu_init(int argc, char **argv) }break ;#endif -case QEMU_OPTION_audio_help: -audio_legacy_help (); -exit (0 ); -break ;case QEMU_OPTION_audiodev:audio_parse_option (optarg);break ;
tests/qtest/libqtest.c +0 -3
@@ -413,9 +413,6 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)*/ prctl (PR_SET_PDEATHSIG ,SIGKILL ,0 ,0 ,0 );#endif /* __linux__ */ -if (!g_setenv ("QEMU_AUDIO_DRV" ,"none" , true)) { -exit (1 ); - }execlp ("/bin/sh" ,"sh" ,"-c" , command,NULL );exit (1 ); }
Signature · 1 line
2.38.1
PATCH 7/9 ui/vnc: don't accept VNC_ENCODING_AUDIO without audiodev
In reply to Daniel P. BerrangéIf we have no audio state configured, then we don't want to advertize the VNC_ENCODING_AUDIO feature. If a client attempts to use it despite being disabled, we should also reject it.
--- docs/about/deprecated.rst | 6 ------ docs/about/removed-features.rst | 6 ++++++ ui/vnc.c | 10 +++++++++- 3 files changed, 15 insertions(+), 7 deletions(-)
docs/about/deprecated.rst +0 -6
@@ -37,12 +37,6 @@ Creating sound card devices without ``audiodev=`` property (since 4.2) When not using the deprecated legacy audio config, each sound card should specify an ``audiodev=`` property. -Supporting audio transfer over vnc without ``audiodev=`` property (since 4.2) -''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' - -When using vnc, you should specify an ``audiodev=`` property if you -intend to allow clients to request audio transfer through the VNC protocol. - Short-form boolean options (since 6.0) ''''''''''''''''''''''''''''''''''''''
docs/about/removed-features.rst +6 -0
@@ -422,6 +422,12 @@ the value is hexadecimal. That is, '0x20M' should be written either as ``tty`` and ``parport`` used to be aliases for ``serial`` and ``parallel`` respectively. The actual backend names should be used instead. +Supporting audio transfer over vnc without ``audiodev=`` property (removed in 8.0) +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +When using vnc, you should specify an ``audiodev=`` property if you +intend to allow clients to request audio transfer through the VNC protocol. + QEMU Machine Protocol (QMP) commands ------------------------------------
ui/vnc.c +9 -1
@@ -2199,7 +2199,9 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)send_ext_key_event_ack (vs);break ;case VNC_ENCODING_AUDIO : -send_ext_audio_ack (vs); +if (vs->vd->audio_state !=NULL ) { +send_ext_audio_ack (vs); + }break ;case VNC_ENCODING_WMVi: vs->features |=VNC_FEATURE_WMVI_MASK ;
@@ -2506,6 +2508,12 @@ static int protocol_client_msg(VncState *vs, uint8_t *data, size_t len) read_u32(data, 4), read_u32(data, 8));break ;case VNC_MSG_CLIENT_QEMU_AUDIO : +if (vs->vd->audio_state ==NULL ) { +error_report ("vnc: QEMU audio client message while disabled" ); +vnc_client_error (vs); +break ; + } +if (len ==2 )return 4 ;
Signature · 1 line
2.38.1
PATCH 5/9 audio: remove empty AUD_remove_card method
In reply to Daniel P. BerrangéSince the linked list of QEMUSoundCard structs was removed, AUD_remove_card does nothing useful.
--- audio/audio.c | 4 ---- audio/audio.h | 1 - hw/audio/ac97.c | 1 - hw/audio/adlib.c | 1 - hw/audio/es1370.c | 1 - hw/audio/gus.c | 1 - hw/audio/hda-codec.c | 1 - hw/audio/wm8750.c | 1 - hw/usb/dev-audio.c | 1 - 9 files changed, 12 deletions(-)
audio/audio.c +0 -4
@@ -1833,10 +1833,6 @@ void AUD_register_card (const char *name, QEMUSoundCard *card) } } -void AUD_remove_card (QEMUSoundCard *card) -{ -} -static struct audio_pcm_ops capture_pcm_ops; CaptureVoiceOut *AUD_add_capture(
audio/audio.h +0 -1
@@ -93,7 +93,6 @@ void AUD_vlog (const char *cap, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0) void AUD_log (const char *cap, const char *fmt, ...) G_GNUC_PRINTF(2, 3);void AUD_register_card (const char *name,QEMUSoundCard *card); -void AUD_remove_card (QEMUSoundCard *card); CaptureVoiceOut *AUD_add_capture( AudioState *s, struct audsettings *as,
hw/audio/ac97.c +0 -1
@@ -1358,7 +1358,6 @@ static void ac97_exit(PCIDevice *dev)AUD_close_in (&s->card, s->voice_pi);AUD_close_out (&s->card, s->voice_po);AUD_close_in (&s->card, s->voice_mc); -AUD_remove_card (&s->card); }static Property ac97_properties[] = {
hw/audio/adlib.c +0 -1
@@ -240,7 +240,6 @@ static void Adlib_fini (AdlibState *s) s->active =0 ; s->enabled =0 ; -AUD_remove_card (&s->card); }static MemoryRegionPortio adlib_portio_list[] = {
hw/audio/es1370.c +0 -1
@@ -882,7 +882,6 @@ static void es1370_exit(PCIDevice *dev) }AUD_close_in (&s->card, s->adc_voice); -AUD_remove_card (&s->card); }static Property es1370_properties[] = {
hw/audio/gus.c +0 -1
@@ -263,7 +263,6 @@ static void gus_realizefn (DeviceState *dev, Error **errp) );if (!s->voice) { -AUD_remove_card (&s->card);error_setg (errp,"No voice" );return ; }
hw/audio/hda-codec.c +0 -1
@@ -743,7 +743,6 @@ static void hda_audio_exit(HDACodecDevice *hda)AUD_close_in (&a->card, st->voice.in); } } -AUD_remove_card (&a->card); }static int hda_audio_post_load (void *opaque,int version)
hw/audio/wm8750.c +0 -1
@@ -634,7 +634,6 @@ static void wm8750_fini(I2CSlave *i2c)WM8750State *s =WM8750 (i2c);wm8750_reset (I2C_SLAVE (s)); -AUD_remove_card (&s->card); g_free(s); }#endif
hw/usb/dev-audio.c +0 -1
@@ -934,7 +934,6 @@ static void usb_audio_unrealize(USBDevice *dev)usb_audio_set_output_altset (s,ALTSET_OFF );AUD_close_out (&s->card, s->out.voice); -AUD_remove_card (&s->card);streambuf_fini (&s->out.buf); }
Signature · 1 line
2.38.1
Re: [PATCH 2/9] audio: remove special audio_calloc function
In reply to Daniel P. BerrangéAm 13.01.23 um 17:21 schrieb Daniel P. Berrangé:
Quoted 13 lines
The
audio_callocfunction does various checks on the size and nmembers parameters to detect various error conditions. There are only 5 callers*
alsa_poll_helper: the pollfd count is small and bounded,
*audio_pcm_create_voice_pair_: allocating a single fixed size struct
*audio_pcm_sw_alloc_resources_: samples could be negative zero, or overflow, so needs a check
*audio_pcm_hw_add_new_: voice size could be zero for backends that don't support audio input
*st_rate_start: allocating a single fixed size struct
Quoted 3 lines
IOW, only two of the callers need special error checks and it is clearer if their respective checks are inlined. Thus
audio_calloccan be eliminated.
Hi Daniel,
my patch series at https://lists.nongnu.org/archive/html/qemu-devel/2022-12/msg02895.html also removes audio_calloc(). There will be merge conflicts.
With best regards,
Volker
Quoted 180 lines
Signed-off-by Daniel P. Berrangé <[email protected]>--- audio/alsaaudio.c | 6 +----- audio/audio.c | 20 -------------------- audio/audio_int.h | 1 - audio/audio_template.h | 28 ++++++++++++++-------------- audio/mixeng.c | 7 +------ tests/qtest/fuzz-sb16-test.c | 6 ++++-- 6 files changed, 20 insertions(+), 48 deletions(-)audio/alsaaudio.c +1
-5@@ -222,11 +222,7 @@ static int alsa_poll_helper (snd_pcm_t *handle, struct pollhlp *hlp, int mask)return -1 ; } - pfds =audio_calloc ("alsa_poll_helper" , count,sizeof (*pfds)); -if (!pfds) { -dolog ("Could not initialize poll mode\n" ); -return -1 ; - } + pfds = g_new0(struct pollfd, count); err =snd_pcm_poll_descriptors (handle, pfds, count);if (err <0 ) {audio/audio.c +0
-20@@ -146,26 +146,6 @@ static inline int audio_bits_to_index (int bits) } } -void *audio_calloc (const char *funcname,int nmemb,size_t size) -{ -int cond; -size_t len; - - len = nmemb * size; - cond = !nmemb || !size; - cond |= nmemb <0 ; - cond |= len < size; - -if (audio_bug ("audio_calloc" , cond)) { -AUD_log (NULL ,"%s passed invalid arguments to audio_calloc\n" , - funcname); -AUD_log (NULL ,"nmemb=%d size=%zu (len=%zu)\n" , nmemb, size, len); -return NULL ; - } - -return g_malloc0 (len); -} -void AUD_vlog (const char *cap,const char *fmt,va_list ap) {if (cap) {audio/audio_int.h +0
-1@@ -251,7 +251,6 @@ void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as);void audio_pcm_info_clear_buf (struct audio_pcm_info *info,void *buf,int len);int audio_bug (const char *funcname,int cond); -void *audio_calloc (const char *funcname,int nmemb,size_t size);void audio_run (AudioState *s,const char *msg);audio/audio_template.h +14
-14@@ -116,13 +116,20 @@ static int glue (audio_pcm_sw_alloc_resources_, TYPE) (SW *sw) samples = (int64_t )sw->HWBUF->size * sw->ratio >>32 ;#endif - sw->buf =audio_calloc (__func__, samples,sizeof (struct st_sample )); -if (!sw->buf) { -dolog ("Could not allocate buffer for `%s' (%d samples)\n" , +if (audio_bug (__func__, samples <=0 )) { +dolog ("Could not allocate buffer for '%s', samples %d <= 0\n" ,SW_NAME (sw), samples);return -1 ; } +if (audio_bug (__func__, (SIZE_MAX /sizeof (struct st_sample ) < samples))) { +dolog ("Could not allocate buffer for '%s', samples %d overflows\n" , +SW_NAME (sw), samples); +return -1 ; + } + + sw->buf = g_new0(struct st_sample, samples); +#ifdef DAC sw->rate =st_rate_start (sw->info.freq, sw->hw->info.freq);#else @@ -264,13 +271,12 @@ 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 )); +if (audio_bug (__func__,glue (drv->voice_size_,TYPE ) ==0 )) { +dolog ("Voice size is zero" );return NULL ; } + hw =g_malloc0 (glue (drv->voice_size_,TYPE )); hw->s = s; hw->pcm_ops = drv->pcm_ops;@@ -398,12 +404,7 @@ static SW *glue(audio_pcm_create_voice_pair_, TYPE)( hw_as = *as; } - sw =audio_calloc (__func__,1 ,sizeof (*sw)); -if (!sw) { -dolog ("Could not allocate soft voice `%s' (%zu bytes)\n" , - sw_name ? sw_name :"unknown" ,sizeof (*sw)); - goto err1; - } + sw =g_new0 (SW ,1 ); sw->s = s; hw =glue (audio_pcm_hw_add_,TYPE )(s, &hw_as);@@ -424,7 +425,6 @@ err3:glue (audio_pcm_hw_gc_,TYPE ) (&hw); err2:g_free (sw); -err1:return NULL ; }audio/mixeng.c +1
-6@@ -414,12 +414,7 @@ struct rate {*/ void *st_rate_start (int inrate,int outrate) { -struct rate *rate =audio_calloc (__func__,1 ,sizeof (*rate)); - -if (!rate) { -dolog ("Could not allocate resampler (%zu bytes)\n" ,sizeof (*rate)); -return NULL ; - } + struct rate *rate = g_new0(struct rate, 1); rate->opos =0 ;tests/qtest/fuzz-sb16-test.c +4
-2@@ -10,7 +10,8 @@#include "libqtest.h" /* -* This used to trigger the assert in audio_calloc +* This used to trigger the audio_bug calls in +* audio_pcm_sw_alloc_resources * https://bugs.launchpad.net/qemu/+bug/1910603 */ static void test_fuzz_sb16_0x1c (void )@@ -38,7 +39,8 @@ static void test_fuzz_sb16_0x91(void) }/* -* This used to trigger the assert in audio_calloc +* This used to trigger the audio_bug calls in +* audio_pcm_sw_alloc_resources * through command 0xd4 */ static void test_fuzz_sb16_0xd4 (void )
Re: [PATCH 1/9] audio: don't check qemu_add_vm_change_state_handler failure
In reply to Daniel P. BerrangéAm 13.01.23 um 17:21 schrieb Daniel P. Berrangé:
Quoted 20 lines
This function cannot fail since
g_malloc0aborts on OOM.Signed-off-by Daniel P. Berrangé <[email protected]>--- audio/audio.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)audio/audio.c +0
-1@@ -1712,7 +1712,6 @@ static AudioState *audio_init(Audiodev *dev, const char *name)size_t i;int done =0 ;const char *drvname =NULL ; -VMChangeStateEntry *e;AudioState *s;struct audio_driver *driver;/* silence gcc warning about uninitialized variable */
audio/audio.c static AudioState *audio_init(Audiodev *dev, const char *name) · line 1832
Quoted 9 lines
audio/audio.c +1
-5@@ -1830,11 +1829,7 @@ static AudioState *audio_init(Audiodev *dev, const char *name) s->period_ticks = dev->timer_period * (int64_t )SCALE_US ; } - e =qemu_add_vm_change_state_handler (audio_vm_change_state_handler, s); -if (!e) { -dolog ("warning: Could not register change state handler\n" -"(Audio can continue looping even after stopping the VM)\n" ); - } +qemu_add_vm_change_state_handler (audio_vm_change_state_handler, s);
checkpatch.pl doesn't work properly here. It should report:
ERROR: space prohibited between function name and open parenthesis '('
With this changed,
Quoted 3 lines
audio/audio.c +0
-0QTAILQ_INSERT_TAIL (&audio_states, s, list);QLIST_INIT (&s->card_head);
Re: [PATCH 2/9] audio: remove special audio_calloc function
In reply to Volker RümelinQuoted 18 lines · Volker Rümelin
Am 13.01.23 um 17:21 schrieb Daniel P. Berrangé:
Quoted 13 lines
The
audio_callocfunction does various checks on the size and nmembers parameters to detect various error conditions. There are only 5 callers*
alsa_poll_helper: the pollfd count is small and bounded,
*audio_pcm_create_voice_pair_: allocating a single fixed size struct
*audio_pcm_sw_alloc_resources_: samples could be negative zero, or overflow, so needs a check
*audio_pcm_hw_add_new_: voice size could be zero for backends that don't support audio input
*st_rate_start: allocating a single fixed size structQuoted 3 lines
IOW, only two of the callers need special error checks and it is clearer if their respective checks are inlined. Thus
audio_calloccan be eliminated.
Quoted 5 lines
Hi Daniel,
my patch series at
https://lists.nongnu.org/archive/html/qemu-devel/2022-12/msg02895.html also removesaudio_calloc(). There will be merge conflicts.
Ah, yes, sorry I missed that. I've sent a few comments on your impl. Consider this patch dropped.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|