From: Ian Jackson Subject: Re: [PATCH 1/4] libxl: CODING_STYLE: Much new material Date: Fri, 14 Nov 2014 18:43:53 +0000 Message-ID: <21606.19817.933930.293751@mariner.uk.xensource.com> References: <1415198630-29937-1-git-send-email-ian.jackson@eu.citrix.com> <1415198630-29937-2-git-send-email-ian.jackson@eu.citrix.com> <1415622453.25176.4.camel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1415622453.25176.4.camel@citrix.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: Ian Campbell Cc: xen-devel@lists.xensource.com, stefano.stabellini@eu.citrix.com List-Id: xen-devel@lists.xenproject.org Ian Campbell writes ("Re: [PATCH 1/4] libxl: CODING_STYLE: Much new material"): > On Wed, 2014-11-05 at 14:43 +0000, Ian Jackson wrote: > > +The following local variable names should be used where applicable: > > + > > + int rc; /* a libxl error code - and not anything else */ > > + int r; /* the return value from a system call (or libxc call) */ > > Quite a bit more "ret" for this one. Probably quite a few are being > misused as rc too, which is perhaps why you omitted it? I have avoided specifying `ret' here because ret is used indiscriminately for pretty much any int returned from a function. > > + * If the function is to return a libxl error value, `rc' is > > + used to contain the error codem, but it is NOT initialised: > > I suspect this is a typo? (but then I never studied latin...) Fixed. > > + * Function calls which might fail (ie most function calls) are > > + handled by putting the return/status value into a variable, and > > + then checking it in a separate statement: > > + evg->vdev = strdup(vdev); > > + if (!evg->vdev) { rc = ERROR_NOMEM; goto out; } > > A slightly dodgy example because this should be GCSTRDUP(NOGC, vdev) and > therefore can't fail ;-) Example replaced with: char *dompath = libxl__xs_get_dompath(gc, bl->domid); if (!dompath) { rc = ERROR_FAIL; goto out; } > > +Nontrivial data structures (in structs) should come with an idempotent > > +_destroy function, which must free all resources associated with the > > _dispose. Fixed (twice). Thanks, Ian.