From nobody Tue Feb 10 15:44:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501071174798597.4338328015583; Wed, 26 Jul 2017 05:12:54 -0700 (PDT) Received: from localhost ([::1]:37879 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1daLBH-0000KZ-Mr for importer@patchew.org; Wed, 26 Jul 2017 08:12:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34267) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1daL2q-0001QX-7t for qemu-devel@nongnu.org; Wed, 26 Jul 2017 08:04:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1daL2o-0000ER-TD for qemu-devel@nongnu.org; Wed, 26 Jul 2017 08:04:04 -0400 Received: from [59.151.112.132] (port=1336 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1daL2f-0008RW-Ah; Wed, 26 Jul 2017 08:03:53 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 26 Jul 2017 20:03:45 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id BF63240144EA; Wed, 26 Jul 2017 20:03:43 +0800 (CST) Received: from maozy.g08.fujitsu.local (10.167.225.76) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 26 Jul 2017 20:03:43 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="21843095" From: Mao Zhongyi To: , Date: Wed, 26 Jul 2017 20:02:53 +0800 Message-ID: <20170726120255.14292-5-maozy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170726120255.14292-1-maozy.fnst@cn.fujitsu.com> References: <20170726120255.14292-1-maozy.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.225.76] X-yoursite-MailScanner-ID: BF63240144EA.A0042 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: maozy.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH 4/6] hw/block: Fix the return type 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: , Cc: Kevin Wolf , John Snow , Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When the function no success value to transmit, it usually make the function return void. It has turned out not to be a success, because it means that the extra local_err variable and error_propagate() will be needed. It leads to cumbersome code, therefore, transmit success/ failure in the return value is worth. So fix the return type of blkconf_apply_backend_options(), blkconf_geometry() and virtio_blk_data_plane_create() to avoid it. Cc: John Snow Cc: Kevin Wolf Cc: Max Reitz Cc: Stefan Hajnoczi Signed-off-by: Mao Zhongyi --- hw/block/block.c | 21 ++++++++++++--------- hw/block/dataplane/virtio-blk.c | 16 +++++++++------- hw/block/dataplane/virtio-blk.h | 6 +++--- include/hw/block/block.h | 10 +++++----- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/hw/block/block.c b/hw/block/block.c index 27878d0..717bd0e 100644 --- a/hw/block/block.c +++ b/hw/block/block.c @@ -51,8 +51,8 @@ void blkconf_blocksizes(BlockConf *conf) } } =20 -void blkconf_apply_backend_options(BlockConf *conf, bool readonly, - bool resizable, Error **errp) +int blkconf_apply_backend_options(BlockConf *conf, bool readonly, + bool resizable, Error **errp) { BlockBackend *blk =3D conf->blk; BlockdevOnError rerror, werror; @@ -76,7 +76,7 @@ void blkconf_apply_backend_options(BlockConf *conf, bool = readonly, =20 ret =3D blk_set_perm(blk, perm, shared_perm, errp); if (ret < 0) { - return; + return -1; } =20 switch (conf->wce) { @@ -99,11 +99,13 @@ void blkconf_apply_backend_options(BlockConf *conf, boo= l readonly, =20 blk_set_enable_write_cache(blk, wce); blk_set_on_error(blk, rerror, werror); + + return 0; } =20 -void blkconf_geometry(BlockConf *conf, int *ptrans, - unsigned cyls_max, unsigned heads_max, unsigned secs= _max, - Error **errp) +int blkconf_geometry(BlockConf *conf, int *ptrans, + unsigned cyls_max, unsigned heads_max, unsigned secs_= max, + Error **errp) { DriveInfo *dinfo; =20 @@ -129,15 +131,16 @@ void blkconf_geometry(BlockConf *conf, int *ptrans, if (conf->cyls || conf->heads || conf->secs) { if (conf->cyls < 1 || conf->cyls > cyls_max) { error_setg(errp, "cyls must be between 1 and %u", cyls_max); - return; + return -1; } if (conf->heads < 1 || conf->heads > heads_max) { error_setg(errp, "heads must be between 1 and %u", heads_max); - return; + return -1; } if (conf->secs < 1 || conf->secs > secs_max) { error_setg(errp, "secs must be between 1 and %u", secs_max); - return; + return -1; } } + return 0; } diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-bl= k.c index 5556f0e..619bc5e 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -76,9 +76,9 @@ static void notify_guest_bh(void *opaque) } =20 /* Context: QEMU global mutex held */ -void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf, - VirtIOBlockDataPlane **dataplane, - Error **errp) +int virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf, + VirtIOBlockDataPlane **dataplane, + Error **errp) { VirtIOBlockDataPlane *s; BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); @@ -91,11 +91,11 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, V= irtIOBlkConf *conf, error_setg(errp, "device is incompatible with iothread " "(transport does not support notifiers)"); - return; + return -1; } if (!virtio_device_ioeventfd_enabled(vdev)) { error_setg(errp, "ioeventfd is required for iothread"); - return; + return -1; } =20 /* If dataplane is (re-)enabled while the guest is running there c= ould @@ -103,12 +103,12 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev,= VirtIOBlkConf *conf, */ if (blk_op_is_blocked(conf->conf.blk, BLOCK_OP_TYPE_DATAPLANE, err= p)) { error_prepend(errp, "cannot start virtio-blk dataplane: "); - return; + return -1; } } /* Don't try if transport does not support notifiers. */ if (!virtio_device_ioeventfd_enabled(vdev)) { - return; + return -1; } =20 s =3D g_new0(VirtIOBlockDataPlane, 1); @@ -126,6 +126,8 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, V= irtIOBlkConf *conf, s->batch_notify_vqs =3D bitmap_new(conf->num_queues); =20 *dataplane =3D s; + + return 0; } =20 /* Context: QEMU global mutex held */ diff --git a/hw/block/dataplane/virtio-blk.h b/hw/block/dataplane/virtio-bl= k.h index db3f47b..d25773d 100644 --- a/hw/block/dataplane/virtio-blk.h +++ b/hw/block/dataplane/virtio-blk.h @@ -19,9 +19,9 @@ =20 typedef struct VirtIOBlockDataPlane VirtIOBlockDataPlane; =20 -void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf, - VirtIOBlockDataPlane **dataplane, - Error **errp); +int virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf, + VirtIOBlockDataPlane **dataplane, + Error **errp); void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s); void virtio_blk_data_plane_notify(VirtIOBlockDataPlane *s, VirtQueue *vq); =20 diff --git a/include/hw/block/block.h b/include/hw/block/block.h index f3f6e8e..66117c6 100644 --- a/include/hw/block/block.h +++ b/include/hw/block/block.h @@ -72,12 +72,12 @@ static inline unsigned int get_physical_block_exp(Block= Conf *conf) /* Configuration helpers */ =20 void blkconf_serial(BlockConf *conf, char **serial); -void blkconf_geometry(BlockConf *conf, int *trans, - unsigned cyls_max, unsigned heads_max, unsigned secs= _max, - Error **errp); +int blkconf_geometry(BlockConf *conf, int *trans, + unsigned cyls_max, unsigned heads_max, unsigned secs_= max, + Error **errp); void blkconf_blocksizes(BlockConf *conf); -void blkconf_apply_backend_options(BlockConf *conf, bool readonly, - bool resizable, Error **errp); +int blkconf_apply_backend_options(BlockConf *conf, bool readonly, + bool resizable, Error **errp); =20 /* Hard disk geometry */ =20 --=20 2.9.4