From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
qemu-arm@nongnu.org (open list:OMAP)
Subject: [PATCH 2/2] Add warn_unused_result attr to AUD_register_card
Date: Fri, 10 Nov 2023 11:16:39 +0200 [thread overview]
Message-ID: <4b040fc18cb0e563e92ce084ca18b89a050a8aaa.1699606819.git.manos.pitsidianakis@linaro.org> (raw)
In-Reply-To: <cover.1699606819.git.manos.pitsidianakis@linaro.org>
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
next prev parent reply other threads:[~2023-11-10 9:17 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-10 9:16 [PATCH 0/2] Add QEMU_WARN_UNUSED_RESULT function attribute Manos Pitsidianakis
2023-11-10 9:16 ` [PATCH 1/2] Add QEMU_WARN_UNUSED_RESULT attribute Manos Pitsidianakis
2023-11-10 9:24 ` Daniel P. Berrangé
2023-11-10 11:15 ` Philippe Mathieu-Daudé
2023-11-10 9:16 ` Manos Pitsidianakis [this message]
2023-11-10 10:21 ` [PATCH 2/2] Add warn_unused_result attr to AUD_register_card Peter Maydell
2023-11-10 10:44 ` Manos Pitsidianakis
2023-11-10 11:18 ` Peter Maydell
2023-11-10 11:23 ` Daniel P. Berrangé
2023-11-10 11:28 ` Manos Pitsidianakis
2023-11-10 11:20 ` Daniel P. Berrangé
2023-11-10 11:25 ` Manos Pitsidianakis
2023-11-10 11:35 ` BALATON Zoltan
2023-11-10 11:43 ` Daniel P. Berrangé
2023-11-10 13:04 ` Philippe Mathieu-Daudé
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=4b040fc18cb0e563e92ce084ca18b89a050a8aaa.1699606819.git.manos.pitsidianakis@linaro.org \
--to=manos.pitsidianakis@linaro.org \
--cc=kraxel@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--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).