[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v9 03/10] hw/sd/ssi-sd: fix error handling in ssi_sd_realize
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v9 03/10] hw/sd/ssi-sd: fix error handling in ssi_sd_realize |
Date: |
Thu, 12 Mar 2020 11:59:29 +0300 |
It's wrong to use same err object as errp parameter for several
function calls without intermediate checking for error: we'll crash if
try to set err object twice.
Fix that, using new ERRP_AUTO_PROPAGATE macro.
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
hw/sd/ssi-sd.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c
index 91db069212..bc44e1a0f5 100644
--- a/hw/sd/ssi-sd.c
+++ b/hw/sd/ssi-sd.c
@@ -241,10 +241,10 @@ static const VMStateDescription vmstate_ssi_sd = {
static void ssi_sd_realize(SSISlave *d, Error **errp)
{
+ ERRP_AUTO_PROPAGATE();
ssi_sd_state *s = FROM_SSI_SLAVE(ssi_sd_state, d);
DeviceState *carddev;
DriveInfo *dinfo;
- Error *err = NULL;
qbus_create_inplace(&s->sdbus, sizeof(s->sdbus), TYPE_SD_BUS,
DEVICE(d), "sd-bus");
@@ -254,14 +254,26 @@ static void ssi_sd_realize(SSISlave *d, Error **errp)
dinfo = drive_get_next(IF_SD);
carddev = qdev_create(BUS(&s->sdbus), TYPE_SD_CARD);
if (dinfo) {
- qdev_prop_set_drive(carddev, "drive", blk_by_legacy_dinfo(dinfo),
&err);
+ qdev_prop_set_drive(carddev, "drive", blk_by_legacy_dinfo(dinfo),
errp);
+ if (*errp) {
+ goto fail;
+ }
+ }
+
+ object_property_set_bool(OBJECT(carddev), true, "spi", errp);
+ if (*errp) {
+ goto fail;
}
- object_property_set_bool(OBJECT(carddev), true, "spi", &err);
- object_property_set_bool(OBJECT(carddev), true, "realized", &err);
- if (err) {
- error_setg(errp, "failed to init SD card: %s", error_get_pretty(err));
- return;
+
+ object_property_set_bool(OBJECT(carddev), true, "realized", errp);
+ if (*errp) {
+ goto fail;
}
+
+ return;
+
+fail:
+ error_prepend(errp, "failed to init SD card: ");
}
static void ssi_sd_reset(DeviceState *dev)
--
2.21.0
- [PATCH v9 00/10] error: auto propagated local_err part I, Vladimir Sementsov-Ogievskiy, 2020/03/12
- [PATCH v9 04/10] SD (Secure Card): introduce ERRP_AUTO_PROPAGATE, Vladimir Sementsov-Ogievskiy, 2020/03/12
- [PATCH v9 06/10] fw_cfg: introduce ERRP_AUTO_PROPAGATE, Vladimir Sementsov-Ogievskiy, 2020/03/12
- [PATCH v9 08/10] TPM: introduce ERRP_AUTO_PROPAGATE, Vladimir Sementsov-Ogievskiy, 2020/03/12
- [PATCH v9 03/10] hw/sd/ssi-sd: fix error handling in ssi_sd_realize,
Vladimir Sementsov-Ogievskiy <=
- [PATCH v9 07/10] virtio-9p: introduce ERRP_AUTO_PROPAGATE, Vladimir Sementsov-Ogievskiy, 2020/03/12
- [PATCH v9 09/10] nbd: introduce ERRP_AUTO_PROPAGATE, Vladimir Sementsov-Ogievskiy, 2020/03/12
- [PATCH v9 05/10] pflash: introduce ERRP_AUTO_PROPAGATE, Vladimir Sementsov-Ogievskiy, 2020/03/12
- [PATCH v9 01/10] error: auto propagated local_err, Vladimir Sementsov-Ogievskiy, 2020/03/12
- [PATCH v9 10/10] xen: introduce ERRP_AUTO_PROPAGATE, Vladimir Sementsov-Ogievskiy, 2020/03/12
- [PATCH v9 02/10] scripts: Coccinelle script to use ERRP_AUTO_PROPAGATE(), Vladimir Sementsov-Ogievskiy, 2020/03/12