From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60330) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XePgK-0000di-Kp for qemu-devel@nongnu.org; Wed, 15 Oct 2014 10:36:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XePgF-0008HR-LL for qemu-devel@nongnu.org; Wed, 15 Oct 2014 10:36:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10052) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XePgF-0008HF-Dx for qemu-devel@nongnu.org; Wed, 15 Oct 2014 10:35:59 -0400 Message-ID: <543E8649.7050006@redhat.com> Date: Wed, 15 Oct 2014 08:35:53 -0600 From: Eric Blake MIME-Version: 1.0 References: <1413371003-43597-1-git-send-email-imammedo@redhat.com> <1413371003-43597-3-git-send-email-imammedo@redhat.com> In-Reply-To: <1413371003-43597-3-git-send-email-imammedo@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="vMS69d09w6VprIIbSNIRxKN2fVVs1eiuS" Subject: Re: [Qemu-devel] [PATCH 2/2] vl.c: reduce exit on error code duplication List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Igor Mammedov , qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, aliguori@amazon.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --vMS69d09w6VprIIbSNIRxKN2fVVs1eiuS Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 10/15/2014 05:03 AM, Igor Mammedov wrote: > use exit_if_error() helper instead of a bunch of > if (local_err) { > error_report(foo); > error_free(local_err); > exit(1); > } > code blocks >=20 > Signed-off-by: Igor Mammedov > --- > vl.c | 58 ++++++++++++++++++++++++++++++---------------------------- > 1 file changed, 30 insertions(+), 28 deletions(-) Not much net change, but I like the refactoring. > static int default_driver_check(QemuOpts *opts, void *opaque) > { > const char *driver =3D qemu_opt_get(opts, "driver"); > @@ -2380,11 +2404,7 @@ static int chardev_init_func(QemuOpts *opts, voi= d *opaque) > Error *local_err =3D NULL; > =20 > qemu_chr_new_from_opts(opts, NULL, &local_err); > - if (local_err) { > - error_report("%s", error_get_pretty(local_err)); > - error_free(local_err); > - return -1; > - } > + exit_if_error(local_err, NULL); > return 0; > } Idea for followup patch: this function now always returns 0 (if it returns at all); therefore, change its signature to void and simplify further. > =20 > @@ -2790,12 +2810,7 @@ static int machine_set_property(const char *name= , const char *value, > string_input_visitor_cleanup(siv); > g_free(qom_name); > =20 > - if (local_err) { > - qerror_report_err(local_err); > - error_free(local_err); > - return -1; > - } > - > + exit_if_error(local_err, NULL); > return 0; > } Same idea for simplification. But as that should be a separate patch, this one is: Reviewed-by: Eric Blake --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --vMS69d09w6VprIIbSNIRxKN2fVVs1eiuS Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg iQEcBAEBCAAGBQJUPoZJAAoJEKeha0olJ0NqVuMH/36NBvQnsQYyhvzHRotgQDk3 WX5BLq9SkQ1JRC3T4fcirNhv5zoYuqCTw+mBhI+6Zr7eu1BoVs+GlMaO9rMspDum zR1Fmb/V3jtbWKF8wD0W62GqwVoFTYcI0D9+1DWyRCJ4zmJyCPo6i2J+dk9rJmAX putm+o3v3eqF17hsVnUfQIx0rODLzYod5rNWdqDgzV5U4iyn883ZBWu1lvJuXWl9 6lDVV8IwtTEGNHY/xGREjd7Z3YE5pjShHr4xWjKndKWKQY1rX9yvUssps6duPS3d E18usYqYmMH6jdVCSXjIou8ZdCNCsL3rYgK7YcE9qSex5YMa2RvTZMyS6Gk9Hs0= =06LX -----END PGP SIGNATURE----- --vMS69d09w6VprIIbSNIRxKN2fVVs1eiuS--