hw/audio: Simplify hda audio init

No return values are used anywhere, so switch the functions to be void
and add support for error reporting using errp for use in next patches.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-ID: <cd1df4ad2a6fae969c4a02a77955c4a8c0d430b6.1650874791.git.mkletzan@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Martin Kletzander 2022-04-25 10:21:46 +02:00 committed by Paolo Bonzini
parent 38e476e88e
commit b7639b7dd0
3 changed files with 20 additions and 18 deletions

View File

@ -675,7 +675,9 @@ static void hda_audio_stream(HDACodecDevice *hda, uint32_t stnr, bool running, b
} }
} }
static int hda_audio_init(HDACodecDevice *hda, const struct desc_codec *desc) static void hda_audio_init(HDACodecDevice *hda,
const struct desc_codec *desc,
Error **errp)
{ {
HDAAudioState *a = HDA_AUDIO(hda); HDAAudioState *a = HDA_AUDIO(hda);
HDAAudioStream *st; HDAAudioStream *st;
@ -718,7 +720,6 @@ static int hda_audio_init(HDACodecDevice *hda, const struct desc_codec *desc)
break; break;
} }
} }
return 0;
} }
static void hda_audio_exit(HDACodecDevice *hda) static void hda_audio_exit(HDACodecDevice *hda)
@ -848,37 +849,40 @@ static Property hda_audio_properties[] = {
DEFINE_PROP_END_OF_LIST(), DEFINE_PROP_END_OF_LIST(),
}; };
static int hda_audio_init_output(HDACodecDevice *hda) static void hda_audio_init_output(HDACodecDevice *hda, Error **errp)
{ {
HDAAudioState *a = HDA_AUDIO(hda); HDAAudioState *a = HDA_AUDIO(hda);
const struct desc_codec *desc = &output_nomixemu;
if (!a->mixer) { if (!a->mixer) {
return hda_audio_init(hda, &output_nomixemu); desc = &output_mixemu;
} else {
return hda_audio_init(hda, &output_mixemu);
} }
hda_audio_init(hda, desc, errp);
} }
static int hda_audio_init_duplex(HDACodecDevice *hda) static void hda_audio_init_duplex(HDACodecDevice *hda, Error **errp)
{ {
HDAAudioState *a = HDA_AUDIO(hda); HDAAudioState *a = HDA_AUDIO(hda);
const struct desc_codec *desc = &duplex_nomixemu;
if (!a->mixer) { if (!a->mixer) {
return hda_audio_init(hda, &duplex_nomixemu); desc = &duplex_mixemu;
} else {
return hda_audio_init(hda, &duplex_mixemu);
} }
hda_audio_init(hda, desc, errp);
} }
static int hda_audio_init_micro(HDACodecDevice *hda) static void hda_audio_init_micro(HDACodecDevice *hda, Error **errp)
{ {
HDAAudioState *a = HDA_AUDIO(hda); HDAAudioState *a = HDA_AUDIO(hda);
const struct desc_codec *desc = &micro_nomixemu;
if (!a->mixer) { if (!a->mixer) {
return hda_audio_init(hda, &micro_nomixemu); desc = &micro_mixemu;
} else {
return hda_audio_init(hda, &micro_mixemu);
} }
hda_audio_init(hda, desc, errp);
} }
static void hda_audio_base_class_init(ObjectClass *klass, void *data) static void hda_audio_base_class_init(ObjectClass *klass, void *data)

View File

@ -71,9 +71,7 @@ static void hda_codec_dev_realize(DeviceState *qdev, Error **errp)
return; return;
} }
bus->next_cad = dev->cad + 1; bus->next_cad = dev->cad + 1;
if (cdc->init(dev) != 0) { cdc->init(dev, errp);
error_setg(errp, "HDA audio init failed");
}
} }
static void hda_codec_dev_unrealize(DeviceState *qdev) static void hda_codec_dev_unrealize(DeviceState *qdev)

View File

@ -31,7 +31,7 @@ struct HDACodecBus {
struct HDACodecDeviceClass { struct HDACodecDeviceClass {
DeviceClass parent_class; DeviceClass parent_class;
int (*init)(HDACodecDevice *dev); void (*init)(HDACodecDevice *dev, Error **errp);
void (*exit)(HDACodecDevice *dev); void (*exit)(HDACodecDevice *dev);
void (*command)(HDACodecDevice *dev, uint32_t nid, uint32_t data); void (*command)(HDACodecDevice *dev, uint32_t nid, uint32_t data);
void (*stream)(HDACodecDevice *dev, uint32_t stnr, bool running, bool output); void (*stream)(HDACodecDevice *dev, uint32_t stnr, bool running, bool output);