From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dario Faggioli Subject: Re: [PATCH v3] libxl: fix handling of returns in libxl_get_version_info() Date: Mon, 15 Feb 2016 11:07:21 +0100 Message-ID: <1455530841.14334.38.camel@citrix.com> References: <1455309313-5149-1-git-send-email-write.harmandeep@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============4795091256448054365==" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aVG4D-0002E3-D5 for xen-devel@lists.xenproject.org; Mon, 15 Feb 2016 10:07:41 +0000 In-Reply-To: <1455309313-5149-1-git-send-email-write.harmandeep@gmail.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Harmandeep Kaur , xen-devel@lists.xenproject.org Cc: wei.liu2@citrix.com, ian.jackson@eu.citrix.com, ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com List-Id: xen-devel@lists.xenproject.org --===============4795091256448054365== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-vReCmzdk985zhp5zzA9B" --=-vReCmzdk985zhp5zzA9B Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hey, Harmandeep, We're almost there, I would say. The subject is still suboptimal, IMO. I would go for something like "libxl: handle failure of xc_version() in libxl_get_version_info() The changelog... On Sat, 2016-02-13 at 02:05 +0530, Harmandeep Kaur wrote: > Check the return value of xc_version() and return NULL if it > fails. libxl_get_version_info() can also return NULL now. > Put a blank line here. > Callers of the function libxl_get_version_info() are already > prepared to deal with returning NULL on failure of xc_version(). > Callers don't know what actually failed inside the function, and that is perfectly ok. I'd just say "are already prepared to deal with a NULL return value" > Group all calls to xc_version() , so that data copies in various > info fields only if all calls to xc_version go error-free. > This is not super-important to have here in the changelog. I would have put it in the "v2:" section, below the "---". I don't mind too much if you want to leave it here, though. > diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c > index 2d18b8d..f660280 100644 > --- a/tools/libxl/libxl.c > +++ b/tools/libxl/libxl.c > @@ -5267,42 +5267,44 @@ const libxl_version_info* > libxl_get_version_info(libxl_ctx *ctx) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0xen_platform_parame= ters_t p_parms; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0xen_commandline_t x= en_commandline; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0} u; > -=C2=A0=C2=A0=C2=A0=C2=A0long xen_version; > +=C2=A0=C2=A0=C2=A0=C2=A0long r =3D 0; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0libxl_version_info *info =3D &ctx->version_= info; > =C2=A0 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if (info->xen_version_extra !=3D NULL) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0goto out; > =C2=A0 > -=C2=A0=C2=A0=C2=A0=C2=A0xen_version =3D xc_version(ctx->xch, XENVER_vers= ion, NULL); > -=C2=A0=C2=A0=C2=A0=C2=A0info->xen_version_major =3D xen_version >> 16; > -=C2=A0=C2=A0=C2=A0=C2=A0info->xen_version_minor =3D xen_version & 0xFF; > - > -=C2=A0=C2=A0=C2=A0=C2=A0xc_version(ctx->xch, XENVER_extraversion, &u.xen= _extra); > +=C2=A0=C2=A0=C2=A0=C2=A0r =3D xc_version(ctx->xch, XENVER_version, NULL)= ; > +=C2=A0=C2=A0=C2=A0=C2=A0if (r < 0) goto out; > +=C2=A0=C2=A0=C2=A0=C2=A0r =3D xc_version(ctx->xch, XENVER_extraversion, = &u.xen_extra); > +=C2=A0=C2=A0=C2=A0=C2=A0if (r < 0) goto out; > +=C2=A0=C2=A0=C2=A0=C2=A0r =3D xc_version(ctx->xch, XENVER_compile_info, = &u.xen_cc); > +=C2=A0=C2=A0=C2=A0=C2=A0if (r < 0) goto out; > +=C2=A0=C2=A0=C2=A0=C2=A0r =3D xc_version(ctx->xch, XENVER_capabilities, = &u.xen_caps); > +=C2=A0=C2=A0=C2=A0=C2=A0if (r < 0) goto out; > +=C2=A0=C2=A0=C2=A0=C2=A0r =3D xc_version(ctx->xch, XENVER_changeset, &u.= xen_chgset); > +=C2=A0=C2=A0=C2=A0=C2=A0if (r < 0) goto out; > +=C2=A0=C2=A0=C2=A0=C2=A0r =3D xc_version(ctx->xch, XENVER_platform_param= eters, > &u.p_parms); > +=C2=A0=C2=A0=C2=A0=C2=A0if (r < 0) goto out; > +=C2=A0=C2=A0=C2=A0=C2=A0r =3D info->pagesize =3D xc_version(ctx->xch, XE= NVER_pagesize, > NULL); > +=C2=A0=C2=A0=C2=A0=C2=A0if (r < 0) goto out; > +=C2=A0=C2=A0=C2=A0=C2=A0r =3D xc_version(ctx->xch, XENVER_commandline, > &u.xen_commandline); > +=C2=A0=C2=A0=C2=A0=C2=A0if (r < 0) goto out; > + > +=C2=A0=C2=A0=C2=A0=C2=A0info->xen_version_major =3D r >> 16; > +=C2=A0=C2=A0=C2=A0=C2=A0info->xen_version_minor =3D r & 0xFF; > But now you are using the value of 'r' returned by xc_version(ctx->xch, XENVER_commandline, &u.xen_commandline), which is not what you want! You either need to make the call to xc_version(ctx->xch, XENVER_version, NULL) the last one, or avoid getting rid of the xen_version local variable. I'd do the latter. I know it was me that suggested you did not need it, but that was with the previous structure of the function. With this re- arrangement, I think it's more than fine to keep it. But that's mostly a matter of taste (yours, and tools' maintainers' one :-D). > =C2=A0 out: > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0GC_FREE; > -=C2=A0=C2=A0=C2=A0=C2=A0return info; > +=C2=A0=C2=A0=C2=A0=C2=A0return r < 0 ? NULL:info; > =C2=A0NULL : info; =C2=A0(spaces around ':'). Thanks and Regards, Dario --=20 <> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK) --=-vReCmzdk985zhp5zzA9B Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEABECAAYFAlbBo1kACgkQk4XaBE3IOsSD9gCfamKz5Irmt/uR0Qj5tDSokk/l YQgAni1/MJv9NOLPz/ZfniBpjHHEheJL =NeoE -----END PGP SIGNATURE----- --=-vReCmzdk985zhp5zzA9B-- --===============4795091256448054365== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --===============4795091256448054365==--