Received: from eggs.gnu.org ([2001:4830:134:3::10]:44706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCUAH-0005cS-GZ for qemu-devel@nongnu.org; Mon, 13 Jun 2016 11:52:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCUAF-0000Kl-BB for qemu-devel@nongnu.org; Mon, 13 Jun 2016 11:52:36 -0400 Date: Mon, 13 Jun 2016 12:52:26 -0300 From: Eduardo Habkost Message-ID: <20160613155226.GH18662@thinpad.lan.raisama.net> References: <1465589538-24998-1-git-send-email-ehabkost@redhat.com> <1465589538-24998-3-git-send-email-ehabkost@redhat.com> <87k2htwc14.fsf@dusky.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87k2htwc14.fsf@dusky.pond.sub.org> Subject: Re: [Qemu-devel] [PATCH v2 2/3] error: Remove unnecessary local_err variables List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: qemu-devel@nongnu.org, kwolf@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com, borntraeger@de.ibm.com, cornelia.huck@de.ibm.com On Mon, Jun 13, 2016 at 01:42:15PM +0200, Markus Armbruster wrote: > Eduardo Habkost writes: > > > This patch simplifies code that uses a local_err variable just to > > immediately use it for an error_propagate() call. > > > > Coccinelle patch used to perform the changes added to > > scripts/coccinelle/remove_local_err.cocci. > > > > Signed-off-by: Eduardo Habkost > [...] > > diff --git a/scripts/coccinelle/remove_local_err.cocci b/scripts/coccinelle/remove_local_err.cocci > > new file mode 100644 > > index 0000000..5f0b6c0 > > --- /dev/null > > +++ b/scripts/coccinelle/remove_local_err.cocci > > @@ -0,0 +1,27 @@ > > +// Replace unnecessary usage of local_err variable with > > +// direct usage of errp argument > > + > > +@@ > > +expression list ARGS; > > +expression F2; > > +identifier LOCAL_ERR; > > +expression ERRP; > > +idexpression V; > > +typedef Error; > > +expression I; > > I isn't used. > > > +@@ > > + { > > + ... > > +- Error *LOCAL_ERR; > > + ... when != LOCAL_ERR > > +( > > +- F2(ARGS, &LOCAL_ERR); > > +- error_propagate(ERRP, LOCAL_ERR); > > ++ F2(ARGS, ERRP); > > +| > > +- V = F2(ARGS, &LOCAL_ERR); > > +- error_propagate(ERRP, LOCAL_ERR); > > ++ V = F2(ARGS, ERRP); > > +) > > + ... when != LOCAL_ERR > > + } > > There is an (ugly) difference between > > error_setg(&local_err, ...); > error_propagate(errp, &local_err); > > and > > error_setg(errp, ...); > > The latter aborts when @errp already contains an error, the former does > nothing. Why the difference? Couldn't we change that so that both are equivalent? > > Your transformation has the error_setg() or similar hidden in F2(). It > can add aborts. > > I think it can be salvaged: we know that @errp must not contain an error > on function entry. If @errp doesn't occur elsewhere in this function, > it cannot pick up an error on the way to the transformed spot. Can you > add that to your when constraints? Do we really know that *errp is NULL on entry? Aren't we allowed to call functions with a non-NULL *errp? See, e.g.: void qmp_guest_suspend_disk(Error **errp) { Error *local_err = NULL; GuestSuspendMode *mode = g_new(GuestSuspendMode, 1); *mode = GUEST_SUSPEND_MODE_DISK; check_suspend_mode(*mode, &local_err); acquire_privilege(SE_SHUTDOWN_NAME, &local_err); execute_async(do_suspend, mode, &local_err); if (local_err) { error_propagate(errp, local_err); g_free(mode); } } -- Eduardo