[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-block] [Qemu-devel] [PATCH v2 2/3] error: Remove unnecessary l
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-block] [Qemu-devel] [PATCH v2 2/3] error: Remove unnecessary local_err variables |
Date: |
Mon, 13 Jun 2016 13:42:15 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
Eduardo Habkost <address@hidden> writes:
> This patch simplifies code that uses a local_err variable just to
> immediately use it for an error_propagate() call.
>
> Coccinelle patch used to perform the changes added to
> scripts/coccinelle/remove_local_err.cocci.
>
> Signed-off-by: Eduardo Habkost <address@hidden>
[...]
> diff --git a/scripts/coccinelle/remove_local_err.cocci
> b/scripts/coccinelle/remove_local_err.cocci
> new file mode 100644
> index 0000000..5f0b6c0
> --- /dev/null
> +++ b/scripts/coccinelle/remove_local_err.cocci
> @@ -0,0 +1,27 @@
> +// Replace unnecessary usage of local_err variable with
> +// direct usage of errp argument
> +
> +@@
> +expression list ARGS;
> +expression F2;
> +identifier LOCAL_ERR;
> +expression ERRP;
> +idexpression V;
> +typedef Error;
> +expression I;
I isn't used.
> +@@
> + {
> + ...
> +- Error *LOCAL_ERR;
> + ... when != LOCAL_ERR
> +(
> +- F2(ARGS, &LOCAL_ERR);
> +- error_propagate(ERRP, LOCAL_ERR);
> ++ F2(ARGS, ERRP);
> +|
> +- V = F2(ARGS, &LOCAL_ERR);
> +- error_propagate(ERRP, LOCAL_ERR);
> ++ V = F2(ARGS, ERRP);
> +)
> + ... when != LOCAL_ERR
> + }
There is an (ugly) difference between
error_setg(&local_err, ...);
error_propagate(errp, &local_err);
and
error_setg(errp, ...);
The latter aborts when @errp already contains an error, the former does
nothing.
Your transformation has the error_setg() or similar hidden in F2(). It
can add aborts.
I think it can be salvaged: we know that @errp must not contain an error
on function entry. If @errp doesn't occur elsewhere in this function,
it cannot pick up an error on the way to the transformed spot. Can you
add that to your when constraints?
[...]
- [Qemu-block] [PATCH v2 0/3] coccinelle: Clean up error checks and return value variables, Eduardo Habkost, 2016/06/10
- [Qemu-block] [PATCH v2 2/3] error: Remove unnecessary local_err variables, Eduardo Habkost, 2016/06/10
- Re: [Qemu-block] [PATCH v2 2/3] error: Remove unnecessary local_err variables, Eric Blake, 2016/06/10
- Re: [Qemu-block] [PATCH v2 2/3] error: Remove unnecessary local_err variables, Cornelia Huck, 2016/06/13
- Re: [Qemu-block] [Qemu-devel] [PATCH v2 2/3] error: Remove unnecessary local_err variables,
Markus Armbruster <=
- Re: [Qemu-block] [Qemu-devel] [PATCH v2 2/3] error: Remove unnecessary local_err variables, Eduardo Habkost, 2016/06/13
- Re: [Qemu-block] [Qemu-devel] [PATCH v2 2/3] error: Remove unnecessary local_err variables, Eric Blake, 2016/06/13
- Re: [Qemu-block] [Qemu-devel] [PATCH v2 2/3] error: Remove unnecessary local_err variables, Markus Armbruster, 2016/06/13
- Re: [Qemu-block] [Qemu-devel] [PATCH v2 2/3] error: Remove unnecessary local_err variables, Eduardo Habkost, 2016/06/13
- Re: [Qemu-block] [Qemu-devel] [PATCH v2 2/3] error: Remove unnecessary local_err variables, Markus Armbruster, 2016/06/14
- Re: [Qemu-block] [Qemu-devel] [PATCH v2 2/3] error: Remove unnecessary local_err variables, Eduardo Habkost, 2016/06/13
[Qemu-block] [RFC v2 3/3] Remove unnecessary variables for function return value, Eduardo Habkost, 2016/06/10