Skip to content
Snippets Groups Projects
  • Markus Armbruster's avatar
    af175e85
    error: Eliminate error_propagate() with Coccinelle, part 2 · af175e85
    Markus Armbruster authored
    
    When all we do with an Error we receive into a local variable is
    propagating to somewhere else, we can just as well receive it there
    right away.  The previous commit did that with a Coccinelle script I
    consider fairly trustworthy.  This commit uses the same script with
    the matching of return taken out, i.e. we convert
    
        if (!foo(..., &err)) {
            ...
            error_propagate(errp, err);
            ...
        }
    
    to
    
        if (!foo(..., errp)) {
            ...
            ...
        }
    
    This is unsound: @err could still be read between afterwards.  I don't
    know how to express "no read of @err without an intervening write" in
    Coccinelle.  Instead, I manually double-checked for uses of @err.
    
    Suboptimal line breaks tweaked manually.  qdev_realize() simplified
    further to placate scripts/checkpatch.pl.
    
    Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
    Reviewed-by: default avatarEric Blake <eblake@redhat.com>
    Message-Id: <20200707160613.848843-36-armbru@redhat.com>
    af175e85
    History
    error: Eliminate error_propagate() with Coccinelle, part 2
    Markus Armbruster authored
    
    When all we do with an Error we receive into a local variable is
    propagating to somewhere else, we can just as well receive it there
    right away.  The previous commit did that with a Coccinelle script I
    consider fairly trustworthy.  This commit uses the same script with
    the matching of return taken out, i.e. we convert
    
        if (!foo(..., &err)) {
            ...
            error_propagate(errp, err);
            ...
        }
    
    to
    
        if (!foo(..., errp)) {
            ...
            ...
        }
    
    This is unsound: @err could still be read between afterwards.  I don't
    know how to express "no read of @err without an intervening write" in
    Coccinelle.  Instead, I manually double-checked for uses of @err.
    
    Suboptimal line breaks tweaked manually.  qdev_realize() simplified
    further to placate scripts/checkpatch.pl.
    
    Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
    Reviewed-by: default avatarEric Blake <eblake@redhat.com>
    Message-Id: <20200707160613.848843-36-armbru@redhat.com>