From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40516) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a7PQE-0001SA-8v for qemu-devel@nongnu.org; Fri, 11 Dec 2015 10:15:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a7PQA-0008LE-7s for qemu-devel@nongnu.org; Fri, 11 Dec 2015 10:15:50 -0500 References: <1449792685-17000-1-git-send-email-david@gibson.dropbear.id.au> <1449792685-17000-7-git-send-email-david@gibson.dropbear.id.au> From: Eric Blake Message-ID: <566AE89B.7020902@redhat.com> Date: Fri, 11 Dec 2015 08:15:39 -0700 MIME-Version: 1.0 In-Reply-To: <1449792685-17000-7-git-send-email-david@gibson.dropbear.id.au> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="IAHe3gXAHjc2UL2HP7d45fQ5DRvKdCqHr" Subject: Re: [Qemu-devel] [PATCH 06/11] pseries: Improve error handling in find_unknown_sysbus_device() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Gibson , armbru@redhat.com, aik@ozlabs.ru, mdroth@linux.vnet.ibm.com Cc: lvivier@redhat.com, thuth@redhat.com, qemu-ppc@nongnu.org, agraf@suse.de, qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --IAHe3gXAHjc2UL2HP7d45fQ5DRvKdCqHr Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 12/10/2015 05:11 PM, David Gibson wrote: > Use error_setg() to return an error instead of using an explicit exit()= =2E >=20 > Signed-off-by: David Gibson > --- > hw/ppc/spapr.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) >=20 > +++ b/hw/ppc/spapr.c > @@ -1107,6 +1107,7 @@ static void spapr_reset_htab(sPAPRMachineState *s= papr, Error **errp) > =20 > static int find_unknown_sysbus_device(SysBusDevice *sbdev, void *opaqu= e) > { > if (!matched) { > - error_report("Device %s is not supported by this machine yet."= , > - qdev_fw_name(DEVICE(sbdev))); > - exit(1); > + error_setg(errp, > + "Device %s is not supported by this machine yet", > + qdev_fw_name(DEVICE(sbdev))); > } > =20 > return 0; It looks like find_unknown_sysbus_device is designed to be called in a loop, and that returning 0 lets the loop continue. > @@ -1151,7 +1152,7 @@ static void ppc_spapr_reset(void) > uint32_t rtas_limit; > =20 > /* Check for unknown sysbus devices */ > - foreach_dynamic_sysbus_device(find_unknown_sysbus_device, NULL); > + foreach_dynamic_sysbus_device(find_unknown_sysbus_device, &error_a= bort); If a caller passes something other than &error_abort as the opaque, AND the error condition occurs more than once in the loop iteration, then you really need to change find_unknown_sysbus_device() to return non-zero after raising error on the first failure, so that the loop doesn't continue on to a second pass and attempt an error_setg() onto an already-set error. Of course, since _this_ patch uses &error_abort as the only client, the loop will never continue after the first failure, but it's more robust to be clean without having to audit the callers. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --IAHe3gXAHjc2UL2HP7d45fQ5DRvKdCqHr Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJWauibAAoJEKeha0olJ0NqE0gH/jw5a6aIa54rngiT5YLznABG TVj40lFFq8kUE1b0XMTqfRtg54qFvgWIXpmpobGx3elnSPo5v+w7MdfJ6Jbt17cM vaJvQFz+SPGCU8xXTjbAzHkwlLdYFUebaS7szc2SkXMO5/B6GbxM8H3dZgmKKNQq ub4q0g0dm+PxDf+A/9sOhZvZYqVj+wsZoWG0KhBi3FmgT2ALYGsx+4JBMbW4AIfS bqwgL5cCKw59Y9tvtiOngyAbHRmj5QVw9KoGqKHCKxJnmuGXVqSWrWfmBMbNUBKT t3+GXKP60n7iVii0Ns11rFY8CoiqvaKjhxiNm9+tRoFiiAFSahBOSjFagwH6tIE= =YvUT -----END PGP SIGNATURE----- --IAHe3gXAHjc2UL2HP7d45fQ5DRvKdCqHr--