From patchwork Mon Jun 13 21:57:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 9174459 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 459646044F for ; Mon, 13 Jun 2016 21:58:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3538B27C0C for ; Mon, 13 Jun 2016 21:58:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 28B6E27D07; Mon, 13 Jun 2016 21:58:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 141C327C0C for ; Mon, 13 Jun 2016 21:58:51 +0000 (UTC) Received: from localhost ([::1]:59616 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCZsg-0003uB-7W for patchwork-qemu-devel@patchwork.kernel.org; Mon, 13 Jun 2016 17:58:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41019) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCZsG-0003sG-1B for qemu-devel@nongnu.org; Mon, 13 Jun 2016 17:58:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCZs8-0004s5-Rj for qemu-devel@nongnu.org; Mon, 13 Jun 2016 17:58:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40102) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCZs8-0004s1-J3 for qemu-devel@nongnu.org; Mon, 13 Jun 2016 17:58:16 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0EFEE7F6A7 for ; Mon, 13 Jun 2016 21:58:16 +0000 (UTC) Received: from localhost (vpn1-7-192.gru2.redhat.com [10.97.7.192]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5DLwEiK010153; Mon, 13 Jun 2016 17:58:15 -0400 From: Eduardo Habkost To: Markus Armbruster , qemu-devel@nongnu.org Date: Mon, 13 Jun 2016 18:57:56 -0300 Message-Id: <1465855078-19435-2-git-send-email-ehabkost@redhat.com> In-Reply-To: <1465855078-19435-1-git-send-email-ehabkost@redhat.com> References: <1465855078-19435-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 13 Jun 2016 21:58:16 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 1/3] error: Remove NULL checks on error_propagate() calls X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP error_propagate() already ignores local_err==NULL, so there's no need to check it before calling. Coccinelle patch used to perform the changes added to scripts/coccinelle/error_propagate_null.cocci. Reviewed-by: Eric Blake Acked-by: Cornelia Huck Reviewed-by: Markus Armbruster Signed-off-by: Eduardo Habkost --- scripts/coccinelle/error_propagate_null.cocci | 10 ++++++++++ block.c | 20 +++++-------------- block/qcow2.c | 4 +--- block/quorum.c | 4 +--- block/raw-posix.c | 16 ++++----------- block/raw_bsd.c | 4 +--- block/snapshot.c | 4 +--- blockdev.c | 12 +++--------- bootdevice.c | 4 +--- dump.c | 4 +--- hw/ide/qdev.c | 4 +--- hw/net/ne2000-isa.c | 4 +--- hw/s390x/virtio-ccw.c | 28 +++++++-------------------- hw/usb/dev-storage.c | 4 +--- qga/commands-win32.c | 8 ++------ qom/object.c | 4 +--- 16 files changed, 41 insertions(+), 93 deletions(-) create mode 100644 scripts/coccinelle/error_propagate_null.cocci diff --git a/scripts/coccinelle/error_propagate_null.cocci b/scripts/coccinelle/error_propagate_null.cocci new file mode 100644 index 0000000..c236380 --- /dev/null +++ b/scripts/coccinelle/error_propagate_null.cocci @@ -0,0 +1,10 @@ +// error_propagate() already ignores local_err==NULL, so there's +// no need to check it before calling. + +@@ +identifier L; +expression E; +@@ +-if (L) { + error_propagate(E, L); +-} diff --git a/block.c b/block.c index f54bc25..ecca55a 100644 --- a/block.c +++ b/block.c @@ -301,9 +301,7 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque) assert(cco->drv); ret = cco->drv->bdrv_create(cco->filename, cco->opts, &local_err); - if (local_err) { - error_propagate(&cco->err, local_err); - } + error_propagate(&cco->err, local_err); cco->ret = ret; } @@ -364,9 +362,7 @@ int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp) } ret = bdrv_create(drv, filename, opts, &local_err); - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); return ret; } @@ -1760,18 +1756,14 @@ fail: QDECREF(options); bs->options = NULL; bdrv_unref(bs); - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); return NULL; close_and_fail: bdrv_unref(bs); QDECREF(snapshot_options); QDECREF(options); - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); return NULL; } @@ -3591,9 +3583,7 @@ void bdrv_img_create(const char *filename, const char *fmt, out: qemu_opts_del(opts); qemu_opts_free(create_opts); - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); } AioContext *bdrv_get_aio_context(BlockDriverState *bs) diff --git a/block/qcow2.c b/block/qcow2.c index 6f5fb81..4504846 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2394,9 +2394,7 @@ static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp) ret = qcow2_create2(filename, size, backing_file, backing_fmt, flags, cluster_size, prealloc, opts, version, refcount_order, &local_err); - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); finish: g_free(backing_file); diff --git a/block/quorum.c b/block/quorum.c index ec6f3b9..331b726 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -971,9 +971,7 @@ close_exit: exit: qemu_opts_del(opts); /* propagate error */ - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); return ret; } diff --git a/block/raw-posix.c b/block/raw-posix.c index ce2e20f..cb663d8 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -587,9 +587,7 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags, s->type = FTYPE_FILE; ret = raw_open_common(bs, options, flags, 0, &local_err); - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); return ret; } @@ -2239,9 +2237,7 @@ hdev_open_Mac_error: ret = raw_open_common(bs, options, flags, 0, &local_err); if (ret < 0) { - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); #if defined(__APPLE__) && defined(__MACH__) if (*bsd_path) { filename = bsd_path; @@ -2453,9 +2449,7 @@ static int cdrom_open(BlockDriverState *bs, QDict *options, int flags, /* open will not fail even if no CD is inserted, so add O_NONBLOCK */ ret = raw_open_common(bs, options, flags, O_NONBLOCK, &local_err); - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); return ret; } @@ -2573,9 +2567,7 @@ static int cdrom_open(BlockDriverState *bs, QDict *options, int flags, ret = raw_open_common(bs, options, flags, 0, &local_err); if (ret) { - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); return ret; } diff --git a/block/raw_bsd.c b/block/raw_bsd.c index b1d5237..5af11b6 100644 --- a/block/raw_bsd.c +++ b/block/raw_bsd.c @@ -194,9 +194,7 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp) int ret; ret = bdrv_create_file(filename, opts, &local_err); - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); return ret; } diff --git a/block/snapshot.c b/block/snapshot.c index da89d2b..bf5c2ca 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -358,9 +358,7 @@ int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverState *bs, ret = bdrv_snapshot_load_tmp(bs, NULL, id_or_name, &local_err); } - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); return ret; } diff --git a/blockdev.c b/blockdev.c index 7fd515a..028dba3 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3633,9 +3633,7 @@ void qmp_drive_mirror(const char *device, const char *target, has_unmap, unmap, &local_err); bdrv_unref(target_bs); - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); out: aio_context_release(aio_context); } @@ -3689,9 +3687,7 @@ void qmp_blockdev_mirror(const char *device, const char *target, has_on_target_error, on_target_error, true, true, &local_err); - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); aio_context_release(aio_context); } @@ -3901,9 +3897,7 @@ void qmp_change_backing_file(const char *device, if (ro) { bdrv_reopen(image_bs, open_flags, &local_err); - if (local_err) { - error_propagate(errp, local_err); /* will preserve prior errp */ - } + error_propagate(errp, local_err); } out: diff --git a/bootdevice.c b/bootdevice.c index bb9c08e..33e3029 100644 --- a/bootdevice.c +++ b/bootdevice.c @@ -302,9 +302,7 @@ static void device_set_bootindex(Object *obj, Visitor *v, const char *name, add_boot_device_path(*prop->bootindex, prop->dev, prop->suffix); out: - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); } static void property_release_bootindex(Object *obj, const char *name, diff --git a/dump.c b/dump.c index 9726f1f..f7b80d8 100644 --- a/dump.c +++ b/dump.c @@ -918,9 +918,7 @@ static void write_dump_header(DumpState *s, Error **errp) } else { create_header64(s, &local_err); } - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); } static size_t dump_bitmap_get_bufsize(DumpState *s) diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index 4bc74a3..6842a55 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -233,9 +233,7 @@ static void ide_dev_set_bootindex(Object *obj, Visitor *v, const char *name, d->unit ? "/disk@1" : "/disk@0"); } out: - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); } static void ide_dev_instance_init(Object *obj) diff --git a/hw/net/ne2000-isa.c b/hw/net/ne2000-isa.c index a7f5a94..8fab7ae 100644 --- a/hw/net/ne2000-isa.c +++ b/hw/net/ne2000-isa.c @@ -127,9 +127,7 @@ static void isa_ne2000_set_bootindex(Object *obj, Visitor *v, s->c.bootindex = boot_index; out: - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); } static void isa_ne2000_instance_init(Object *obj) diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c index 2b68e5e..464b091 100644 --- a/hw/s390x/virtio-ccw.c +++ b/hw/s390x/virtio-ccw.c @@ -905,9 +905,7 @@ static void virtio_ccw_net_realize(VirtioCcwDevice *ccw_dev, Error **errp) object_get_typename(OBJECT(qdev))); qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); object_property_set_bool(OBJECT(vdev), true, "realized", &err); - if (err) { - error_propagate(errp, err); - } + error_propagate(errp, err); } static void virtio_ccw_net_instance_init(Object *obj) @@ -928,9 +926,7 @@ static void virtio_ccw_blk_realize(VirtioCcwDevice *ccw_dev, Error **errp) qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); object_property_set_bool(OBJECT(vdev), true, "realized", &err); - if (err) { - error_propagate(errp, err); - } + error_propagate(errp, err); } static void virtio_ccw_blk_instance_init(Object *obj) @@ -965,9 +961,7 @@ static void virtio_ccw_serial_realize(VirtioCcwDevice *ccw_dev, Error **errp) qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); object_property_set_bool(OBJECT(vdev), true, "realized", &err); - if (err) { - error_propagate(errp, err); - } + error_propagate(errp, err); } @@ -987,9 +981,7 @@ static void virtio_ccw_balloon_realize(VirtioCcwDevice *ccw_dev, Error **errp) qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); object_property_set_bool(OBJECT(vdev), true, "realized", &err); - if (err) { - error_propagate(errp, err); - } + error_propagate(errp, err); } static void virtio_ccw_balloon_instance_init(Object *obj) @@ -1025,9 +1017,7 @@ static void virtio_ccw_scsi_realize(VirtioCcwDevice *ccw_dev, Error **errp) qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); object_property_set_bool(OBJECT(vdev), true, "realized", &err); - if (err) { - error_propagate(errp, err); - } + error_propagate(errp, err); } static void virtio_ccw_scsi_instance_init(Object *obj) @@ -1049,9 +1039,7 @@ static void vhost_ccw_scsi_realize(VirtioCcwDevice *ccw_dev, Error **errp) qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); object_property_set_bool(OBJECT(vdev), true, "realized", &err); - if (err) { - error_propagate(errp, err); - } + error_propagate(errp, err); } static void vhost_ccw_scsi_instance_init(Object *obj) @@ -1872,9 +1860,7 @@ static void virtio_ccw_9p_realize(VirtioCcwDevice *ccw_dev, Error **errp) qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); object_property_set_bool(OBJECT(vdev), true, "realized", &err); - if (err) { - error_propagate(errp, err); - } + error_propagate(errp, err); } static void virtio_ccw_9p_class_init(ObjectClass *klass, void *data) diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index 248a580..9fd00df 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -818,9 +818,7 @@ static void usb_msd_set_bootindex(Object *obj, Visitor *v, const char *name, } out: - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); } static const TypeInfo usb_storage_dev_type_info = { diff --git a/qga/commands-win32.c b/qga/commands-win32.c index c1a8588..ea23797 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -247,9 +247,7 @@ out: if (token) { CloseHandle(token); } - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); } static void execute_async(DWORD WINAPI (*func)(LPVOID), LPVOID opaque, @@ -882,9 +880,7 @@ static void check_suspend_mode(GuestSuspendMode mode, Error **errp) } out: - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); } static DWORD WINAPI do_suspend(LPVOID opaque) diff --git a/qom/object.c b/qom/object.c index 3bc8a00..7ba5917 100644 --- a/qom/object.c +++ b/qom/object.c @@ -541,9 +541,7 @@ Object *object_new_with_propv(const char *typename, return obj; error: - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); object_unref(obj); return NULL; }