error: Eliminate error_propagate() with Coccinelle, part 2
When all we do with an Error we receive into a local variable is propagating to somewhere else, we can just as well receive it there right away. The previous commit did that with a Coccinelle script I consider fairly trustworthy. This commit uses the same script with the matching of return taken out, i.e. we convert if (!foo(..., &err)) { ... error_propagate(errp, err); ... } to if (!foo(..., errp)) { ... ... } This is unsound: @err could still be read between afterwards. I don't know how to express "no read of @err without an intervening write" in Coccinelle. Instead, I manually double-checked for uses of @err. Suboptimal line breaks tweaked manually. qdev_realize() simplified further to placate scripts/checkpatch.pl. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20200707160613.848843-36-armbru@redhat.com>
This commit is contained in:
parent
668f62ec62
commit
af175e85f9
6
block.c
6
block.c
@ -1629,8 +1629,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file,
|
||||
assert(options != NULL && bs->options != options);
|
||||
|
||||
opts = qemu_opts_create(&bdrv_runtime_opts, NULL, 0, &error_abort);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, errp)) {
|
||||
ret = -EINVAL;
|
||||
goto fail_opts;
|
||||
}
|
||||
@ -4090,8 +4089,7 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,
|
||||
|
||||
/* Process generic block layer options */
|
||||
opts = qemu_opts_create(&bdrv_runtime_opts, NULL, 0, &error_abort);
|
||||
if (!qemu_opts_absorb_qdict(opts, reopen_state->options, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!qemu_opts_absorb_qdict(opts, reopen_state->options, errp)) {
|
||||
ret = -EINVAL;
|
||||
goto error;
|
||||
}
|
||||
|
@ -359,7 +359,6 @@ static int blkdebug_parse_perm_list(uint64_t *dest, QDict *options,
|
||||
QObject *crumpled_subqdict = NULL;
|
||||
Visitor *v = NULL;
|
||||
BlockPermissionList *perm_list = NULL, *element;
|
||||
Error *local_err = NULL;
|
||||
|
||||
*dest = 0;
|
||||
|
||||
@ -375,8 +374,7 @@ static int blkdebug_parse_perm_list(uint64_t *dest, QDict *options,
|
||||
}
|
||||
|
||||
v = qobject_input_visitor_new(crumpled_subqdict);
|
||||
if (!visit_type_BlockPermissionList(v, NULL, &perm_list, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!visit_type_BlockPermissionList(v, NULL, &perm_list, errp)) {
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
@ -471,8 +469,7 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
uint64_t align;
|
||||
|
||||
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, errp)) {
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
@ -149,9 +149,8 @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
bool log_append;
|
||||
|
||||
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
|
||||
if (!qemu_opts_absorb_qdict(opts, options, errp)) {
|
||||
ret = -EINVAL;
|
||||
error_propagate(errp, local_err);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
@ -116,8 +116,7 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
int ret;
|
||||
|
||||
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, errp)) {
|
||||
ret = -EINVAL;
|
||||
goto fail;
|
||||
}
|
||||
|
@ -260,7 +260,6 @@ static int block_crypto_open_generic(QCryptoBlockFormat format,
|
||||
{
|
||||
BlockCrypto *crypto = bs->opaque;
|
||||
QemuOpts *opts = NULL;
|
||||
Error *local_err = NULL;
|
||||
int ret = -EINVAL;
|
||||
QCryptoBlockOpenOptions *open_opts = NULL;
|
||||
unsigned int cflags = 0;
|
||||
@ -276,8 +275,7 @@ static int block_crypto_open_generic(QCryptoBlockFormat format,
|
||||
bs->file->bs->supported_write_flags;
|
||||
|
||||
opts = qemu_opts_create(opts_spec, NULL, 0, &error_abort);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, errp)) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -490,8 +490,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
|
||||
OnOffAuto locking;
|
||||
|
||||
opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, errp)) {
|
||||
ret = -EINVAL;
|
||||
goto fail;
|
||||
}
|
||||
@ -999,8 +998,7 @@ static int raw_reopen_prepare(BDRVReopenState *state,
|
||||
|
||||
/* Handle options changes */
|
||||
opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort);
|
||||
if (!qemu_opts_absorb_qdict(opts, state->options, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!qemu_opts_absorb_qdict(opts, state->options, errp)) {
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
@ -338,8 +338,7 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
s->type = FTYPE_FILE;
|
||||
|
||||
opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, errp)) {
|
||||
ret = -EINVAL;
|
||||
goto fail;
|
||||
}
|
||||
@ -738,8 +737,7 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
|
||||
QemuOpts *opts = qemu_opts_create(&raw_runtime_opts, NULL, 0,
|
||||
&error_abort);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, errp)) {
|
||||
ret = -EINVAL;
|
||||
goto done;
|
||||
}
|
||||
|
@ -811,12 +811,10 @@ static int qemu_gluster_open(BlockDriverState *bs, QDict *options,
|
||||
int ret = 0;
|
||||
BlockdevOptionsGluster *gconf = NULL;
|
||||
QemuOpts *opts;
|
||||
Error *local_err = NULL;
|
||||
const char *filename, *logfile;
|
||||
|
||||
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, errp)) {
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
@ -1792,8 +1792,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
int i, ret = 0, timeout = 0, lun;
|
||||
|
||||
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, errp)) {
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
@ -1726,7 +1726,6 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDict *options,
|
||||
SocketAddress *saddr = NULL;
|
||||
QDict *addr = NULL;
|
||||
Visitor *iv = NULL;
|
||||
Error *local_err = NULL;
|
||||
|
||||
qdict_extract_subqdict(options, &addr, "server.");
|
||||
if (!qdict_size(addr)) {
|
||||
@ -1739,8 +1738,7 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDict *options,
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!visit_type_SocketAddress(iv, NULL, &saddr, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!visit_type_SocketAddress(iv, NULL, &saddr, errp)) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
@ -1835,12 +1833,10 @@ static int nbd_process_options(BlockDriverState *bs, QDict *options,
|
||||
{
|
||||
BDRVNBDState *s = bs->opaque;
|
||||
QemuOpts *opts;
|
||||
Error *local_err = NULL;
|
||||
int ret = -EINVAL;
|
||||
|
||||
opts = qemu_opts_create(&nbd_runtime_opts, NULL, 0, &error_abort);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, errp)) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
@ -990,8 +990,7 @@ static int qcow2_update_options_prepare(BlockDriverState *bs,
|
||||
encryptfmt = qdict_get_try_str(encryptopts, "format");
|
||||
|
||||
opts = qemu_opts_create(&qcow2_runtime_opts, NULL, 0, &error_abort);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, errp)) {
|
||||
ret = -EINVAL;
|
||||
goto fail;
|
||||
}
|
||||
@ -1595,8 +1594,7 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
|
||||
|
||||
/* read qcow2 extensions */
|
||||
if (qcow2_read_extensions(bs, header.header_length, ext_end, NULL,
|
||||
flags, &update_header, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
flags, &update_header, errp)) {
|
||||
ret = -EINVAL;
|
||||
goto fail;
|
||||
}
|
||||
@ -3357,7 +3355,6 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
|
||||
int version;
|
||||
int refcount_order;
|
||||
uint64_t* refcount_table;
|
||||
Error *local_err = NULL;
|
||||
int ret;
|
||||
uint8_t compression_type = QCOW2_COMPRESSION_TYPE_ZLIB;
|
||||
|
||||
@ -3583,9 +3580,8 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
|
||||
}
|
||||
blk = blk_new_open(NULL, NULL, options,
|
||||
BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_NO_FLUSH,
|
||||
&local_err);
|
||||
errp);
|
||||
if (blk == NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = -EIO;
|
||||
goto out;
|
||||
}
|
||||
@ -3665,9 +3661,8 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
|
||||
}
|
||||
blk = blk_new_open(NULL, NULL, options,
|
||||
BDRV_O_RDWR | BDRV_O_NO_BACKING | BDRV_O_NO_IO,
|
||||
&local_err);
|
||||
errp);
|
||||
if (blk == NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = -EIO;
|
||||
goto out;
|
||||
}
|
||||
|
@ -74,13 +74,11 @@ static QemuOptsList raw_create_opts = {
|
||||
static int raw_read_options(QDict *options, uint64_t *offset, bool *has_size,
|
||||
uint64_t *size, Error **errp)
|
||||
{
|
||||
Error *local_err = NULL;
|
||||
QemuOpts *opts = NULL;
|
||||
int ret;
|
||||
|
||||
opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, errp)) {
|
||||
ret = -EINVAL;
|
||||
goto end;
|
||||
}
|
||||
|
@ -532,7 +532,6 @@ static SocketAddress *sd_server_config(QDict *options, Error **errp)
|
||||
QDict *server = NULL;
|
||||
Visitor *iv = NULL;
|
||||
SocketAddress *saddr = NULL;
|
||||
Error *local_err = NULL;
|
||||
|
||||
qdict_extract_subqdict(options, &server, "server.");
|
||||
|
||||
@ -541,8 +540,7 @@ static SocketAddress *sd_server_config(QDict *options, Error **errp)
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!visit_type_SocketAddress(iv, NULL, &saddr, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!visit_type_SocketAddress(iv, NULL, &saddr, errp)) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
@ -1549,14 +1547,12 @@ static int sd_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
uint64_t snap_id;
|
||||
char *buf = NULL;
|
||||
QemuOpts *opts;
|
||||
Error *local_err = NULL;
|
||||
|
||||
s->bs = bs;
|
||||
s->aio_context = bdrv_get_aio_context(bs);
|
||||
|
||||
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, errp)) {
|
||||
ret = -EINVAL;
|
||||
goto err_no_fd;
|
||||
}
|
||||
|
@ -622,8 +622,7 @@ static BlockdevOptionsSsh *ssh_parse_options(QDict *options, Error **errp)
|
||||
|
||||
/* Translate legacy options */
|
||||
opts = qemu_opts_create(&ssh_runtime_opts, NULL, 0, &error_abort);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, errp)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
@ -46,11 +46,9 @@ static int throttle_parse_options(QDict *options, char **group, Error **errp)
|
||||
{
|
||||
int ret;
|
||||
const char *group_name;
|
||||
Error *local_err = NULL;
|
||||
QemuOpts *opts = qemu_opts_create(&throttle_opts, NULL, 0, &error_abort);
|
||||
|
||||
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, errp)) {
|
||||
ret = -EINVAL;
|
||||
goto fin;
|
||||
}
|
||||
|
@ -2250,7 +2250,6 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,
|
||||
{
|
||||
int ret;
|
||||
BlockBackend *blk = NULL;
|
||||
Error *local_err = NULL;
|
||||
|
||||
ret = bdrv_create_file(filename, opts, errp);
|
||||
if (ret < 0) {
|
||||
@ -2259,9 +2258,8 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,
|
||||
|
||||
blk = blk_new_open(filename, NULL, NULL,
|
||||
BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL,
|
||||
&local_err);
|
||||
errp);
|
||||
if (blk == NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = -EIO;
|
||||
goto exit;
|
||||
}
|
||||
|
@ -235,8 +235,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
}
|
||||
|
||||
opts = qemu_opts_create(&vpc_runtime_opts, NULL, 0, &error_abort);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, errp)) {
|
||||
ret = -EINVAL;
|
||||
goto fail;
|
||||
}
|
||||
|
@ -1149,8 +1149,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
#endif
|
||||
|
||||
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!qemu_opts_absorb_qdict(opts, options, errp)) {
|
||||
ret = -EINVAL;
|
||||
goto fail;
|
||||
}
|
||||
|
@ -863,8 +863,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type,
|
||||
|
||||
legacy_opts = qemu_opts_create(&qemu_legacy_drive_opts, NULL, 0,
|
||||
&error_abort);
|
||||
if (!qemu_opts_absorb_qdict(legacy_opts, bs_opts, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!qemu_opts_absorb_qdict(legacy_opts, bs_opts, errp)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
@ -376,7 +376,6 @@ static const TypeInfo icp_info = {
|
||||
|
||||
Object *icp_create(Object *cpu, const char *type, XICSFabric *xi, Error **errp)
|
||||
{
|
||||
Error *local_err = NULL;
|
||||
Object *obj;
|
||||
|
||||
obj = object_new(type);
|
||||
@ -384,9 +383,8 @@ Object *icp_create(Object *cpu, const char *type, XICSFabric *xi, Error **errp)
|
||||
object_unref(obj);
|
||||
object_property_set_link(obj, ICP_PROP_XICS, OBJECT(xi), &error_abort);
|
||||
object_property_set_link(obj, ICP_PROP_CPU, cpu, &error_abort);
|
||||
if (!qdev_realize(DEVICE(obj), NULL, &local_err)) {
|
||||
if (!qdev_realize(DEVICE(obj), NULL, errp)) {
|
||||
object_unparent(obj);
|
||||
error_propagate(errp, local_err);
|
||||
obj = NULL;
|
||||
}
|
||||
|
||||
|
@ -292,8 +292,7 @@ static int vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp)
|
||||
qemu_set_fd_handler(fd, vfio_intx_interrupt, NULL, vdev);
|
||||
|
||||
if (vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX, 0,
|
||||
VFIO_IRQ_SET_ACTION_TRIGGER, fd, &err)) {
|
||||
error_propagate(errp, err);
|
||||
VFIO_IRQ_SET_ACTION_TRIGGER, fd, errp)) {
|
||||
qemu_set_fd_handler(fd, NULL, NULL, vdev);
|
||||
event_notifier_cleanup(&vdev->intx.interrupt);
|
||||
return -errno;
|
||||
|
@ -836,9 +836,8 @@ int net_init_tap(const Netdev *netdev, const char *name,
|
||||
}
|
||||
|
||||
for (i = 0; i < nfds; i++) {
|
||||
fd = monitor_fd_param(cur_mon, fds[i], &err);
|
||||
fd = monitor_fd_param(cur_mon, fds[i], errp);
|
||||
if (fd == -1) {
|
||||
error_propagate(errp, err);
|
||||
ret = -1;
|
||||
goto free_fail;
|
||||
}
|
||||
|
@ -1599,11 +1599,9 @@ char *object_property_print(Object *obj, const char *name, bool human,
|
||||
{
|
||||
Visitor *v;
|
||||
char *string = NULL;
|
||||
Error *local_err = NULL;
|
||||
|
||||
v = string_output_visitor_new(human, &string);
|
||||
if (!object_property_get(obj, name, v, &local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
if (!object_property_get(obj, name, v, errp)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user