[PATCH 4/9] util: simplify virPCIProbeStubDriver()

Erik Skultety eskultet at redhat.com
Wed Oct 21 08:41:48 UTC 2020

On Tue, Oct 20, 2020 at 10:26:04PM -0400, Laine Stump wrote:
> This function had a loop that was only executed twice; it was
> artificially constructed with a label, a goto, and a boolean to tell
> that it had already been executed once. Aside from that, the body of
> the loop contained only two lines that needed to be repeated (the
> second time through, everything beyond those two lines would be
> skipped).
> One side effect of this strange loop was that a g_autofree string was
> manually freed and re-initialized; I've been told that manually
> freeing a g_auto_free object is highly discouraged.
> This patch refactors the function to simply repeat the 2 lines that
> might possibly be executed twice, thus eliminating the ugly use of
> goto to construct a loop, and also takes advantage of the fact that
> virPCIDriverDir() was previously returning *exactly* the same string
> both times it was called to eliminate the manual VIR_FREE of drvpath.
> Signed-off-by: Laine Stump <laine at redhat.com>

Much better :)
Reviewed-by: Erik Skultety <eskultet at redhat.com>

More information about the libvir-list mailing list