From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53170) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCQG7-0002gE-L9 for qemu-devel@nongnu.org; Mon, 13 Jun 2016 07:42:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCQG6-0005Aw-KC for qemu-devel@nongnu.org; Mon, 13 Jun 2016 07:42:23 -0400 From: Markus Armbruster References: <1465589538-24998-1-git-send-email-ehabkost@redhat.com> <1465589538-24998-3-git-send-email-ehabkost@redhat.com> Date: Mon, 13 Jun 2016 13:42:15 +0200 In-Reply-To: <1465589538-24998-3-git-send-email-ehabkost@redhat.com> (Eduardo Habkost's message of "Fri, 10 Jun 2016 17:12:17 -0300") Message-ID: <87k2htwc14.fsf@dusky.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain 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: Eduardo Habkost Cc: qemu-devel@nongnu.org, kwolf@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com, borntraeger@de.ibm.com, cornelia.huck@de.ibm.com 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. 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? [...]