]> git.ipfire.org Git - thirdparty/libvirt.git/commit
util: simplify virPCIProbeStubDriver()
authorLaine Stump <laine@redhat.com>
Sun, 11 Oct 2020 01:47:16 +0000 (21:47 -0400)
committerLaine Stump <laine@redhat.com>
Wed, 21 Oct 2020 19:15:32 +0000 (15:15 -0400)
commitbc7c4f541516666a65f37f6bfea57601d87b4823
treebe285f0899f80dfe67502dd9139c289d898c58c2
parentb3066b55bfa7a123c685dce9a688b0c2336b6c16
util: simplify virPCIProbeStubDriver()

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@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/util/virpci.c