[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/2] Add warn_unused_result attr to AUD_register_card
From: |
Manos Pitsidianakis |
Subject: |
[PATCH 2/2] Add warn_unused_result attr to AUD_register_card |
Date: |
Fri, 10 Nov 2023 11:16:39 +0200 |
Ignoring the return value by accident is easy to miss as a bug. Such a
bug was spotted by Coverity CID 1523899. Now, future instances of this
type of bug will produce a warning when using GCC.
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
---
audio/audio.h | 2 +-
hw/arm/omap2.c | 8 +++++++-
hw/input/tsc210x.c | 8 +++++++-
3 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/audio/audio.h b/audio/audio.h
index fcc22307be..b78c75962e 100644
--- a/audio/audio.h
+++ b/audio/audio.h
@@ -94,7 +94,7 @@ typedef struct QEMUAudioTimeStamp {
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);
-bool AUD_register_card (const char *name, QEMUSoundCard *card, Error **errp);
+bool AUD_register_card (const char *name, QEMUSoundCard *card, Error **errp)
QEMU_WARN_UNUSED_RESULT;
void AUD_remove_card (QEMUSoundCard *card);
CaptureVoiceOut *AUD_add_capture(
AudioState *s,
diff --git a/hw/arm/omap2.c b/hw/arm/omap2.c
index f170728e7e..59fc061120 100644
--- a/hw/arm/omap2.c
+++ b/hw/arm/omap2.c
@@ -614,7 +614,13 @@ static struct omap_eac_s *omap_eac_init(struct
omap_target_agent_s *ta,
s->codec.card.name = g_strdup(current_machine->audiodev);
s->codec.card.state = audio_state_by_name(s->codec.card.name,
&error_fatal);
}
- AUD_register_card("OMAP EAC", &s->codec.card, &error_fatal);
+ /*
+ * We pass error_fatal so on error QEMU will exit(). But we check the
+ * return value to make the warn_unused_result compiler warning go away.
+ */
+ if (!AUD_register_card("OMAP EAC", &s->codec.card, &error_fatal)) {
+ exit(1);
+ }
memory_region_init_io(&s->iomem, NULL, &omap_eac_ops, s, "omap.eac",
omap_l4_region_size(ta, 0));
diff --git a/hw/input/tsc210x.c b/hw/input/tsc210x.c
index 950506fb38..003c664b56 100644
--- a/hw/input/tsc210x.c
+++ b/hw/input/tsc210x.c
@@ -1102,7 +1102,13 @@ static void tsc210x_init(TSC210xState *s,
s->card.name = g_strdup(current_machine->audiodev);
s->card.state = audio_state_by_name(s->card.name, &error_fatal);
}
- AUD_register_card(s->name, &s->card, &error_fatal);
+ /*
+ * We pass error_fatal so on error QEMU will exit(). But we check the
+ * return value to make the warn_unused_result compiler warning go away.
+ */
+ if (!AUD_register_card(s->name, &s->card, &error_fatal)) {
+ return;
+ }
qemu_register_reset((void *) tsc210x_reset, s);
vmstate_register(NULL, 0, vmsd, s);
--
2.39.2
- [PATCH 2/2] Add warn_unused_result attr to AUD_register_card,
Manos Pitsidianakis <=
- Re: [PATCH 2/2] Add warn_unused_result attr to AUD_register_card, Peter Maydell, 2023/11/10
- Re: [PATCH 2/2] Add warn_unused_result attr to AUD_register_card, Daniel P . Berrangé, 2023/11/10
- Re: [PATCH 2/2] Add warn_unused_result attr to AUD_register_card, Manos Pitsidianakis, 2023/11/10
- Re: [PATCH 2/2] Add warn_unused_result attr to AUD_register_card, BALATON Zoltan, 2023/11/10
- Re: [PATCH 2/2] Add warn_unused_result attr to AUD_register_card, Daniel P . Berrangé, 2023/11/10
- Re: [PATCH 2/2] Add warn_unused_result attr to AUD_register_card, Philippe Mathieu-Daudé, 2023/11/10