Skip to contentSkip to conversation

PATCH:hw/sd:sd_init()] hw/sd : modified the sd_init() function

RFC In review Tejaswini 2 participants 5 messages Mar 27, 2017 – Apr 18, 2017

lore
Share & tools
lore

Tejaswini

author
#0 lore raw

RFC 1/1 PATCH:hw/sd:sd_init()] hw/sd : modified the sd_init() function

From: Tejaswini Poluri <[email protected]>

Changed sd_init() to take SDstate by value and return state as success/failure Edited the rest of the functions using sd_init() to accommodate the change

---
 hw/sd/milkymist-memcard.c |  3 +--
 hw/sd/omap_mmc.c          |  6 ++----
 hw/sd/pl181.c             |  4 ++--
 hw/sd/sd.c                | 13 ++++++++-----
 hw/sd/ssi-sd.c            |  3 +--
 include/hw/sd/sd.h        |  2 +-
 6 files changed, 15 insertions(+), 16 deletions(-)
hw/sd/milkymist-memcard.c +1 -2
index 1f2f0ed..68e50e5 100644
@@ -259,8 +259,7 @@ static int milkymist_memcard_init(SysBusDevice *dev)
     /* FIXME use a qdev drive property instead of drive_get_next() */
     dinfo = drive_get_next(IF_SD);
     blk = dinfo ? blk_by_legacy_dinfo(dinfo) : NULL;
-    s->card = sd_init(blk, false);
-    if (s->card == NULL) {
+    if (sd_init(s->card, blk, false) < 0) {
         return -1;
     }
 
hw/sd/omap_mmc.c +2 -4
index e934cd3..add48a6 100644
@@ -593,8 +593,7 @@ struct omap_mmc_s *omap_mmc_init(hwaddr base,
     memory_region_add_subregion(sysmem, base, &s->iomem);
 
     /* Instantiate the storage */
-    s->card = sd_init(blk, false);
-    if (s->card == NULL) {
+    if (sd_init(s->card, blk, false) < 0) {
         exit(1);
     }
 
@@ -620,8 +619,7 @@ struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta,
     omap_l4_attach(ta, 0, &s->iomem);
 
     /* Instantiate the storage */
-    s->card = sd_init(blk, false);
-    if (s->card == NULL) {
+    if (sd_init(s->card, blk, false) < 0) {
         exit(1);
     }
 
hw/sd/pl181.c +2 -2
index 82c63a4..c2e2459 100644
@@ -502,8 +502,8 @@ static void pl181_realize(DeviceState *dev, Error **errp)
 
     /* FIXME use a qdev drive property instead of drive_get_next() */
     dinfo = drive_get_next(IF_SD);
-    s->card = sd_init(dinfo ? blk_by_legacy_dinfo(dinfo) : NULL, false);
-    if (s->card == NULL) {
+    if (sd_init(s->card, dinfo ?
+		blk_by_legacy_dinfo(dinfo) : NULL, false) < 0) {
         error_setg(errp, "sd_init failed");
     }
 }
hw/sd/sd.c +8 -5
index ba47bff..b593939 100644
@@ -562,7 +562,7 @@ static const VMStateDescription sd_vmstate = {
 };
 
 /* Legacy initialization function for use by non-qdevified callers */
-SDState *sd_init(BlockBackend *blk, bool is_spi)
+int sd_init(SDState *sd_state, BlockBackend *blk, bool is_spi)
 {
     Object *obj;
     DeviceState *dev;
@@ -573,16 +573,19 @@ SDState *sd_init(BlockBackend *blk, bool is_spi)
     qdev_prop_set_drive(dev, "drive", blk, &err);
     if (err) {
         error_report("sd_init failed: %s", error_get_pretty(err));
-        return NULL;
+        return -1;
     }
     qdev_prop_set_bit(dev, "spi", is_spi);
     object_property_set_bool(obj, true, "realized", &err);
     if (err) {
         error_report("sd_init failed: %s", error_get_pretty(err));
-        return NULL;
+        return -1;
     }
-
-    return SD_CARD(dev);
+    sd_state = SD_CARD(dev);
+    if (!sd_state) {
+		return -1;
+	}
+    return 0;
 }
 
 void sd_set_cb(SDState *sd, qemu_irq readonly, qemu_irq insert)
hw/sd/ssi-sd.c +1 -2
index 24001dc..c70b32d 100644
@@ -244,8 +244,7 @@ static void ssi_sd_realize(SSISlave *d, Error **errp)
     s->mode = SSI_SD_CMD;
     /* FIXME use a qdev drive property instead of drive_get_next() */
     dinfo = drive_get_next(IF_SD);
-    s->sd = sd_init(dinfo ? blk_by_legacy_dinfo(dinfo) : NULL, true);
-    if (s->sd == NULL) {
+    if (sd_init(s->sd, dinfo ? blk_by_legacy_dinfo(dinfo) : NULL, true) < 0) {
         error_setg(errp, "Device initialization failed.");
         return;
     }
include/hw/sd/sd.h +1 -1
index 96caefe..63741c0 100644
@@ -115,7 +115,7 @@ typedef struct {
 } SDBusClass;
 
 /* Legacy functions to be used only by non-qdevified callers */
-SDState *sd_init(BlockBackend *bs, bool is_spi);
+int sd_init(SDState *sd, BlockBackend *bs, bool is_spi);
 int sd_do_command(SDState *sd, SDRequest *req,
                   uint8_t *response);
 void sd_write_data(SDState *sd, uint8_t value);
Signature · 1 line
2.7.4
#1 lore raw
Quoted 1 line · Tejaswini

From: Tejaswini Poluri <[email protected]>

Please shorten the subject line: "[PATCH] hw/sd: simplify sd_init() prototype"

Quoted 7 lines
hw/sd/sd.c +1 -1
@@ -573,16 +573,19 @@ SDState *sd_init(BlockBackend *blk, bool is_spi)
     qdev_prop_set_drive(dev, "drive", blk, &err);
     if (err) {
         error_report("sd_init failed: %s", error_get_pretty(err));
-        return NULL;
+        return -1;
     }

hw/sd/sd.c SDState *sd_init(BlockBackend *blk, bool is_spi) · line 584

Quoted 10 lines
hw/sd/sd.c +2 -3
     qdev_prop_set_bit(dev, "spi", is_spi);
     object_property_set_bool(obj, true, "realized", &err);
     if (err) {
         error_report("sd_init failed: %s", error_get_pretty(err));
-        return NULL;
+        return -1;
     }
-
-    return SD_CARD(dev);
+    sd_state = SD_CARD(dev);

The caller will not see the new value of sd_state. In C arguments are passed by value. That means they are local variables inside the function and do not affect the caller.

I have CCed Paolo Bonzini, who posted this task. Maybe he can explain what he meant by "Include SDState by value instead of allocating it in sd_init (hw/sd/)".

hw/sd/sd.c SDState *sd_init(BlockBackend *blk, bool is_spi) · line 587

Quoted 3 lines
hw/sd/sd.c +3 -0
+    if (!sd_state) {
+		return -1;
+	}

QEMU use 4 space indentation. Please do not use tabs.

#2 lore raw
Quoted 28 lines · Stefan Hajnoczi
Quoted 1 line · Tejaswini

From: Tejaswini Poluri <[email protected]>

Please shorten the subject line: "[PATCH] hw/sd: simplify sd_init() prototype"

Quoted 7 lines
hw/sd/sd.c +1 -1
@@ -573,16 +573,19 @@ SDState *sd_init(BlockBackend *blk, bool is_spi)
     qdev_prop_set_drive(dev, "drive", blk, &err);
     if (err) {
         error_report("sd_init failed: %s", error_get_pretty(err));
-        return NULL;
+        return -1;
     }

hw/sd/sd.c SDState *sd_init(BlockBackend *blk, bool is_spi) · line 584

Quoted 10 lines
hw/sd/sd.c +2 -3
     qdev_prop_set_bit(dev, "spi", is_spi);
     object_property_set_bool(obj, true, "realized", &err);
     if (err) {
         error_report("sd_init failed: %s", error_get_pretty(err));
-        return NULL;
+        return -1;
     }
-
-    return SD_CARD(dev);
+    sd_state = SD_CARD(dev);

The caller will not see the new value of sd_state. In C arguments are passed by value. That means they are local variables inside the function and do not affect the caller.

Quoted 1 line

The caller will call sd_init() along with passing SDState pointer as an

argument like below
if (sd_init(s->card, blk, false) < 0) .
And the sd_init() function is modified to
int sd_init(SDState *sd_state, BlockBackend *blk, bool is_spi) so that the caller gets the new value of SDstate updated. Looking forward for the comments of Paolo Bonzini to understand what more needs to be done as part of the task.

I have CCed Paolo Bonzini, who posted this task. Maybe he can explain

Quoted 9 lines

what he meant by "Include SDState by value instead of allocating it in sd_init (hw/sd/)".

hw/sd/sd.c SDState *sd_init(BlockBackend *blk, bool is_spi) · line 587

Quoted 3 lines
hw/sd/sd.c +3 -0
+    if (!sd_state) {
+             return -1;
+     }

QEMU use 4 space indentation. Please do not use tabs.

Signature · 2 lines
Regards,
Tejaswini
#3 lore raw

Hii Paolo,
Waiting for your comments on this patch

Regards,
Tejaswini

Quoted 59 lines · Tejaswini Poluri
Quoted 28 lines · Stefan Hajnoczi
Quoted 1 line · Tejaswini

From: Tejaswini Poluri <[email protected]>

Please shorten the subject line: "[PATCH] hw/sd: simplify sd_init() prototype"

Quoted 7 lines
hw/sd/sd.c +1 -1
@@ -573,16 +573,19 @@ SDState *sd_init(BlockBackend *blk, bool is_spi)
     qdev_prop_set_drive(dev, "drive", blk, &err);
     if (err) {
         error_report("sd_init failed: %s", error_get_pretty(err));
-        return NULL;
+        return -1;
     }

hw/sd/sd.c SDState *sd_init(BlockBackend *blk, bool is_spi) · line 584

Quoted 10 lines
hw/sd/sd.c +2 -3
     qdev_prop_set_bit(dev, "spi", is_spi);
     object_property_set_bool(obj, true, "realized", &err);
     if (err) {
         error_report("sd_init failed: %s", error_get_pretty(err));
-        return NULL;
+        return -1;
     }
-
-    return SD_CARD(dev);
+    sd_state = SD_CARD(dev);

The caller will not see the new value of sd_state. In C arguments are passed by value. That means they are local variables inside the function and do not affect the caller.

Quoted 1 line

The caller will call sd_init() along with passing SDState pointer as an

argument like below
if (sd_init(s->card, blk, false) < 0) .
And the sd_init() function is modified to
int sd_init(SDState *sd_state, BlockBackend *blk, bool is_spi) so that the caller gets the new value of SDstate updated. Looking forward for the comments of Paolo Bonzini to understand what more needs to be done as part of the task.

I have CCed Paolo Bonzini, who posted this task. Maybe he can explain

Quoted 9 lines

what he meant by "Include SDState by value instead of allocating it in sd_init (hw/sd/)".

hw/sd/sd.c SDState *sd_init(BlockBackend *blk, bool is_spi) · line 587

Quoted 3 lines
hw/sd/sd.c +3 -0
+    if (!sd_state) {
+             return -1;
+     }

QEMU use 4 space indentation. Please do not use tabs.

--
Regards,
Tejaswini

#4 lore raw

Hii,

A gentle reminder on the same!

Regards,
Tejaswini

On Sun, Apr 9, 2017 at 5:44 AM, Tejaswini Poluri <[email protected]

Quoted 70 lines

wrote:

Hii Paolo,
Waiting for your comments on this patch

Regards,
Tejaswini

Quoted 59 lines · Tejaswini Poluri
Quoted 28 lines · Stefan Hajnoczi
Quoted 1 line · Tejaswini

From: Tejaswini Poluri <[email protected]>

Please shorten the subject line: "[PATCH] hw/sd: simplify sd_init() prototype"

Quoted 7 lines
hw/sd/sd.c +1 -1
@@ -573,16 +573,19 @@ SDState *sd_init(BlockBackend *blk, bool is_spi)
     qdev_prop_set_drive(dev, "drive", blk, &err);
     if (err) {
         error_report("sd_init failed: %s", error_get_pretty(err));
-        return NULL;
+        return -1;
     }

hw/sd/sd.c SDState *sd_init(BlockBackend *blk, bool is_spi) · line 584

Quoted 10 lines
hw/sd/sd.c +2 -3
     qdev_prop_set_bit(dev, "spi", is_spi);
     object_property_set_bool(obj, true, "realized", &err);
     if (err) {
         error_report("sd_init failed: %s", error_get_pretty(err));
-        return NULL;
+        return -1;
     }
-
-    return SD_CARD(dev);
+    sd_state = SD_CARD(dev);

The caller will not see the new value of sd_state. In C arguments are passed by value. That means they are local variables inside the function and do not affect the caller.

Quoted 1 line

The caller will call sd_init() along with passing SDState pointer as an

argument like below
if (sd_init(s->card, blk, false) < 0) .
And the sd_init() function is modified to
int sd_init(SDState *sd_state, BlockBackend *blk, bool is_spi) so that the caller gets the new value of SDstate updated. Looking forward for the comments of Paolo Bonzini to understand what more needs to be done as part of the task.

I have CCed Paolo Bonzini, who posted this task. Maybe he can explain

Quoted 9 lines

what he meant by "Include SDState by value instead of allocating it in sd_init (hw/sd/)".

hw/sd/sd.c SDState *sd_init(BlockBackend *blk, bool is_spi) · line 587

Quoted 3 lines
hw/sd/sd.c +3 -0
+    if (!sd_state) {
+             return -1;
+     }

QEMU use 4 space indentation. Please do not use tabs.

--
Regards,
Tejaswini

Signature · 2 lines
Regards,
Tejaswini