yeahuh / 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

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