From nobody Tue Feb 10 11:16:06 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1769538813; cv=none; d=zohomail.com; s=zohoarc; b=CQzcioVJjv/pk8KmTXv519LtOekH/AuPMRS/FkUYBjZmCKHG+apchwGXf3OtOAw5uZ+U1SI4KV7blJN8L8Xeu8hozJJvDeiM1mgveAWrJ87xAtmHw8YbAq2u0Huv6E9Uzsixr+2Idf92nPleSa5df+HIoVgeHt/gESgILcTipdk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769538813; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+uJXgzbYwnd2Ft9E/FZODhsTxW5YrI2UjjBzGSgxpz8=; b=l//0S7kG/OejeylgBKTldhImwWzb/WNMjdxQVbjncIW1ceIiliNNQnrnBotXru0RZEHPR6gJKfJCV66Ol0lDUw95/9BaiGxa+AZQqJpbwBw1iBGOoqM4l9oroyhj9rNacdafg60aZ4YlN4LSdmshmzflz7evYspXY+d5BKzfgEo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769538813711172.78187309750479; Tue, 27 Jan 2026 10:33:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vknrL-0001A0-NU; Tue, 27 Jan 2026 13:32:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vknot-0002IF-5I for qemu-devel@nongnu.org; Tue, 27 Jan 2026 13:29:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vknoo-0003na-Ty for qemu-devel@nongnu.org; Tue, 27 Jan 2026 13:29:42 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-338-LBPM0o0dMWKpz6qtqT5iUQ-1; Tue, 27 Jan 2026 13:29:36 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8755D18E6DA1; Tue, 27 Jan 2026 18:29:22 +0000 (UTC) Received: from localhost (unknown [10.45.242.23]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0F2C830001A2; Tue, 27 Jan 2026 18:29:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769538578; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+uJXgzbYwnd2Ft9E/FZODhsTxW5YrI2UjjBzGSgxpz8=; b=IEhMe6dLXrMoPPpoVD20g34O/l8JmI1NNx7+D0chs6BAsRXejR6oSVaSZpZoxkBDuy4hXI rXd+LsGvVqSLWHrka5cM7MK8TbMc9XKr1UiiA70V4rxWvTgMoKEJyKcFMY0RBk9c4tm+Sl LBaK0HObi3XaP2WRzVtXSV/T9nFjbXY= X-MC-Unique: LBPM0o0dMWKpz6qtqT5iUQ-1 X-Mimecast-MFC-AGG-ID: LBPM0o0dMWKpz6qtqT5iUQ_1769538575 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH 40/43] audio: rework audio_bug() Date: Tue, 27 Jan 2026 22:25:07 +0400 Message-ID: <20260127182516.289834-41-marcandre.lureau@redhat.com> In-Reply-To: <20260127182516.289834-1-marcandre.lureau@redhat.com> References: <20260127182516.289834-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1769538815502158500 From: Marc-Andr=C3=A9 Lureau audio_bug() is a bit unconventional, it is meant to be used as a condition expression, passing the actual condition as second argument (and __func__ as first argument). If the condition is true, it uses AUD_log() to print to stderr, and has some dubious recommendations printed only once. This change: - clears the control flow, and make the condition directly visible in the 'if' statement. - uses standard QEMU error_report() - audio_bug() now captures __func__ - remove the "Save all your work and restart..." once hint Signed-off-by: Marc-Andr=C3=A9 Lureau --- audio/audio_int.h | 2 -- audio/audio_template.h | 38 +++++++++++------------ audio/audio-mixeng-be.c | 69 ++++++++++++++++------------------------- 3 files changed, 46 insertions(+), 63 deletions(-) diff --git a/audio/audio_int.h b/audio/audio_int.h index e0ed6af67ed..20ec7883aab 100644 --- a/audio/audio_int.h +++ b/audio/audio_int.h @@ -244,8 +244,6 @@ extern const char *audio_prio_list[]; void audio_pcm_init_info (struct audio_pcm_info *info, const struct audset= tings *as); void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int= len); =20 -int audio_bug (const char *funcname, int cond); - void audio_run(AudioMixengBackend *s, const char *msg); =20 typedef struct RateCtl { diff --git a/audio/audio_template.h b/audio/audio_template.h index 5711f4a26e1..9dde36738bc 100644 --- a/audio/audio_template.h +++ b/audio/audio_template.h @@ -64,15 +64,15 @@ static void glue(audio_init_nb_voices_, TYPE)(AudioMixe= ngBackend *s, min_voices); } =20 - if (audio_bug(__func__, !voice_size && max_voices)) { - dolog("drv=3D`%s' voice_size=3D0 max_voices=3D%d\n", - k->name, max_voices); + if (!voice_size && max_voices) { + audio_bug("drv=3D`%s' voice_size=3D0 max_voices=3D%d", + k->name, max_voices); glue(s->nb_hw_voices_, TYPE) =3D 0; } =20 - if (audio_bug(__func__, voice_size && !max_voices)) { - dolog("drv=3D`%s' voice_size=3D%zu max_voices=3D0\n", - k->name, voice_size); + if (voice_size && !max_voices) { + audio_bug("drv=3D`%s' voice_size=3D%zu max_voices=3D0", + k->name, voice_size); } } =20 @@ -88,8 +88,8 @@ static void glue(audio_pcm_hw_alloc_resources_, TYPE)(HW = *hw) { if (glue(audio_get_pdo_, TYPE)(hw->s->dev)->mixing_engine) { size_t samples =3D hw->samples; - if (audio_bug(__func__, samples =3D=3D 0)) { - dolog("Attempted to allocate empty buffer\n"); + if (samples =3D=3D 0) { + audio_bug("Attempted to allocate empty buffer"); } =20 HWBUF.buffer =3D g_new0(st_sample, samples); @@ -275,8 +275,8 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioMixen= gBackend *s, return NULL; } =20 - if (audio_bug(__func__, !glue(k->init_, TYPE))) { - dolog("No host audio driver or missing init_%s\n", NAME); + if (!glue(k->init_, TYPE)) { + audio_bug("No host audio driver or missing init_%s", NAME); return NULL; } =20 @@ -295,8 +295,8 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioMixen= gBackend *s, goto err0; } =20 - if (audio_bug(__func__, hw->samples <=3D 0)) { - dolog("hw->samples=3D%zd\n", hw->samples); + if (hw->samples <=3D 0) { + audio_bug("hw->samples=3D%zd", hw->samples); goto err1; } =20 @@ -477,8 +477,8 @@ static void glue (audio_close_, TYPE) (SW *sw) static void glue(audio_mixeng_backend_close_, TYPE)(AudioBackend *be, SW *= sw) { if (sw) { - if (audio_bug(__func__, !be)) { - dolog("backend=3D%p\n", be); + if (!be) { + audio_bug("backend=3D%p", be); return; } =20 @@ -498,9 +498,9 @@ static SW *glue(audio_mixeng_backend_open_, TYPE) ( AudioMixengBackendClass *k; AudiodevPerDirectionOptions *pdo; =20 - if (audio_bug(__func__, !be || !name || !callback_fn || !as)) { - dolog("backend=3D%p name=3D%p callback_fn=3D%p as=3D%p\n", - be, name, callback_fn, as); + if (!be || !name || !callback_fn || !as) { + audio_bug("backend=3D%p name=3D%p callback_fn=3D%p as=3D%p", + be, name, callback_fn, as); goto fail; } =20 @@ -519,8 +519,8 @@ static SW *glue(audio_mixeng_backend_open_, TYPE) ( goto fail; } =20 - if (audio_bug(__func__, !glue(k->init_, TYPE))) { - dolog("Can not open `%s' (no host audio driver)\n", name); + if (!glue(k->init_, TYPE)) { + error_report("audio: Can not open `%s' (no host audio driver)", na= me); goto fail; } =20 diff --git a/audio/audio-mixeng-be.c b/audio/audio-mixeng-be.c index e8fae2ab977..4988627279e 100644 --- a/audio/audio-mixeng-be.c +++ b/audio/audio-mixeng-be.c @@ -31,6 +31,8 @@ =20 #define SW_NAME(sw) (sw)->name ? (sw)->name : "unknown" =20 +#define audio_bug(fmt, ...) error_report("%s: " fmt, __func__, ##__VA_ARGS= __) + const struct mixeng_volume nominal_volume =3D { .mute =3D 0, #ifdef FLOAT_MIXENG @@ -42,23 +44,6 @@ const struct mixeng_volume nominal_volume =3D { #endif }; =20 -int audio_bug (const char *funcname, int cond) -{ - if (cond) { - static int shown; - - AUD_log (NULL, "A bug was just triggered in %s\n", funcname); - if (!shown) { - shown =3D 1; - AUD_log (NULL, "Save all your work and restart without audio\n= "); - AUD_log (NULL, "I am sorry\n"); - } - AUD_log (NULL, "Context:\n"); - } - - return cond; -} - /* * Convert audio format to mixeng_clip index. Used by audio_pcm_sw_init_ a= nd * audio_mixeng_backend_add_capture() @@ -332,8 +317,8 @@ static size_t audio_pcm_hw_find_min_in (HWVoiceIn *hw) static size_t audio_pcm_hw_get_live_in(HWVoiceIn *hw) { size_t live =3D hw->total_samples_captured - audio_pcm_hw_find_min_in = (hw); - if (audio_bug(__func__, live > hw->conv_buf.size)) { - dolog("live=3D%zu hw->conv_buf.size=3D%zu\n", live, hw->conv_buf.s= ize); + if (live > hw->conv_buf.size) { + audio_bug("live=3D%zu hw->conv_buf.size=3D%zu", live, hw->conv_buf= .size); return 0; } return live; @@ -402,8 +387,8 @@ static size_t audio_pcm_sw_read(SWVoiceIn *sw, void *bu= f, size_t buf_len) if (!live) { return 0; } - if (audio_bug(__func__, live > hw->conv_buf.size)) { - dolog("live_in=3D%zu hw->conv_buf.size=3D%zu\n", live, hw->conv_bu= f.size); + if (live > hw->conv_buf.size) { + audio_bug("live=3D%zu hw->conv_buf.size=3D%zu", live, hw->conv_buf= .size); return 0; } =20 @@ -454,8 +439,8 @@ static size_t audio_pcm_hw_get_live_out (HWVoiceOut *hw= , int *nb_live) if (nb_live1) { size_t live =3D smin; =20 - if (audio_bug(__func__, live > hw->mix_buf.size)) { - dolog("live=3D%zu hw->mix_buf.size=3D%zu\n", live, hw->mix_buf= .size); + if (live > hw->mix_buf.size) { + audio_bug("live=3D%zu hw->mix_buf.size=3D%zu", live, hw->mix_b= uf.size); return 0; } return live; @@ -533,8 +518,8 @@ static size_t audio_pcm_sw_write(SWVoiceOut *sw, void *= buf, size_t buf_len) size_t frames_in_max, frames_out_max, total_in, total_out; =20 live =3D sw->total_hw_samples_mixed; - if (audio_bug(__func__, live > hw->mix_buf.size)) { - dolog("live=3D%zu hw->mix_buf.size=3D%zu\n", live, hw->mix_buf.siz= e); + if (live > hw->mix_buf.size) { + audio_bug("live=3D%zu hw->mix_buf.size=3D%zu", live, hw->mix_buf.s= ize); return 0; } =20 @@ -824,9 +809,9 @@ static size_t audio_get_avail(SWVoiceIn *sw) } =20 live =3D sw->hw->total_samples_captured - sw->total_hw_samples_acquire= d; - if (audio_bug(__func__, live > sw->hw->conv_buf.size)) { - dolog("live=3D%zu sw->hw->conv_buf.size=3D%zu\n", live, - sw->hw->conv_buf.size); + if (live > sw->hw->conv_buf.size) { + audio_bug("live=3D%zu sw->hw->conv_buf.size=3D%zu", live, + sw->hw->conv_buf.size); return 0; } =20 @@ -845,9 +830,9 @@ static size_t audio_get_free(SWVoiceOut *sw) =20 live =3D sw->total_hw_samples_mixed; =20 - if (audio_bug(__func__, live > sw->hw->mix_buf.size)) { - dolog("live=3D%zu sw->hw->mix_buf.size=3D%zu\n", live, - sw->hw->mix_buf.size); + if (live > sw->hw->mix_buf.size) { + audio_bug("live=3D%zu sw->hw->mix_buf.size=3D%zu", live, + sw->hw->mix_buf.size); return 0; } =20 @@ -1002,8 +987,8 @@ static void audio_run_out(AudioMixengBackend *s) live =3D 0; } =20 - if (audio_bug(__func__, live > hw->mix_buf.size)) { - dolog("live=3D%zu hw->mix_buf.size=3D%zu\n", live, hw->mix_buf= .size); + if (live > hw->mix_buf.size) { + audio_bug("live=3D%zu hw->mix_buf.size=3D%zu", live, hw->mix_b= uf.size); continue; } =20 @@ -1033,9 +1018,9 @@ static void audio_run_out(AudioMixengBackend *s) prev_rpos =3D hw->mix_buf.pos; played =3D audio_pcm_hw_run_out(hw, live); replay_audio_out(&played); - if (audio_bug(__func__, hw->mix_buf.pos >=3D hw->mix_buf.size)) { - dolog("hw->mix_buf.pos=3D%zu hw->mix_buf.size=3D%zu played=3D%= zu\n", - hw->mix_buf.pos, hw->mix_buf.size, played); + if (hw->mix_buf.pos >=3D hw->mix_buf.size) { + audio_bug("hw->mix_buf.pos=3D%zu hw->mix_buf.size=3D%zu played= =3D%zu", + hw->mix_buf.pos, hw->mix_buf.size, played); hw->mix_buf.pos =3D 0; } =20 @@ -1050,9 +1035,9 @@ static void audio_run_out(AudioMixengBackend *s) continue; } =20 - if (audio_bug(__func__, played > sw->total_hw_samples_mixed)) { - dolog("played=3D%zu sw->total_hw_samples_mixed=3D%zu\n", - played, sw->total_hw_samples_mixed); + if (played > sw->total_hw_samples_mixed) { + audio_bug("played=3D%zu sw->total_hw_samples_mixed=3D%zu", + played, sw->total_hw_samples_mixed); played =3D sw->total_hw_samples_mixed; } =20 @@ -1195,9 +1180,9 @@ static void audio_run_capture(AudioMixengBackend *s) continue; } =20 - if (audio_bug(__func__, captured > sw->total_hw_samples_mixed)= ) { - dolog("captured=3D%zu sw->total_hw_samples_mixed=3D%zu\n", - captured, sw->total_hw_samples_mixed); + if (captured > sw->total_hw_samples_mixed) { + audio_bug("captured=3D%zu sw->total_hw_samples_mixed=3D%zu= ", + captured, sw->total_hw_samples_mixed); captured =3D sw->total_hw_samples_mixed; } =20 --=20 2.52.0