block: check return value of bdrv_open_child and drop error propagation

This patch is generated by cocci script:

@@
symbol bdrv_open_child, errp, local_err;
expression file;
@@

  file = bdrv_open_child(...,
-                        &local_err
+                        errp
                        );
- if (local_err)
+ if (!file)
  {
      ...
-     error_propagate(errp, local_err);
      ...
  }

with command

spatch --sp-file x.cocci --macro-file scripts/cocci-macro-file.h \
--in-place --no-show-diff --max-width 80 --use-gitgrep block

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Message-Id: <20210202124956.63146-4-vsementsov@virtuozzo.com>
[eblake: fix qcow2_do_open() to use ERRP_GUARD, necessary as the only
caller to pass allow_none=true]
Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Vladimir Sementsov-Ogievskiy 2021-02-02 15:49:45 +03:00 committed by Eric Blake
parent f174cd3350
commit bc52024959
6 changed files with 17 additions and 28 deletions

View file

@ -464,7 +464,6 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
{ {
BDRVBlkdebugState *s = bs->opaque; BDRVBlkdebugState *s = bs->opaque;
QemuOpts *opts; QemuOpts *opts;
Error *local_err = NULL;
int ret; int ret;
uint64_t align; uint64_t align;
@ -494,10 +493,9 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
bs->file = bdrv_open_child(qemu_opt_get(opts, "x-image"), options, "image", bs->file = bdrv_open_child(qemu_opt_get(opts, "x-image"), options, "image",
bs, &child_of_bds, bs, &child_of_bds,
BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY,
false, &local_err); false, errp);
if (local_err) { if (!bs->file) {
ret = -EINVAL; ret = -EINVAL;
error_propagate(errp, local_err);
goto out; goto out;
} }

View file

@ -157,19 +157,17 @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags,
/* Open the file */ /* Open the file */
bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, false, BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, false,
&local_err); errp);
if (local_err) { if (!bs->file) {
ret = -EINVAL; ret = -EINVAL;
error_propagate(errp, local_err);
goto fail; goto fail;
} }
/* Open the log file */ /* Open the log file */
s->log_file = bdrv_open_child(NULL, options, "log", bs, &child_of_bds, s->log_file = bdrv_open_child(NULL, options, "log", bs, &child_of_bds,
BDRV_CHILD_METADATA, false, &local_err); BDRV_CHILD_METADATA, false, errp);
if (local_err) { if (!s->log_file) {
ret = -EINVAL; ret = -EINVAL;
error_propagate(errp, local_err);
goto fail; goto fail;
} }

View file

@ -23,16 +23,14 @@ typedef struct Request {
static int blkreplay_open(BlockDriverState *bs, QDict *options, int flags, static int blkreplay_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp) Error **errp)
{ {
Error *local_err = NULL;
int ret; int ret;
/* Open the image file */ /* Open the image file */
bs->file = bdrv_open_child(NULL, options, "image", bs, &child_of_bds, bs->file = bdrv_open_child(NULL, options, "image", bs, &child_of_bds,
BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY,
false, &local_err); false, errp);
if (local_err) { if (!bs->file) {
ret = -EINVAL; ret = -EINVAL;
error_propagate(errp, local_err);
goto fail; goto fail;
} }

View file

@ -112,7 +112,6 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,
{ {
BDRVBlkverifyState *s = bs->opaque; BDRVBlkverifyState *s = bs->opaque;
QemuOpts *opts; QemuOpts *opts;
Error *local_err = NULL;
int ret; int ret;
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
@ -125,20 +124,18 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,
bs->file = bdrv_open_child(qemu_opt_get(opts, "x-raw"), options, "raw", bs->file = bdrv_open_child(qemu_opt_get(opts, "x-raw"), options, "raw",
bs, &child_of_bds, bs, &child_of_bds,
BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY,
false, &local_err); false, errp);
if (local_err) { if (!bs->file) {
ret = -EINVAL; ret = -EINVAL;
error_propagate(errp, local_err);
goto fail; goto fail;
} }
/* Open the test file */ /* Open the test file */
s->test_file = bdrv_open_child(qemu_opt_get(opts, "x-image"), options, s->test_file = bdrv_open_child(qemu_opt_get(opts, "x-image"), options,
"test", bs, &child_of_bds, BDRV_CHILD_DATA, "test", bs, &child_of_bds, BDRV_CHILD_DATA,
false, &local_err); false, errp);
if (local_err) { if (!s->test_file) {
ret = -EINVAL; ret = -EINVAL;
error_propagate(errp, local_err);
goto fail; goto fail;
} }

View file

@ -1292,6 +1292,7 @@ static int validate_compression_type(BDRVQcow2State *s, Error **errp)
static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
int flags, Error **errp) int flags, Error **errp)
{ {
ERRP_GUARD();
BDRVQcow2State *s = bs->opaque; BDRVQcow2State *s = bs->opaque;
unsigned int len, i; unsigned int len, i;
int ret = 0; int ret = 0;
@ -1611,9 +1612,8 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
/* Open external data file */ /* Open external data file */
s->data_file = bdrv_open_child(NULL, options, "data-file", bs, s->data_file = bdrv_open_child(NULL, options, "data-file", bs,
&child_of_bds, BDRV_CHILD_DATA, &child_of_bds, BDRV_CHILD_DATA,
true, &local_err); true, errp);
if (local_err) { if (*errp) {
error_propagate(errp, local_err);
ret = -EINVAL; ret = -EINVAL;
goto fail; goto fail;
} }

View file

@ -929,7 +929,6 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp) Error **errp)
{ {
BDRVQuorumState *s = bs->opaque; BDRVQuorumState *s = bs->opaque;
Error *local_err = NULL;
QemuOpts *opts = NULL; QemuOpts *opts = NULL;
const char *pattern_str; const char *pattern_str;
bool *opened; bool *opened;
@ -1007,9 +1006,8 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
s->children[i] = bdrv_open_child(NULL, options, indexstr, bs, s->children[i] = bdrv_open_child(NULL, options, indexstr, bs,
&child_of_bds, BDRV_CHILD_DATA, false, &child_of_bds, BDRV_CHILD_DATA, false,
&local_err); errp);
if (local_err) { if (!s->children[i]) {
error_propagate(errp, local_err);
ret = -EINVAL; ret = -EINVAL;
goto close_exit; goto close_exit;
} }