[libvirt] [PATCH 2/4] virCPUDefFormatBufFull: Use our general error handling pattern

Martin Kletzander mkletzan at redhat.com
Tue Feb 24 10:53:22 UTC 2015


On Thu, Feb 19, 2015 at 02:13:43PM +0100, Michal Privoznik wrote:
>Well, so far there are no variables to free, no cleanup work needed on
>an error, so bare 'return -1;' after each error is just okay. But this
>will change in a while.
>
>Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
>---
> src/conf/cpu_conf.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>

ACK, but you could've just squashed it in with the next one, I guess.

>diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
>index 4a367a1..9a430ef 100644
>--- a/src/conf/cpu_conf.c
>+++ b/src/conf/cpu_conf.c
>@@ -555,6 +555,8 @@ virCPUDefFormatBufFull(virBufferPtr buf,
>                        virCPUDefPtr def,
>                        bool updateCPU)
> {
>+    int ret = -1;
>+
>     if (!def)
>         return 0;
>
>@@ -566,7 +568,7 @@ virCPUDefFormatBufFull(virBufferPtr buf,
>             if (!(tmp = virCPUModeTypeToString(def->mode))) {
>                 virReportError(VIR_ERR_INTERNAL_ERROR,
>                                _("Unexpected CPU mode %d"), def->mode);
>-                return -1;
>+                goto cleanup;
>             }
>             virBufferAsprintf(buf, " mode='%s'", tmp);
>         }
>@@ -578,7 +580,7 @@ virCPUDefFormatBufFull(virBufferPtr buf,
>                 virReportError(VIR_ERR_INTERNAL_ERROR,
>                                _("Unexpected CPU match policy %d"),
>                                def->match);
>-                return -1;
>+                goto cleanup;
>             }
>             virBufferAsprintf(buf, " match='%s'", tmp);
>         }
>@@ -590,12 +592,14 @@ virCPUDefFormatBufFull(virBufferPtr buf,
>         virBufferAsprintf(buf, "<arch>%s</arch>\n",
>                           virArchToString(def->arch));
>     if (virCPUDefFormatBuf(buf, def, updateCPU) < 0)
>-        return -1;
>+        goto cleanup;
>     virBufferAdjustIndent(buf, -2);
>
>     virBufferAddLit(buf, "</cpu>\n");
>
>-    return 0;
>+    ret = 0;
>+ cleanup:
>+    return ret;
> }
>
> int
>--
>2.0.5
>
>--
>libvir-list mailing list
>libvir-list at redhat.com
>https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20150224/6400c3e0/attachment-0001.sig>


More information about the libvir-list mailing list