[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 17/46] qemu-option: Smooth error checking with Coccinelle
From: |
Markus Armbruster |
Subject: |
Re: [PATCH 17/46] qemu-option: Smooth error checking with Coccinelle |
Date: |
Thu, 25 Jun 2020 15:33:15 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) |
Eric Blake <eblake@redhat.com> writes:
> On 6/24/20 11:43 AM, Markus Armbruster wrote:
>> 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:
>>
>
>>
>> Eliminate error_propagate() that are now unnecessary. Delete @err
>> that are now unused. Tidy up line breaks and whitespace.
>>
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>
>> 32 files changed, 70 insertions(+), 192 deletions(-)
>
> Another decent chunk of cleanups.
>
>>
>> diff --git a/block.c b/block.c
>> index 30a72bc4c2..77e85f13db 100644
>> --- a/block.c
>> +++ b/block.c
>
>> @@ -6091,8 +6086,8 @@ void bdrv_img_create(const char *filename, const char
>> *fmt,
>> }
>> if (base_filename) {
>> - qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename,
>> &local_err);
>> - if (local_err) {
>> + if (!qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename,
>> + &local_err)) {
>> error_setg(errp, "Backing file not supported for file format
>> '%s'",
>> fmt);
>
> Pre-existing - it is odd that we collect a message into local_err,
> then write something else into errp; the out: label does
> error_propagate(errp, local_err) which ensures there is no leak but
> discards the original err. You could pass NULL instead. But as it is
> pre-existing, passing NULL should be a separate patch.
PATCH 20.
>> goto out;
>> @@ -6100,8 +6095,7 @@ void bdrv_img_create(const char *filename, const char
>> *fmt,
>> }
>> if (base_fmt) {
>> - qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt, &local_err);
>> - if (local_err) {
>> + if (!qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt,
>> &local_err)) {
>> error_setg(errp, "Backing file format not supported for file "
>> "format '%s'", fmt);
>
> Ditto.
Likewise.
>> +++ b/qemu-img.c
>> @@ -467,8 +467,8 @@ static int add_old_style_options(const char *fmt,
>> QemuOpts *opts,
>> Error *err = NULL;
>> if (base_filename) {
>> - qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename, &err);
>> - if (err) {
>> + if (!qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename,
>> + &err)) {
>> error_report("Backing file not supported for file format '%s'",
>> fmt);
>> error_free(err);
>> @@ -476,8 +476,7 @@ static int add_old_style_options(const char *fmt,
>> QemuOpts *opts,
>> }
>> }
>> if (base_fmt) {
>> - qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt, &err);
>> - if (err) {
>> + if (!qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt, &err)) {
>> error_report("Backing file format not supported for file "
>> "format '%s'", fmt);
>> error_free(err);
>
> Ditto.
PATCH 44.
> But the conversion here is sane.
> Reviewed-by: Eric Blake <eblake@redhat.com>
Thanks!
- Re: [PATCH 30/46] s390x/pci: Fix harmless mistake in zpci's property fid's setter, (continued)
- [PATCH 37/46] qom: Make functions taking Error ** return bool, not void, Markus Armbruster, 2020/06/24
- [PATCH 26/46] qapi: Smooth another visitor error checking pattern, Markus Armbruster, 2020/06/24
- [PATCH 24/46] qapi: Smooth error checking manually, Markus Armbruster, 2020/06/24
- [PATCH 17/46] qemu-option: Smooth error checking with Coccinelle, Markus Armbruster, 2020/06/24
- [PATCH 15/46] qemu-option: Tidy up opt_set() not to free arguments on failure, Markus Armbruster, 2020/06/24
- [PATCH 39/46] qom: Smooth error checking manually, Markus Armbruster, 2020/06/24
- [PATCH 44/46] qemu-img: Ignore Error objects where the return value suffices, Markus Armbruster, 2020/06/24
- [PATCH 07/46] error: Avoid more error_propagate() when error is not used here, Markus Armbruster, 2020/06/24