From nobody Fri May 10 16:59:23 2024 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661174362; cv=none; d=zohomail.com; s=zohoarc; b=gjLh+7Qhuz4z55x5CDlk7LanuPsaiNQw1Yh+jSq/uaGpLfJd4Lfh6AErC5qmpRkPZyFkwng84AyG51sNyyaS6/UQFONfuF0hVt5CKpWaVbPkrN5OxZ4e4Y53N98WLsQ9WiDA4B5Yi3SfuR7VAwDSlnpND0pW2L+g3geDKRj7h/c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661174362; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=jmiDn4EIMZQktX9Y8leV1t4a++zmx8gqxJ8HJDnnfww=; b=lKpCIcgFSdwVThHnsSsQRMV8n+Lm8Rcswog+81XxVw2UQsiW8jiJvYOzanfnuxAJgqWdEPjkN+bLQ5BscSRL2LqcwcgFJlc8RRVXWtv/f2hE9jXvkUp7tWpukr0mjontBKl1p0DyEdm4k7tR37gX5OhuiIrP7FlFOtK5a+tB/Xs= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 166117436275299.89953981033113; Mon, 22 Aug 2022 06:19:22 -0700 (PDT) Received: from localhost ([::1]:37448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQ7Kq-0000ZV-5U for importer@patchew.org; Mon, 22 Aug 2022 09:19:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38850) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ7Cf-0008G6-2e for qemu-devel@nongnu.org; Mon, 22 Aug 2022 09:10:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:27687) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ7CT-0007bi-CS for qemu-devel@nongnu.org; Mon, 22 Aug 2022 09:10:51 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-534-hi4BiJNVNKKdRixTFVamyw-1; Mon, 22 Aug 2022 09:10:25 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2DB011C14D20 for ; Mon, 22 Aug 2022 13:10:25 +0000 (UTC) Received: from localhost (unknown [10.39.208.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id E488D1415137; Mon, 22 Aug 2022 13:10:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661173826; 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; bh=jmiDn4EIMZQktX9Y8leV1t4a++zmx8gqxJ8HJDnnfww=; b=QrmUeX9I80zhTo0LxCVW4aTd5kq1CLaEUSy0M0Dy2UEfsRDMM3eYt+yUQCn8YT6wfGadYX jiUpTYOTkJsIYOrBMPxvOTtevDjo9P+PcYSICrE0c4CGK4vxNme5FR2MXC8Hld+HpP0N+V kznh0wWXaoRJ+W47SmTgmEhEUDfQgrc= X-MC-Unique: hi4BiJNVNKKdRixTFVamyw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann , Paolo Bonzini Subject: [PATCH] audio: exit(1) if audio backend failed to be found or initialized Date: Mon, 22 Aug 2022 17:10:21 +0400 Message-Id: <20220822131021.975656-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 2.85 on 10.11.54.7 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661174364913100001 From: Marc-Andr=C3=A9 Lureau If you specify a known backend but it isn't compiled in, or failed to initialize, you get a simple warning and the "none" backend as a fallback, and QEMU runs happily: $ qemu-system-x86_64 -audiodev id=3Daudio,driver=3Ddsound audio: Unknown audio driver `dsound' audio: warning: Using timer based audio emulation ... Instead, QEMU should fail to start: $ qemu-system-x86_64 -audiodev id=3Daudio,driver=3Ddsound audio: Unknown audio driver `dsound' $ Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1983493 Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Volker R=C3=BCmelin --- audio/audio.h | 2 +- audio/audio.c | 14 +++++++++++--- softmmu/vl.c | 4 +++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/audio/audio.h b/audio/audio.h index b5e17cd218..27e67079a0 100644 --- a/audio/audio.h +++ b/audio/audio.h @@ -170,7 +170,7 @@ void audio_sample_from_uint64(void *samples, int pos, =20 void audio_define(Audiodev *audio); void audio_parse_option(const char *opt); -void audio_init_audiodevs(void); +bool audio_init_audiodevs(void); void audio_legacy_help(void); =20 AudioState *audio_state_by_name(const char *name); diff --git a/audio/audio.c b/audio/audio.c index a02f3ce5c6..76b8735b44 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -1743,7 +1743,6 @@ static AudioState *audio_init(Audiodev *dev, const ch= ar *name) atexit(audio_cleanup); atexit_registered =3D true; } - QTAILQ_INSERT_TAIL(&audio_states, s, list); =20 s->ts =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, audio_timer, s); =20 @@ -1769,6 +1768,10 @@ static AudioState *audio_init(Audiodev *dev, const c= har *name) } else { dolog ("Unknown audio driver `%s'\n", drvname); } + if (!done) { + free_audio_state(s); + return NULL; + } } else { for (i =3D 0; audio_prio_list[i]; i++) { AudiodevListEntry *e =3D audiodev_find(&head, audio_prio_list[= i]); @@ -1806,6 +1809,7 @@ static AudioState *audio_init(Audiodev *dev, const ch= ar *name) "(Audio can continue looping even after stopping the VM)\n"= ); } =20 + QTAILQ_INSERT_TAIL(&audio_states, s, list); QLIST_INIT (&s->card_head); vmstate_register (NULL, 0, &vmstate_audio, s); return s; @@ -2119,13 +2123,17 @@ void audio_define(Audiodev *dev) QSIMPLEQ_INSERT_TAIL(&audiodevs, e, next); } =20 -void audio_init_audiodevs(void) +bool audio_init_audiodevs(void) { AudiodevListEntry *e; =20 QSIMPLEQ_FOREACH(e, &audiodevs, next) { - audio_init(e->dev, NULL); + if (!audio_init(e->dev, NULL)) { + return false; + } } + + return true; } =20 audsettings audiodev_to_audsettings(AudiodevPerDirectionOptions *pdo) diff --git a/softmmu/vl.c b/softmmu/vl.c index 706bd7cff7..dea4005e47 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -1885,7 +1885,9 @@ static void qemu_create_early_backends(void) * setting machine properties, so they can be referred to. */ configure_blockdev(&bdo_queue, machine_class, snapshot); - audio_init_audiodevs(); + if (!audio_init_audiodevs()) { + exit(1); + } } =20 =20 --=20 2.37.1