From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43827) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8I7m-0001eF-UO for qemu-devel@nongnu.org; Sun, 13 Dec 2015 20:40:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a8I7k-0004Tr-TQ for qemu-devel@nongnu.org; Sun, 13 Dec 2015 20:40:26 -0500 Date: Mon, 14 Dec 2015 12:21:45 +1100 From: David Gibson Message-ID: <20151214012145.GI22783@voom.fritz.box> References: <1449792685-17000-1-git-send-email-david@gibson.dropbear.id.au> <1449792685-17000-7-git-send-email-david@gibson.dropbear.id.au> <566AE89B.7020902@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="X+nYw8KZ/oNxZ8JS" Content-Disposition: inline In-Reply-To: <566AE89B.7020902@redhat.com> 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: Eric Blake Cc: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com, aik@ozlabs.ru, armbru@redhat.com, agraf@suse.de, qemu-ppc@nongnu.org --X+nYw8KZ/oNxZ8JS Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Dec 11, 2015 at 08:15:39AM -0700, Eric Blake wrote: > On 12/10/2015 05:11 PM, David Gibson wrote: > > Use error_setg() to return an error instead of using an explicit exit(). > >=20 > > Signed-off-by: David Gibson > > --- > > hw/ppc/spapr.c | 9 +++++---- > > 1 file changed, 5 insertions(+), 4 deletions(-) > >=20 >=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) > > { >=20 > > 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; >=20 > It looks like find_unknown_sysbus_device is designed to be called in a > loop, and that returning 0 lets the loop continue. >=20 > > @@ -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); >=20 > 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. Ah, good catch. I'll correct in the next spin. > 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 --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --X+nYw8KZ/oNxZ8JS Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJWbhmpAAoJEGw4ysog2bOSKX8P/ibLyQVTbFEP/uzwf4msOQXG LXRXMLM1SpD4/A5Fwy4LpomxCci6lWAfskfq8tnBwvxKYM4Q7Nc4WkIgK+dU2cfs NpjXl5jRj3p7B+b/78pCrq0Ai8HiVurwcwxgZW6y0FP0wI2QSer9QPPZ5PtL1G0k I8vcn6SZNipRPdnZu0P7DAoTP7Z7U698fDif/pNgZq94fY20yM7sDi80OdqxLCKq yqcMRfoxar+QnD0g7t55QhnkZ/wp6JOBMqQ3d5lfrUVjlNe94abCS2NrIP2Kyp5x RuX1GW6+vEwgJICn5I9/U/EcnaygHmVjnUJk96skYDaF00zsLHUjKJhguc7KlZAx s/wp1NfAYr1KioELEZYD8HFBSULVqjnCESKZQ+5KTyl4MvHT9EkQGyeVygyWVxMj cuWEbjDDES5luVAeXxWeGv0+tO298Twi8UZsa6/IjZmlnMw27SVFtzBzB8WNYUnS Oc8BMPA1RDDvo5GnyRCuwny28Hiu1uagSxD+rfRe2brmCYQ+41QKYymx9bdENnDo jPh3PWejDSUTrkbXeUvu7bDvz5VgMunqhAJr5jyIoI54pftcShMOCHQMhBzTZN1/ gVO11+cMDPh7Z9wAX2xYir+YgskgHwDbYpGp0OeBemwKxLhlkrhCLSELcDvnoYbv jtDeWC0QtmePWWwIc34W =aVgM -----END PGP SIGNATURE----- --X+nYw8KZ/oNxZ8JS--