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

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