From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: berrange@redhat.com, balaton@eik.bme.hu
Subject: [PATCH v3 14/14] audio: propagate Error out of audio_driver_init
Date: Fri, 29 Sep 2023 10:51:07 +0200 [thread overview]
Message-ID: <20230929085112.983957-15-pbonzini@redhat.com> (raw)
In-Reply-To: <20230929085112.983957-1-pbonzini@redhat.com>
Now that all the callers of audio_init can report failure, pass the Error
from audio_driver_init to audio_init instead of reporting it directly
in audio_driver_init. This eliminates more complex logic that calls
error_report_err and error_init, replacing it with just &error_fatal
(when creating command line audiodevs) and error propagation
(when creating default audiodevs from AUD_register_card).
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
audio/audio.c | 31 ++++++++++++++-----------------
audio/audio.h | 2 +-
softmmu/vl.c | 4 +---
3 files changed, 16 insertions(+), 21 deletions(-)
diff --git a/audio/audio.c b/audio/audio.c
index 7cfcbfb6ef1..380da72a7b0 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1556,7 +1556,7 @@ size_t audio_generic_read(HWVoiceIn *hw, void *buf, size_t size)
}
static int audio_driver_init(AudioState *s, struct audio_driver *drv,
- bool msg, Audiodev *dev)
+ Audiodev *dev, Error **errp)
{
Error *local_err = NULL;
@@ -1577,12 +1577,10 @@ static int audio_driver_init(AudioState *s, struct audio_driver *drv,
s->drv = drv;
return 0;
} else {
- if (!msg) {
- error_free(local_err);
- } else if (local_err) {
- error_report_err(local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
} else {
- error_report("Could not init `%s' audio driver", drv->name);
+ error_setg(errp, "Could not init `%s' audio driver", drv->name);
}
return -1;
}
@@ -1733,7 +1731,7 @@ static void audio_create_default_audiodevs(void)
* if dev == NULL => legacy implicit initialization, return the already created
* state or create a new one
*/
-static AudioState *audio_init(Audiodev *dev)
+static AudioState *audio_init(Audiodev *dev, Error **errp)
{
static bool atexit_registered;
int done = 0;
@@ -1760,9 +1758,9 @@ static AudioState *audio_init(Audiodev *dev)
drvname = AudiodevDriver_str(dev->driver);
driver = audio_driver_lookup(drvname);
if (driver) {
- done = !audio_driver_init(s, driver, true, dev);
+ done = !audio_driver_init(s, driver, dev, errp);
} else {
- dolog ("Unknown audio driver `%s'\n", drvname);
+ error_setg(errp, "Unknown audio driver `%s'\n", drvname);
}
if (!done) {
free_audio_state(s);
@@ -1778,7 +1776,7 @@ static AudioState *audio_init(Audiodev *dev)
s->dev = dev = e->dev;
drvname = AudiodevDriver_str(dev->driver);
driver = audio_driver_lookup(drvname);
- if (!audio_driver_init(s, driver, false, dev)) {
+ if (!audio_driver_init(s, driver, dev, NULL)) {
break;
}
QSIMPLEQ_REMOVE_HEAD(&default_audiodevs, next);
@@ -1821,7 +1819,10 @@ bool AUD_register_card (const char *name, QEMUSoundCard *card, Error **errp)
if (QSIMPLEQ_EMPTY(&default_audiodevs)) {
audio_create_default_audiodevs();
}
- card->state = audio_init(NULL);
+ card->state = audio_init(NULL, errp);
+ if (!card->state) {
+ return false;
+ }
}
}
@@ -2157,17 +2158,13 @@ void audio_define(Audiodev *dev)
QSIMPLEQ_INSERT_TAIL(&audiodevs, e, next);
}
-bool audio_init_audiodevs(void)
+void audio_init_audiodevs(void)
{
AudiodevListEntry *e;
QSIMPLEQ_FOREACH(e, &audiodevs, next) {
- if (!audio_init(e->dev)) {
- return false;
- }
+ audio_init(e->dev, &error_fatal);
}
-
- return true;
}
audsettings audiodev_to_audsettings(AudiodevPerDirectionOptions *pdo)
diff --git a/audio/audio.h b/audio/audio.h
index 70b264d897d..80f3f92124d 100644
--- a/audio/audio.h
+++ b/audio/audio.h
@@ -170,7 +170,7 @@ void audio_sample_from_uint64(void *samples, int pos,
void audio_define(Audiodev *audio);
void audio_parse_option(const char *opt);
-bool audio_init_audiodevs(void);
+void audio_init_audiodevs(void);
void audio_help(void);
AudioState *audio_state_by_name(const char *name, Error **errp);
diff --git a/softmmu/vl.c b/softmmu/vl.c
index cafb1a98427..98e071e63bb 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -1962,9 +1962,7 @@ static void qemu_create_early_backends(void)
* setting machine properties, so they can be referred to.
*/
configure_blockdev(&bdo_queue, machine_class, snapshot);
- if (!audio_init_audiodevs()) {
- exit(1);
- }
+ audio_init_audiodevs();
}
--
2.41.0
prev parent reply other threads:[~2023-09-29 8:56 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-29 8:50 [PATCH v3 00/14] Cleanup deprecated audio features, take 2 Paolo Bonzini
2023-09-29 8:50 ` [PATCH v3 01/14] ui/vnc: Require audiodev= to enable audio Paolo Bonzini
2023-09-29 8:50 ` [PATCH v3 02/14] audio: Require AudioState in AUD_add_capture Paolo Bonzini
2023-09-29 11:36 ` BALATON Zoltan
2023-09-29 8:50 ` [PATCH v3 03/14] audio: allow returning an error from the driver init Paolo Bonzini
2023-09-29 8:50 ` [PATCH v3 04/14] audio: return Error ** from audio_state_by_name Paolo Bonzini
2023-09-29 8:50 ` [PATCH v3 05/14] audio: commonize voice initialization Paolo Bonzini
2023-09-29 8:50 ` [PATCH v3 06/14] audio: simplify flow in audio_init Paolo Bonzini
2023-09-29 8:51 ` [PATCH v3 07/14] audio: remove QEMU_AUDIO_* and -audio-help support Paolo Bonzini
2023-09-29 8:51 ` [PATCH v3 08/14] Introduce machine property "audiodev" Paolo Bonzini
2023-10-03 23:36 ` Bernhard Beschow
2023-09-29 8:51 ` [PATCH v3 09/14] hw/arm: Support machine-default audiodev with fallback Paolo Bonzini
2023-09-29 8:51 ` [PATCH v3 10/14] hw/ppc: " Paolo Bonzini
2023-09-29 8:51 ` [PATCH v3 11/14] vt82c686: " Paolo Bonzini
2023-09-29 11:46 ` BALATON Zoltan
2023-09-29 8:51 ` [PATCH v3 12/14] audio: forbid mixing default audiodev backend and -audiodev Paolo Bonzini
2023-09-29 11:54 ` BALATON Zoltan
2023-09-29 16:37 ` Paolo Bonzini
2023-09-29 8:51 ` [PATCH v3 13/14] audio: forbid default audiodev backend with -nodefaults Paolo Bonzini
2023-09-29 8:51 ` Paolo Bonzini [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230929085112.983957-15-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=balaton@eik.bme.hu \
--cc=berrange@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).