audio: fix pc speaker init
PATCH 1/1 audio: fix pc speaker init
Get rid of the pcspk_state global, allow pc speaker be added using "-device isa-pcspk".
--- hw/audio/pcspk.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-)
hw/audio/pcspk.c +15 -20
@@ -57,7 +57,6 @@ typedef struct { } PCSpkState;static const char *s_spk ="pcspk" ; -static PCSpkState *pcspk_state;static inline void generate_samples (PCSpkState *s) {
@@ -111,22 +110,6 @@ static void pcspk_callback(void *opaque, int free) } } -static int pcspk_audio_init (ISABus *bus) -{ -PCSpkState *s = pcspk_state; -struct audsettings as = {PCSPK_SAMPLE_RATE ,1 ,AUD_FMT_U8 ,0 }; - -AUD_register_card (s_spk, &s->card); - - s->voice =AUD_open_out (&s->card, s->voice, s_spk, s, pcspk_callback, &as); -if (!s->voice) { -AUD_log (s_spk,"Could not open voice\n" ); -return -1 ; - } - -return 0 ; -} -static uint64_t pcspk_io_read (void *opaque,hwaddr addr,unsigned size) {
@@ -179,12 +162,20 @@ static void pcspk_initfn(Object *obj)static void pcspk_realizefn (DeviceState *dev,Error **errp) { +struct audsettings as = {PCSPK_SAMPLE_RATE ,1 ,AUD_FMT_U8 ,0 };ISADevice *isadev =ISA_DEVICE (dev);PCSpkState *s =PC_SPEAKER (dev);isa_register_ioport (isadev, &s->ioport, s->iobase); - pcspk_state = s; +AUD_register_card (s_spk, &s->card); + + s->voice =AUD_open_out (&s->card, s->voice, s_spk, s, pcspk_callback, &as); +if (!s->voice) { +error_setg (errp,"Initializing audio voice failed" ); +AUD_remove_card (&s->card); +return ; + } }static bool migrate_needed (void *opaque)
@@ -221,8 +212,6 @@ static void pcspk_class_initfn(ObjectClass *klass, void *data)set_bit (DEVICE_CATEGORY_SOUND , dc->categories); dc->vmsd = &vmstate_spk; dc->props = pcspk_properties; -/* Reason: realize sets global pcspk_state */ - dc->user_creatable = false; }static const TypeInfo pcspk_info = {
@@ -233,6 +222,12 @@ static const TypeInfo pcspk_info = { .class_init = pcspk_class_initfn, }; +static int pcspk_audio_init (ISABus *bus) +{ +isa_create_simple (bus,TYPE_PC_SPEAKER ); +return 0 ; +} +static void pcspk_register (void ) {type_register_static (&pcspk_info);
Signature · 1 line
2.9.3
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Message-id: [email protected]
Type: series
Subject: [Qemu-devel] [PATCH] audio: fix pc speaker init
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
a762b28 audio: fix pc speaker init
=== OUTPUT BEGIN ===
ERROR: space prohibited between function name and open parenthesis '(' #63: FILE: hw/audio/pcspk.c:175:
+ error_setg (errp, "Initializing audio voice failed");
ERROR: space prohibited between function name and open parenthesis '(' #85: FILE: hw/audio/pcspk.c:227:
+ isa_create_simple (bus, TYPE_PC_SPEAKER);
total: 2 errors, 0 warnings, 70 lines checked
Commit a762b288e328 (audio: fix pc speaker init) has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]
Hi Gerd,
Quoted 13 lines · Gerd Hoffmann
Get rid of the
pcspk_stateglobal, allow pc speaker be added using "-device isa-pcspk".Signed-off-by Gerd Hoffmann <[email protected]>--- hw/audio/pcspk.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-)hw/audio/pcspk.c +0
-0
hw/audio/pcspk.c typedef struct { · line 60
Quoted 4 lines
hw/audio/pcspk.c +0
-1@@ -57,7 +57,6 @@ typedef struct { } PCSpkState;static const char *s_spk ="pcspk" ; -static PCSpkState *pcspk_state;
Yeah \o/
Quoted 7 lines
hw/audio/pcspk.c +0
-0static inline void generate_samples (PCSpkState *s) {@@ -111,22 +110,6 @@ static void pcspk_callback(void *opaque, int free) } }
hw/audio/pcspk.c static void pcspk_callback(void *opaque, int free) · line 123
Quoted 10 lines
hw/audio/pcspk.c +0
-10-static int pcspk_audio_init (ISABus *bus) -{ -PCSpkState *s = pcspk_state; -struct audsettings as = {PCSPK_SAMPLE_RATE ,1 ,AUD_FMT_U8 ,0 }; - -AUD_register_card (s_spk, &s->card); - - s->voice =AUD_open_out (&s->card, s->voice, s_spk, s, pcspk_callback, &as); -if (!s->voice) { -AUD_log (s_spk,"Could not open voice\n" );
Too bad you fixed this message, it was funny :)
Quoted 41 lines
hw/audio/pcspk.c +9
-9-return -1 ; - } - -return 0 ; -} -static uint64_t pcspk_io_read (void *opaque,hwaddr addr,unsigned size) {@@ -179,12 +162,20 @@ static void pcspk_initfn(Object *obj)static void pcspk_realizefn (DeviceState *dev,Error **errp) { +struct audsettings as = {PCSPK_SAMPLE_RATE ,1 ,AUD_FMT_U8 ,0 };ISADevice *isadev =ISA_DEVICE (dev);PCSpkState *s =PC_SPEAKER (dev);isa_register_ioport (isadev, &s->ioport, s->iobase); - pcspk_state = s; +AUD_register_card (s_spk, &s->card); + + s->voice =AUD_open_out (&s->card, s->voice, s_spk, s, pcspk_callback, &as); +if (!s->voice) { +error_setg (errp,"Initializing audio voice failed" ); +AUD_remove_card (&s->card); +return ; + } }static bool migrate_needed (void *opaque)@@ -221,8 +212,6 @@ static void pcspk_class_initfn(ObjectClass *klass, void *data)set_bit (DEVICE_CATEGORY_SOUND , dc->categories); dc->vmsd = &vmstate_spk; dc->props = pcspk_properties; -/* Reason: realize sets global pcspk_state */ - dc->user_creatable = false; }static const TypeInfo pcspk_info = {
hw/audio/pcspk.c static const TypeInfo pcspk_info = { · line 228
Quoted 7 lines
hw/audio/pcspk.c +4
-0@@ -233,6 +222,12 @@ static const TypeInfo pcspk_info = { .class_init = pcspk_class_initfn, }; +static int pcspk_audio_init (ISABus *bus) +{ +isa_create_simple (bus,TYPE_PC_SPEAKER ); +return 0 ;
Previously we had soundhw_init() calling pcspk_audio_init() and ignore failures. Now since you use isa_create_simple() which calls qdev_init_nofail(), failure will directly exit(1).
Is it the expected behavior?
If not, we can keep the current behavior using:
if (isa_try_create(bus, TYPE_PC_SPEAKER) == NULL) {
return -1;
}
return 0;Regards,
Phil.
Quoted 6 lines
hw/audio/pcspk.c +2
-0+} +static void pcspk_register (void ) {type_register_static (&pcspk_info);
Quoted 9 lines
hw/audio/pcspk.c static const TypeInfo pcspk_info = { · line 228
Quoted 4 lines
hw/audio/pcspk.c +4
-0+static int pcspk_audio_init (ISABus *bus) +{ +isa_create_simple (bus,TYPE_PC_SPEAKER ); +return 0 ;Previously we had
soundhw_init()callingpcspk_audio_init()and ignore failures. Now since you useisa_create_simple()which callsqdev_init_nofail(), failure will directly exit(1).
Is it the expected behavior?
The change wasn't intentional, but I think it is better to throw an error instead of silently ignoring the problem.
In practice it probably doesn't make much of a difference, there isn't much why isa_create_simple could fail ...
cheers,
Gerd