[PATCH v4 4/4] hw/isa/i82378: Propagate error if PC_SPEAKER device creation failed

Philippe Mathieu-Daudé posted 4 patches 2 years, 3 months ago
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Eduardo Habkost <eduardo@habkost.net>, "Hervé Poussineau" <hpoussin@reactos.org>
[PATCH v4 4/4] hw/isa/i82378: Propagate error if PC_SPEAKER device creation failed
Posted by Philippe Mathieu-Daudé 2 years, 3 months ago
In commit 40f8214fcd ("hw/audio/pcspk: Inline pcspk_init()")
we neglected to give a change to the caller to handle failed
device creation cleanly. Respect the caller API contract and
propagate the error if creating the PC_SPEAKER device ever
failed. This avoid yet another bad API use to be taken as
example and copy / pasted all over the code base.

Reported-by: Bernhard Beschow <shentey@gmail.com>
Suggested-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/isa/i82378.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/isa/i82378.c b/hw/isa/i82378.c
index 79ffbb52a0..203b92c264 100644
--- a/hw/isa/i82378.c
+++ b/hw/isa/i82378.c
@@ -105,7 +105,9 @@ static void i82378_realize(PCIDevice *pci, Error **errp)
     /* speaker */
     pcspk = isa_new(TYPE_PC_SPEAKER);
     object_property_set_link(OBJECT(pcspk), "pit", OBJECT(pit), &error_fatal);
-    isa_realize_and_unref(pcspk, isabus, &error_fatal);
+    if (!isa_realize_and_unref(pcspk, isabus, errp)) {
+        return;
+    }
 
     /* 2 82C37 (dma) */
     isa_create_simple(isabus, "i82374");
-- 
2.41.0


Re: [PATCH v4 4/4] hw/isa/i82378: Propagate error if PC_SPEAKER device creation failed
Posted by Bernhard Beschow 2 years, 3 months ago

Am 20. Oktober 2023 17:15:08 UTC schrieb "Philippe Mathieu-Daudé" <philmd@linaro.org>:
>In commit 40f8214fcd ("hw/audio/pcspk: Inline pcspk_init()")
>we neglected to give a change to the caller to handle failed
>device creation cleanly. Respect the caller API contract and
>propagate the error if creating the PC_SPEAKER device ever
>failed. This avoid yet another bad API use to be taken as
>example and copy / pasted all over the code base.
>
>Reported-by: Bernhard Beschow <shentey@gmail.com>
>Suggested-by: Markus Armbruster <armbru@redhat.com>
>Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Reviewed-by: Bernhard Beschow <shentey@gmail.com>

>---
> hw/isa/i82378.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
>diff --git a/hw/isa/i82378.c b/hw/isa/i82378.c
>index 79ffbb52a0..203b92c264 100644
>--- a/hw/isa/i82378.c
>+++ b/hw/isa/i82378.c
>@@ -105,7 +105,9 @@ static void i82378_realize(PCIDevice *pci, Error **errp)
>     /* speaker */
>     pcspk = isa_new(TYPE_PC_SPEAKER);
>     object_property_set_link(OBJECT(pcspk), "pit", OBJECT(pit), &error_fatal);
>-    isa_realize_and_unref(pcspk, isabus, &error_fatal);
>+    if (!isa_realize_and_unref(pcspk, isabus, errp)) {
>+        return;
>+    }
> 
>     /* 2 82C37 (dma) */
>     isa_create_simple(isabus, "i82374");
Re: [PATCH v4 4/4] hw/isa/i82378: Propagate error if PC_SPEAKER device creation failed
Posted by Richard Henderson 2 years, 3 months ago
On 10/20/23 10:15, Philippe Mathieu-Daudé wrote:
> In commit 40f8214fcd ("hw/audio/pcspk: Inline pcspk_init()")
> we neglected to give a change to the caller to handle failed
> device creation cleanly. Respect the caller API contract and
> propagate the error if creating the PC_SPEAKER device ever
> failed. This avoid yet another bad API use to be taken as
> example and copy / pasted all over the code base.
> 
> Reported-by: Bernhard Beschow <shentey@gmail.com>
> Suggested-by: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/isa/i82378.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~