error: Avoid error_propagate() after migrate_add_blocker()
When migrate_add_blocker(blocker, &errp) is followed by error_propagate(errp, err), we can often just as well do migrate_add_blocker(..., errp). Do that with this Coccinelle script: @@ expression blocker, err, errp; expression ret; @@ - ret = migrate_add_blocker(blocker, &err); - if (err) { + ret = migrate_add_blocker(blocker, errp); + if (ret < 0) { ... when != err; - error_propagate(errp, err); ... } @@ expression blocker, err, errp; @@ - migrate_add_blocker(blocker, &err); - if (err) { + if (migrate_add_blocker(blocker, errp) < 0) { ... when != err; - error_propagate(errp, err); ... } Double-check @err is not used afterwards. Dereferencing it would be use after free, but checking whether it's null would be legitimate. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Message-Id: <20200707160613.848843-43-armbru@redhat.com>
This commit is contained in:
parent
7b3cb8037c
commit
386f6c07d2
@ -859,9 +859,8 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
error_setg(&s->migration_blocker, "The Parallels format used by node '%s' "
|
||||
"does not support live migration",
|
||||
bdrv_get_device_or_node_name(bs));
|
||||
ret = migrate_add_blocker(s->migration_blocker, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = migrate_add_blocker(s->migration_blocker, errp);
|
||||
if (ret < 0) {
|
||||
error_free(s->migration_blocker);
|
||||
goto fail;
|
||||
}
|
||||
|
@ -121,7 +121,6 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
unsigned int len, i, shift;
|
||||
int ret;
|
||||
QCowHeader header;
|
||||
Error *local_err = NULL;
|
||||
QCryptoBlockOpenOptions *crypto_opts = NULL;
|
||||
unsigned int cflags = 0;
|
||||
QDict *encryptopts = NULL;
|
||||
@ -314,9 +313,8 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
error_setg(&s->migration_blocker, "The qcow format used by node '%s' "
|
||||
"does not support live migration",
|
||||
bdrv_get_device_or_node_name(bs));
|
||||
ret = migrate_add_blocker(s->migration_blocker, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = migrate_add_blocker(s->migration_blocker, errp);
|
||||
if (ret < 0) {
|
||||
error_free(s->migration_blocker);
|
||||
goto fail;
|
||||
}
|
||||
|
@ -374,7 +374,6 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
VdiHeader header;
|
||||
size_t bmap_size;
|
||||
int ret;
|
||||
Error *local_err = NULL;
|
||||
QemuUUID uuid_link, uuid_parent;
|
||||
|
||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
|
||||
@ -495,9 +494,8 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
error_setg(&s->migration_blocker, "The vdi format used by node '%s' "
|
||||
"does not support live migration",
|
||||
bdrv_get_device_or_node_name(bs));
|
||||
ret = migrate_add_blocker(s->migration_blocker, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = migrate_add_blocker(s->migration_blocker, errp);
|
||||
if (ret < 0) {
|
||||
error_free(s->migration_blocker);
|
||||
goto fail_free_bmap;
|
||||
}
|
||||
|
@ -1089,9 +1089,8 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
error_setg(&s->migration_blocker, "The vhdx format used by node '%s' "
|
||||
"does not support live migration",
|
||||
bdrv_get_device_or_node_name(bs));
|
||||
ret = migrate_add_blocker(s->migration_blocker, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = migrate_add_blocker(s->migration_blocker, errp);
|
||||
if (ret < 0) {
|
||||
error_free(s->migration_blocker);
|
||||
goto fail;
|
||||
}
|
||||
|
@ -1263,7 +1263,6 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
int ret;
|
||||
BDRVVmdkState *s = bs->opaque;
|
||||
uint32_t magic;
|
||||
Error *local_err = NULL;
|
||||
|
||||
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
|
||||
BDRV_CHILD_IMAGE, false, errp);
|
||||
@ -1317,9 +1316,8 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
error_setg(&s->migration_blocker, "The vmdk format used by node '%s' "
|
||||
"does not support live migration",
|
||||
bdrv_get_device_or_node_name(bs));
|
||||
ret = migrate_add_blocker(s->migration_blocker, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = migrate_add_blocker(s->migration_blocker, errp);
|
||||
if (ret < 0) {
|
||||
error_free(s->migration_blocker);
|
||||
goto fail;
|
||||
}
|
||||
|
@ -446,9 +446,8 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
error_setg(&s->migration_blocker, "The vpc format used by node '%s' "
|
||||
"does not support live migration",
|
||||
bdrv_get_device_or_node_name(bs));
|
||||
ret = migrate_add_blocker(s->migration_blocker, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = migrate_add_blocker(s->migration_blocker, errp);
|
||||
if (ret < 0) {
|
||||
error_free(s->migration_blocker);
|
||||
goto fail;
|
||||
}
|
||||
|
@ -1141,7 +1141,6 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
bool floppy;
|
||||
const char *dirname, *label;
|
||||
QemuOpts *opts;
|
||||
Error *local_err = NULL;
|
||||
int ret;
|
||||
|
||||
#ifdef DEBUG
|
||||
@ -1267,9 +1266,8 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
"The vvfat (rw) format used by node '%s' "
|
||||
"does not support live migration",
|
||||
bdrv_get_device_or_node_name(bs));
|
||||
ret = migrate_add_blocker(s->migration_blocker, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = migrate_add_blocker(s->migration_blocker, errp);
|
||||
if (ret < 0) {
|
||||
error_free(s->migration_blocker);
|
||||
goto fail;
|
||||
}
|
||||
|
@ -128,7 +128,6 @@ virtio_gpu_base_device_realize(DeviceState *qdev,
|
||||
{
|
||||
VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
|
||||
VirtIOGPUBase *g = VIRTIO_GPU_BASE(qdev);
|
||||
Error *local_err = NULL;
|
||||
int i;
|
||||
|
||||
if (g->conf.max_outputs > VIRTIO_GPU_MAX_SCANOUTS) {
|
||||
@ -139,9 +138,7 @@ virtio_gpu_base_device_realize(DeviceState *qdev,
|
||||
g->use_virgl_renderer = false;
|
||||
if (virtio_gpu_virgl_enabled(g->conf)) {
|
||||
error_setg(&g->migration_blocker, "virgl is not yet migratable");
|
||||
migrate_add_blocker(g->migration_blocker, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
if (migrate_add_blocker(g->migration_blocker, errp) < 0) {
|
||||
error_free(g->migration_blocker);
|
||||
return false;
|
||||
}
|
||||
|
@ -517,9 +517,7 @@ static void kvm_arm_gic_realize(DeviceState *dev, Error **errp)
|
||||
if (!kvm_arm_gic_can_save_restore(s)) {
|
||||
error_setg(&s->migration_blocker, "This operating system kernel does "
|
||||
"not support vGICv2 migration");
|
||||
migrate_add_blocker(s->migration_blocker, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
if (migrate_add_blocker(s->migration_blocker, errp) < 0) {
|
||||
error_free(s->migration_blocker);
|
||||
return;
|
||||
}
|
||||
|
@ -91,7 +91,6 @@ static void vm_change_state_handler(void *opaque, int running,
|
||||
static void kvm_arm_its_realize(DeviceState *dev, Error **errp)
|
||||
{
|
||||
GICv3ITSState *s = ARM_GICV3_ITS_COMMON(dev);
|
||||
Error *local_err = NULL;
|
||||
|
||||
s->dev_fd = kvm_create_device(kvm_state, KVM_DEV_TYPE_ARM_VGIC_ITS, false);
|
||||
if (s->dev_fd < 0) {
|
||||
@ -113,9 +112,7 @@ static void kvm_arm_its_realize(DeviceState *dev, Error **errp)
|
||||
GITS_CTLR)) {
|
||||
error_setg(&s->migration_blocker, "This operating system kernel "
|
||||
"does not support vITS migration");
|
||||
migrate_add_blocker(s->migration_blocker, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
if (migrate_add_blocker(s->migration_blocker, errp) < 0) {
|
||||
error_free(s->migration_blocker);
|
||||
return;
|
||||
}
|
||||
|
@ -858,9 +858,7 @@ static void kvm_arm_gicv3_realize(DeviceState *dev, Error **errp)
|
||||
GICD_CTLR)) {
|
||||
error_setg(&s->migration_blocker, "This operating system kernel does "
|
||||
"not support vGICv3 migration");
|
||||
migrate_add_blocker(s->migration_blocker, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
if (migrate_add_blocker(s->migration_blocker, errp) < 0) {
|
||||
error_free(s->migration_blocker);
|
||||
return;
|
||||
}
|
||||
|
@ -898,9 +898,7 @@ static void ivshmem_common_realize(PCIDevice *dev, Error **errp)
|
||||
if (!ivshmem_is_master(s)) {
|
||||
error_setg(&s->migration_blocker,
|
||||
"Migration is disabled when using feature 'peer mode' in device 'ivshmem'");
|
||||
migrate_add_blocker(s->migration_blocker, &err);
|
||||
if (err) {
|
||||
error_propagate(errp, err);
|
||||
if (migrate_add_blocker(s->migration_blocker, errp) < 0) {
|
||||
error_free(s->migration_blocker);
|
||||
return;
|
||||
}
|
||||
|
@ -207,9 +207,7 @@ static void vhost_scsi_realize(DeviceState *dev, Error **errp)
|
||||
"When external environment supports it (Orchestrator migrates "
|
||||
"target SCSI device state or use shared storage over network), "
|
||||
"set 'migratable' property to true to enable migration.");
|
||||
migrate_add_blocker(vsc->migration_blocker, &err);
|
||||
if (err) {
|
||||
error_propagate(errp, err);
|
||||
if (migrate_add_blocker(vsc->migration_blocker, errp) < 0) {
|
||||
error_free(vsc->migration_blocker);
|
||||
goto free_virtio;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user