Patchwork [v1,4/5] block/nand: Convert Sysbus::init to Device::realize

login
register
mail settings
Submitter Peter Crosthwaite
Date June 18, 2013, 11:11 a.m.
Message ID <c58f8529510c849b9a6deab9194f685b695d98ac.1371553360.git.peter.crosthwaite@xilinx.com>
Download mbox | patch
Permalink /patch/252234/
State New
Headers show

Comments

Peter Crosthwaite - June 18, 2013, 11:11 a.m.
From: Peter Crosthwaite <peter.crosthwaite@xilinx.com>

The prescribed transition from Sysbus::init function to a
Device::realize.

Cc: afaerber@suse.de

Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
---

 hw/block/nand.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
Andreas Färber - June 19, 2013, 10:56 a.m.
Am 18.06.2013 13:11, schrieb peter.crosthwaite@xilinx.com:
> From: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
> 
> The prescribed transition from Sysbus::init function to a
> Device::realize.
> 
> Cc: afaerber@suse.de
> 
> Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
> ---
> 
>  hw/block/nand.c | 16 +++++++---------
>  1 file changed, 7 insertions(+), 9 deletions(-)

Due to chip_id property we can't seem to split anything off from realize.

Reviewed-by: Andreas Färber <afaerber@suse.de>

Andreas

Patch

diff --git a/hw/block/nand.c b/hw/block/nand.c
index d2469f5..8dca3bc 100644
--- a/hw/block/nand.c
+++ b/hw/block/nand.c
@@ -367,7 +367,7 @@  static const VMStateDescription vmstate_nand = {
     }
 };
 
-static int nand_device_init(SysBusDevice *dev)
+static void nand_realize(DeviceState *dev, Error **errp)
 {
     int pagesize;
     NANDFlashState *s = NAND(dev);
@@ -393,16 +393,17 @@  static int nand_device_init(SysBusDevice *dev)
         nand_init_2048(s);
         break;
     default:
-        error_report("Unsupported NAND block size");
-        return -1;
+        error_setg(errp, "Unsupported NAND block size %#x\n",
+                   1 << s->page_shift);
+        return;
     }
 
     pagesize = 1 << s->oob_shift;
     s->mem_oob = 1;
     if (s->bdrv) {
         if (bdrv_is_read_only(s->bdrv)) {
-            error_report("Can't use a read-only drive");
-            return -1;
+            error_setg(errp, "Can't use a read-only drive");
+            return;
         }
         if (bdrv_getlength(s->bdrv) >=
                 (s->pages << s->page_shift) + (s->pages << s->oob_shift)) {
@@ -418,8 +419,6 @@  static int nand_device_init(SysBusDevice *dev)
     }
     /* Give s->ioaddr a sane value in case we save state before it is used. */
     s->ioaddr = s->io;
-
-    return 0;
 }
 
 static Property nand_properties[] = {
@@ -432,9 +431,8 @@  static Property nand_properties[] = {
 static void nand_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-    k->init = nand_device_init;
+    dc->realize = nand_realize;
     dc->reset = nand_reset;
     dc->vmsd = &vmstate_nand;
     dc->props = nand_properties;