Patchwork [07/10] isa: add creation function that may fail

login
register
mail settings
Submitter Blue Swirl
Date Feb. 3, 2011, 9:01 p.m.
Message ID <AANLkTikGBjdR1umFAjPEH9GOrq+0CDAukLCfMDRwu2BY@mail.gmail.com>
Download mbox | patch
Permalink /patch/81722/
State New
Headers show

Comments

Blue Swirl - Feb. 3, 2011, 9:01 p.m.
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 hw/isa-bus.c |   12 ++++++++++++
 hw/isa.h     |    1 +
 2 files changed, 13 insertions(+), 0 deletions(-)
Markus Armbruster - Feb. 12, 2011, 5:11 p.m.
Blue Swirl <blauwirbel@gmail.com> writes:

> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
> ---
>  hw/isa-bus.c |   12 ++++++++++++
>  hw/isa.h     |    1 +
>  2 files changed, 13 insertions(+), 0 deletions(-)
>
> diff --git a/hw/isa-bus.c b/hw/isa-bus.c
> index 0cb1afb..6f349a5 100644
> --- a/hw/isa-bus.c
> +++ b/hw/isa-bus.c
> @@ -146,6 +146,18 @@ ISADevice *isa_create(const char *name)
>      return DO_UPCAST(ISADevice, qdev, dev);
>  }
>
> +ISADevice *isa_try_create(const char *name)
> +{
> +    DeviceState *dev;
> +
> +    if (!isabus) {
> +        hw_error("Tried to create isa device %s with no isa bus present.",
> +                 name);

I don't like the use of hw_error() here either.

> +    }
> +    dev = qdev_try_create(&isabus->qbus, name);
> +    return DO_UPCAST(ISADevice, qdev, dev);
> +}
> +
>  ISADevice *isa_create_simple(const char *name)
>  {
>      ISADevice *dev;
> diff --git a/hw/isa.h b/hw/isa.h
> index 19aa94c..e26abfa 100644
> --- a/hw/isa.h
> +++ b/hw/isa.h
> @@ -32,6 +32,7 @@ void isa_init_ioport(ISADevice *dev, uint16_t ioport);
>  void isa_init_ioport_range(ISADevice *dev, uint16_t start, uint16_t length);
>  void isa_qdev_register(ISADeviceInfo *info);
>  ISADevice *isa_create(const char *name);
> +ISADevice *isa_try_create(const char *name);
>  ISADevice *isa_create_simple(const char *name);
>
>  extern target_phys_addr_t isa_mem_base;

Patch

diff --git a/hw/isa-bus.c b/hw/isa-bus.c
index 0cb1afb..6f349a5 100644
--- a/hw/isa-bus.c
+++ b/hw/isa-bus.c
@@ -146,6 +146,18 @@  ISADevice *isa_create(const char *name)
     return DO_UPCAST(ISADevice, qdev, dev);
 }

+ISADevice *isa_try_create(const char *name)
+{
+    DeviceState *dev;
+
+    if (!isabus) {
+        hw_error("Tried to create isa device %s with no isa bus present.",
+                 name);
+    }
+    dev = qdev_try_create(&isabus->qbus, name);
+    return DO_UPCAST(ISADevice, qdev, dev);
+}
+
 ISADevice *isa_create_simple(const char *name)
 {
     ISADevice *dev;
diff --git a/hw/isa.h b/hw/isa.h
index 19aa94c..e26abfa 100644
--- a/hw/isa.h
+++ b/hw/isa.h
@@ -32,6 +32,7 @@  void isa_init_ioport(ISADevice *dev, uint16_t ioport);
 void isa_init_ioport_range(ISADevice *dev, uint16_t start, uint16_t length);
 void isa_qdev_register(ISADeviceInfo *info);
 ISADevice *isa_create(const char *name);
+ISADevice *isa_try_create(const char *name);
 ISADevice *isa_create_simple(const char *name);

 extern target_phys_addr_t isa_mem_base;