From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: balaton@eik.bme.hu
Subject: [PATCH 04/13] audio: return Error ** from audio_state_by_name
Date: Mon, 2 Oct 2023 16:57:18 +0200 [thread overview]
Message-ID: <20231002145728.87958-5-pbonzini@redhat.com> (raw)
In-Reply-To: <20231002145728.87958-1-pbonzini@redhat.com>
Remove duplicate error formatting code.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
audio/audio-hmp-cmds.c | 6 ++++--
audio/audio.c | 3 ++-
audio/audio.h | 2 +-
hw/core/qdev-properties-system.c | 16 ++++------------
ui/dbus.c | 3 +--
ui/vnc.c | 3 +--
6 files changed, 13 insertions(+), 20 deletions(-)
diff --git a/audio/audio-hmp-cmds.c b/audio/audio-hmp-cmds.c
index 1237ce9e750..c9608b715b8 100644
--- a/audio/audio-hmp-cmds.c
+++ b/audio/audio-hmp-cmds.c
@@ -26,6 +26,7 @@
#include "audio/audio.h"
#include "monitor/hmp.h"
#include "monitor/monitor.h"
+#include "qapi/error.h"
#include "qapi/qmp/qdict.h"
static QLIST_HEAD (capture_list_head, CaptureState) capture_head;
@@ -65,10 +66,11 @@ void hmp_wavcapture(Monitor *mon, const QDict *qdict)
int nchannels = qdict_get_try_int(qdict, "nchannels", 2);
const char *audiodev = qdict_get_str(qdict, "audiodev");
CaptureState *s;
- AudioState *as = audio_state_by_name(audiodev);
+ Error *local_err = NULL;
+ AudioState *as = audio_state_by_name(audiodev, &local_err);
if (!as) {
- monitor_printf(mon, "Audiodev '%s' not found\n", audiodev);
+ error_report_err(local_err);
return;
}
diff --git a/audio/audio.c b/audio/audio.c
index fdc34a77520..874a4c3c412 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -2260,7 +2260,7 @@ int audio_buffer_bytes(AudiodevPerDirectionOptions *pdo,
audioformat_bytes_per_sample(as->fmt);
}
-AudioState *audio_state_by_name(const char *name)
+AudioState *audio_state_by_name(const char *name, Error **errp)
{
AudioState *s;
QTAILQ_FOREACH(s, &audio_states, list) {
@@ -2269,6 +2269,7 @@ AudioState *audio_state_by_name(const char *name)
return s;
}
}
+ error_setg(errp, "audiodev '%s' not found", name);
return NULL;
}
diff --git a/audio/audio.h b/audio/audio.h
index 01bdc567fb1..e0c13b5dcdf 100644
--- a/audio/audio.h
+++ b/audio/audio.h
@@ -174,7 +174,7 @@ bool audio_init_audiodevs(void);
void audio_help(void);
void audio_legacy_help(void);
-AudioState *audio_state_by_name(const char *name);
+AudioState *audio_state_by_name(const char *name, Error **errp);
const char *audio_get_id(QEMUSoundCard *card);
#define DEFINE_AUDIO_PROPERTIES(_s, _f) \
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 41b7e682c78..688340610ec 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -480,24 +480,16 @@ static void set_audiodev(Object *obj, Visitor *v, const char* name,
Property *prop = opaque;
QEMUSoundCard *card = object_field_prop_ptr(obj, prop);
AudioState *state;
- int err = 0;
- char *str;
+ g_autofree char *str = NULL;
if (!visit_type_str(v, name, &str, errp)) {
return;
}
- state = audio_state_by_name(str);
-
- if (!state) {
- err = -ENOENT;
- goto out;
+ state = audio_state_by_name(str, errp);
+ if (state) {
+ card->state = state;
}
- card->state = state;
-
-out:
- error_set_from_qdev_prop_error(errp, err, obj, name, str);
- g_free(str);
}
const PropertyInfo qdev_prop_audiodev = {
diff --git a/ui/dbus.c b/ui/dbus.c
index 32f1bbe81ae..866467ad2e3 100644
--- a/ui/dbus.c
+++ b/ui/dbus.c
@@ -220,9 +220,8 @@ dbus_display_complete(UserCreatable *uc, Error **errp)
}
if (dd->audiodev && *dd->audiodev) {
- AudioState *audio_state = audio_state_by_name(dd->audiodev);
+ AudioState *audio_state = audio_state_by_name(dd->audiodev, errp);
if (!audio_state) {
- error_setg(errp, "Audiodev '%s' not found", dd->audiodev);
return;
}
if (!g_str_equal(audio_state->drv->name, "dbus")) {
diff --git a/ui/vnc.c b/ui/vnc.c
index acb56461b2d..82929469130 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -4181,9 +4181,8 @@ void vnc_display_open(const char *id, Error **errp)
audiodev = qemu_opt_get(opts, "audiodev");
if (audiodev) {
- vd->audio_state = audio_state_by_name(audiodev);
+ vd->audio_state = audio_state_by_name(audiodev, errp);
if (!vd->audio_state) {
- error_setg(errp, "Audiodev '%s' not found", audiodev);
goto fail;
}
}
--
2.41.0
next prev parent reply other threads:[~2023-10-02 14:58 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-02 14:57 [PATCH v4 00/13] Cleanup deprecated audio features, take 2 Paolo Bonzini
2023-10-02 14:57 ` [PATCH 01/13] ui/vnc: Require audiodev= to enable audio Paolo Bonzini
2023-10-02 14:57 ` [PATCH 02/13] audio: Require AudioState in AUD_add_capture Paolo Bonzini
2023-10-02 14:57 ` [PATCH 03/13] audio: allow returning an error from the driver init Paolo Bonzini
2023-10-02 14:57 ` Paolo Bonzini [this message]
2023-10-02 14:57 ` [PATCH 05/13] audio: commonize voice initialization Paolo Bonzini
2023-10-02 14:57 ` [PATCH 06/13] audio: simplify flow in audio_init Paolo Bonzini
2023-10-02 14:57 ` [PATCH 07/13] audio: remove QEMU_AUDIO_* and -audio-help support Paolo Bonzini
2023-10-02 14:57 ` [PATCH 08/13] Introduce machine property "audiodev" Paolo Bonzini
2023-10-02 14:57 ` [PATCH 09/13] hw/arm: Support machine-default audiodev with fallback Paolo Bonzini
2023-10-02 14:57 ` [PATCH 10/13] hw/ppc: " Paolo Bonzini
2023-10-02 14:57 ` [PATCH 11/13] vt82c686 machines: " Paolo Bonzini
2023-10-02 14:57 ` [PATCH 12/13] audio: propagate Error * out of audio_init Paolo Bonzini
2023-10-02 14:57 ` [PATCH 13/13] audio: forbid default audiodev backend with -nodefaults Paolo Bonzini
-- strict thread matches above, loose matches on Subject: below --
2023-09-28 7:36 [PATCH v2 00/13] Cleanup deprecated audio features, take 2 Paolo Bonzini
2023-09-28 7:36 ` [PATCH 04/13] audio: return Error ** from audio_state_by_name Paolo Bonzini
2023-09-23 8:54 [PATCH 00/13] Cleanup deprecated audio features, take 2 Paolo Bonzini
2023-09-23 8:54 ` [PATCH 04/13] audio: return Error ** from audio_state_by_name Paolo Bonzini
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=20231002145728.87958-5-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=balaton@eik.bme.hu \
--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).