From 235e59cf03ed75d0ce96c97343194ed11c146231 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 7 Jul 2020 18:05:42 +0200 Subject: qemu-option: Use returned bool to check for failure The previous commit enables conversion of foo(..., &err); if (err) { ... } to if (!foo(..., &err)) { ... } for QemuOpts functions that now return true / false on success / error. Coccinelle script: @@ identifier fun = { opts_do_parse, parse_option_bool, parse_option_number, parse_option_size, qemu_opt_parse, qemu_opt_rename, qemu_opt_set, qemu_opt_set_bool, qemu_opt_set_number, qemu_opts_absorb_qdict, qemu_opts_do_parse, qemu_opts_from_qdict_entry, qemu_opts_set, qemu_opts_validate }; expression list args, args2; typedef Error; Error *err; @@ - fun(args, &err, args2); - if (err) + if (!fun(args, &err, args2)) { ... } A few line breaks tidied up manually. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Message-Id: <20200707160613.848843-15-armbru@redhat.com> [Conflict with commit 0b6786a9c1 "block/amend: refactor qcow2 amend options" resolved by rerunning Coccinelle on master's version] --- blockdev.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'blockdev.c') diff --git a/blockdev.c b/blockdev.c index 39e12a6..625c8ff 100644 --- a/blockdev.c +++ b/blockdev.c @@ -509,8 +509,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts, goto err_no_opts; } - qemu_opts_absorb_qdict(opts, bs_opts, &error); - if (error) { + if (!qemu_opts_absorb_qdict(opts, bs_opts, &error)) { error_propagate(errp, error); goto early_err; } @@ -827,9 +826,8 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type, }; for (i = 0; i < ARRAY_SIZE(opt_renames); i++) { - qemu_opt_rename(all_opts, opt_renames[i].from, opt_renames[i].to, - &local_err); - if (local_err) { + if (!qemu_opt_rename(all_opts, opt_renames[i].from, + opt_renames[i].to, &local_err)) { error_propagate(errp, local_err); return NULL; } @@ -867,8 +865,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type, legacy_opts = qemu_opts_create(&qemu_legacy_drive_opts, NULL, 0, &error_abort); - qemu_opts_absorb_qdict(legacy_opts, bs_opts, &local_err); - if (local_err) { + if (!qemu_opts_absorb_qdict(legacy_opts, bs_opts, &local_err)) { error_propagate(errp, local_err); goto fail; } -- cgit v1.1