cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-block-Clean-up-a-misuse-of-qobject_to-in-.bdrv_co_cr.patch

26ba25
From 9cc36895f5a773ac65abedd6b56748c8e15d2eaf Mon Sep 17 00:00:00 2001
26ba25
From: Markus Armbruster <armbru@redhat.com>
26ba25
Date: Mon, 18 Jun 2018 08:43:19 +0200
26ba25
Subject: [PATCH 021/268] block: Clean up a misuse of qobject_to() in
26ba25
 .bdrv_co_create_opts()
26ba25
26ba25
RH-Author: Markus Armbruster <armbru@redhat.com>
26ba25
Message-id: <20180618084330.30009-13-armbru@redhat.com>
26ba25
Patchwork-id: 80733
26ba25
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 12/23] block: Clean up a misuse of qobject_to() in .bdrv_co_create_opts()
26ba25
Bugzilla: 1557995
26ba25
RH-Acked-by: Max Reitz <mreitz@redhat.com>
26ba25
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
26ba25
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
26ba25
26ba25
The following pattern occurs in the .bdrv_co_create_opts() methods of
26ba25
parallels, qcow, qcow2, qed, vhdx and vpc:
26ba25
26ba25
    qobj = qdict_crumple_for_keyval_qiv(qdict, errp);
26ba25
    qobject_unref(qdict);
26ba25
    qdict = qobject_to(QDict, qobj);
26ba25
    if (qdict == NULL) {
26ba25
         ret = -EINVAL;
26ba25
         goto done;
26ba25
    }
26ba25
26ba25
    v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
26ba25
    [...]
26ba25
    ret = 0;
26ba25
done:
26ba25
    qobject_unref(qdict);
26ba25
    [...]
26ba25
    return ret;
26ba25
26ba25
If qobject_to() fails, we return failure without setting errp.  That's
26ba25
wrong.  As far as I can tell, it cannot fail here.  Clean it up
26ba25
anyway, by removing the useless conversion.
26ba25
26ba25
Signed-off-by: Markus Armbruster <armbru@redhat.com>
26ba25
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
(cherry picked from commit 92adf9dbcd3cf9cedddae995b04a99f5c42ae08c)
26ba25
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
26ba25
---
26ba25
 block/parallels.c | 9 ++++-----
26ba25
 block/qcow.c      | 9 ++++-----
26ba25
 block/qcow2.c     | 9 ++++-----
26ba25
 block/qed.c       | 9 ++++-----
26ba25
 block/vhdx.c      | 9 ++++-----
26ba25
 block/vpc.c       | 9 ++++-----
26ba25
 6 files changed, 24 insertions(+), 30 deletions(-)
26ba25
26ba25
diff --git a/block/parallels.c b/block/parallels.c
26ba25
index aa58955..1c96c39 100644
26ba25
--- a/block/parallels.c
26ba25
+++ b/block/parallels.c
26ba25
@@ -614,7 +614,7 @@ static int coroutine_fn parallels_co_create_opts(const char *filename,
26ba25
     BlockdevCreateOptions *create_options = NULL;
26ba25
     Error *local_err = NULL;
26ba25
     BlockDriverState *bs = NULL;
26ba25
-    QDict *qdict = NULL;
26ba25
+    QDict *qdict;
26ba25
     QObject *qobj;
26ba25
     Visitor *v;
26ba25
     int ret;
26ba25
@@ -652,14 +652,13 @@ static int coroutine_fn parallels_co_create_opts(const char *filename,
26ba25
     qdict_put_str(qdict, "file", bs->node_name);
26ba25
 
26ba25
     qobj = qdict_crumple_for_keyval_qiv(qdict, errp);
26ba25
-    qobject_unref(qdict);
26ba25
-    qdict = qobject_to(QDict, qobj);
26ba25
-    if (qdict == NULL) {
26ba25
+    if (!qobj) {
26ba25
         ret = -EINVAL;
26ba25
         goto done;
26ba25
     }
26ba25
 
26ba25
-    v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
26ba25
+    v = qobject_input_visitor_new_keyval(qobj);
26ba25
+    qobject_unref(qobj);
26ba25
     visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
26ba25
     visit_free(v);
26ba25
 
26ba25
diff --git a/block/qcow.c b/block/qcow.c
26ba25
index 14b7296..43a595a 100644
26ba25
--- a/block/qcow.c
26ba25
+++ b/block/qcow.c
26ba25
@@ -944,7 +944,7 @@ static int coroutine_fn qcow_co_create_opts(const char *filename,
26ba25
 {
26ba25
     BlockdevCreateOptions *create_options = NULL;
26ba25
     BlockDriverState *bs = NULL;
26ba25
-    QDict *qdict = NULL;
26ba25
+    QDict *qdict;
26ba25
     QObject *qobj;
26ba25
     Visitor *v;
26ba25
     const char *val;
26ba25
@@ -996,14 +996,13 @@ static int coroutine_fn qcow_co_create_opts(const char *filename,
26ba25
     qdict_put_str(qdict, "file", bs->node_name);
26ba25
 
26ba25
     qobj = qdict_crumple_for_keyval_qiv(qdict, errp);
26ba25
-    qobject_unref(qdict);
26ba25
-    qdict = qobject_to(QDict, qobj);
26ba25
-    if (qdict == NULL) {
26ba25
+    if (!qobj) {
26ba25
         ret = -EINVAL;
26ba25
         goto fail;
26ba25
     }
26ba25
 
26ba25
-    v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
26ba25
+    v = qobject_input_visitor_new_keyval(qobj);
26ba25
+    qobject_unref(qobj);
26ba25
     visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
26ba25
     visit_free(v);
26ba25
 
26ba25
diff --git a/block/qcow2.c b/block/qcow2.c
26ba25
index fa06b41..ede52a8 100644
26ba25
--- a/block/qcow2.c
26ba25
+++ b/block/qcow2.c
26ba25
@@ -3067,7 +3067,7 @@ static int coroutine_fn qcow2_co_create_opts(const char *filename, QemuOpts *opt
26ba25
                                              Error **errp)
26ba25
 {
26ba25
     BlockdevCreateOptions *create_options = NULL;
26ba25
-    QDict *qdict = NULL;
26ba25
+    QDict *qdict;
26ba25
     QObject *qobj;
26ba25
     Visitor *v;
26ba25
     BlockDriverState *bs = NULL;
26ba25
@@ -3140,14 +3140,13 @@ static int coroutine_fn qcow2_co_create_opts(const char *filename, QemuOpts *opt
26ba25
 
26ba25
     /* Now get the QAPI type BlockdevCreateOptions */
26ba25
     qobj = qdict_crumple_for_keyval_qiv(qdict, errp);
26ba25
-    qobject_unref(qdict);
26ba25
-    qdict = qobject_to(QDict, qobj);
26ba25
-    if (qdict == NULL) {
26ba25
+    if (!qobj) {
26ba25
         ret = -EINVAL;
26ba25
         goto finish;
26ba25
     }
26ba25
 
26ba25
-    v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
26ba25
+    v = qobject_input_visitor_new_keyval(qobj);
26ba25
+    qobject_unref(qobj);
26ba25
     visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
26ba25
     visit_free(v);
26ba25
 
26ba25
diff --git a/block/qed.c b/block/qed.c
26ba25
index d8810f5..3818888 100644
26ba25
--- a/block/qed.c
26ba25
+++ b/block/qed.c
26ba25
@@ -722,7 +722,7 @@ static int coroutine_fn bdrv_qed_co_create_opts(const char *filename,
26ba25
                                                 Error **errp)
26ba25
 {
26ba25
     BlockdevCreateOptions *create_options = NULL;
26ba25
-    QDict *qdict = NULL;
26ba25
+    QDict *qdict;
26ba25
     QObject *qobj;
26ba25
     Visitor *v;
26ba25
     BlockDriverState *bs = NULL;
26ba25
@@ -764,14 +764,13 @@ static int coroutine_fn bdrv_qed_co_create_opts(const char *filename,
26ba25
     qdict_put_str(qdict, "file", bs->node_name);
26ba25
 
26ba25
     qobj = qdict_crumple_for_keyval_qiv(qdict, errp);
26ba25
-    qobject_unref(qdict);
26ba25
-    qdict = qobject_to(QDict, qobj);
26ba25
-    if (qdict == NULL) {
26ba25
+    if (!qobj) {
26ba25
         ret = -EINVAL;
26ba25
         goto fail;
26ba25
     }
26ba25
 
26ba25
-    v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
26ba25
+    v = qobject_input_visitor_new_keyval(qobj);
26ba25
+    qobject_unref(qobj);
26ba25
     visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
26ba25
     visit_free(v);
26ba25
 
26ba25
diff --git a/block/vhdx.c b/block/vhdx.c
26ba25
index 32939c4..728d8b3 100644
26ba25
--- a/block/vhdx.c
26ba25
+++ b/block/vhdx.c
26ba25
@@ -1963,7 +1963,7 @@ static int coroutine_fn vhdx_co_create_opts(const char *filename,
26ba25
                                             Error **errp)
26ba25
 {
26ba25
     BlockdevCreateOptions *create_options = NULL;
26ba25
-    QDict *qdict = NULL;
26ba25
+    QDict *qdict;
26ba25
     QObject *qobj;
26ba25
     Visitor *v;
26ba25
     BlockDriverState *bs = NULL;
26ba25
@@ -2004,14 +2004,13 @@ static int coroutine_fn vhdx_co_create_opts(const char *filename,
26ba25
     qdict_put_str(qdict, "file", bs->node_name);
26ba25
 
26ba25
     qobj = qdict_crumple_for_keyval_qiv(qdict, errp);
26ba25
-    qobject_unref(qdict);
26ba25
-    qdict = qobject_to(QDict, qobj);
26ba25
-    if (qdict == NULL) {
26ba25
+    if (!qobj) {
26ba25
         ret = -EINVAL;
26ba25
         goto fail;
26ba25
     }
26ba25
 
26ba25
-    v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
26ba25
+    v = qobject_input_visitor_new_keyval(qobj);
26ba25
+    qobject_unref(qobj);
26ba25
     visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
26ba25
     visit_free(v);
26ba25
 
26ba25
diff --git a/block/vpc.c b/block/vpc.c
26ba25
index 16178e5..a9bb041 100644
26ba25
--- a/block/vpc.c
26ba25
+++ b/block/vpc.c
26ba25
@@ -1081,7 +1081,7 @@ static int coroutine_fn vpc_co_create_opts(const char *filename,
26ba25
                                            QemuOpts *opts, Error **errp)
26ba25
 {
26ba25
     BlockdevCreateOptions *create_options = NULL;
26ba25
-    QDict *qdict = NULL;
26ba25
+    QDict *qdict;
26ba25
     QObject *qobj;
26ba25
     Visitor *v;
26ba25
     BlockDriverState *bs = NULL;
26ba25
@@ -1120,14 +1120,13 @@ static int coroutine_fn vpc_co_create_opts(const char *filename,
26ba25
     qdict_put_str(qdict, "file", bs->node_name);
26ba25
 
26ba25
     qobj = qdict_crumple_for_keyval_qiv(qdict, errp);
26ba25
-    qobject_unref(qdict);
26ba25
-    qdict = qobject_to(QDict, qobj);
26ba25
-    if (qdict == NULL) {
26ba25
+    if (!qobj) {
26ba25
         ret = -EINVAL;
26ba25
         goto fail;
26ba25
     }
26ba25
 
26ba25
-    v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
26ba25
+    v = qobject_input_visitor_new_keyval(qobj);
26ba25
+    qobject_unref(qobj);
26ba25
     visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
26ba25
     visit_free(v);
26ba25
 
26ba25
-- 
26ba25
1.8.3.1
26ba25