diff mbox

[2/5] block: Don't try to set *errp directly

Message ID 20170608133906.12737-3-ehabkost@redhat.com
State New
Headers show

Commit Message

Eduardo Habkost June 8, 2017, 1:39 p.m. UTC
Assigning directly to *errp is not valid, as errp may be NULL,
&error_fatal, or &error_abort.  Use error_propagate() instead.

With this, there's no need to check if errp is NULL anymore, as
error_propagate() and error_prepend() are able to handle that.

Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Max Reitz <mreitz@redhat.com>
Cc: qemu-block@nongnu.org
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 block.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Alberto Garcia June 8, 2017, 3:04 p.m. UTC | #1
On Thu 08 Jun 2017 03:39:03 PM CEST, Eduardo Habkost wrote:
> Assigning directly to *errp is not valid, as errp may be NULL,
> &error_fatal, or &error_abort.  Use error_propagate() instead.

Well, the NULL case was already handled by the code, but &error_fatal
and &error_abort certainly not.

> With this, there's no need to check if errp is NULL anymore, as
> error_propagate() and error_prepend() are able to handle that.
>
> Cc: Kevin Wolf <kwolf@redhat.com>
> Cc: Max Reitz <mreitz@redhat.com>
> Cc: qemu-block@nongnu.org
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>

Reviewed-by: Alberto Garcia <berto@igalia.com>

Berto
Markus Armbruster July 5, 2017, 11:50 a.m. UTC | #2
Eduardo Habkost <ehabkost@redhat.com> writes:

> Assigning directly to *errp is not valid, as errp may be NULL,
> &error_fatal, or &error_abort.  Use error_propagate() instead.
>
> With this, there's no need to check if errp is NULL anymore, as
> error_propagate() and error_prepend() are able to handle that.
>
> Cc: Kevin Wolf <kwolf@redhat.com>
> Cc: Max Reitz <mreitz@redhat.com>
> Cc: qemu-block@nongnu.org
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  block.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/block.c b/block.c
> index fa1d06d846..1750a1838e 100644
> --- a/block.c
> +++ b/block.c
> @@ -4263,11 +4263,9 @@ bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp)
>      assert((int) op >= 0 && op < BLOCK_OP_TYPE_MAX);
>      if (!QLIST_EMPTY(&bs->op_blockers[op])) {
>          blocker = QLIST_FIRST(&bs->op_blockers[op]);
> -        if (errp) {
> -            *errp = error_copy(blocker->reason);
> -            error_prepend(errp, "Node '%s' is busy: ",
> -                          bdrv_get_device_or_node_name(bs));
> -        }
> +        error_propagate(errp, error_copy(blocker->reason));
> +        error_prepend(errp, "Node '%s' is busy: ",
> +                      bdrv_get_device_or_node_name(bs));
>          return true;
>      }
>      return false;

Reviewed-by: Markus Armbruster <armbru@redhat.com>
diff mbox

Patch

diff --git a/block.c b/block.c
index fa1d06d846..1750a1838e 100644
--- a/block.c
+++ b/block.c
@@ -4263,11 +4263,9 @@  bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp)
     assert((int) op >= 0 && op < BLOCK_OP_TYPE_MAX);
     if (!QLIST_EMPTY(&bs->op_blockers[op])) {
         blocker = QLIST_FIRST(&bs->op_blockers[op]);
-        if (errp) {
-            *errp = error_copy(blocker->reason);
-            error_prepend(errp, "Node '%s' is busy: ",
-                          bdrv_get_device_or_node_name(bs));
-        }
+        error_propagate(errp, error_copy(blocker->reason));
+        error_prepend(errp, "Node '%s' is busy: ",
+                      bdrv_get_device_or_node_name(bs));
         return true;
     }
     return false;