qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com
Subject: [Qemu-devel] [PATCH 4/8] qom: push permission checks up into qdev_property_add_legacy
Date: Fri, 16 Dec 2011 13:01:54 +0100	[thread overview]
Message-ID: <1324036918-2405-5-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1324036918-2405-1-git-send-email-pbonzini@redhat.com>

qdev_property_get and qdev_property_set can generate permission
denied errors themselves.  Do not duplicate this functionality in
qdev_get/set_legacy_property, and clean up excessive indentation.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/qdev.c |   46 +++++++++++++++++++---------------------------
 1 files changed, 19 insertions(+), 27 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index bda8d6c..c020a6f 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -1135,46 +1135,38 @@ static void qdev_get_legacy_property(DeviceState *dev, Visitor *v, void *opaque,
 {
     Property *prop = opaque;
 
-    if (prop->info->print) {
-        char buffer[1024];
-        char *ptr = buffer;
+    char buffer[1024];
+    char *ptr = buffer;
 
-        prop->info->print(dev, prop, buffer, sizeof(buffer));
-        visit_type_str(v, &ptr, name, errp);
-    } else {
-        error_set(errp, QERR_PERMISSION_DENIED);
-    }
+    prop->info->print(dev, prop, buffer, sizeof(buffer));
+    visit_type_str(v, &ptr, name, errp);
 }
 
 static void qdev_set_legacy_property(DeviceState *dev, Visitor *v, void *opaque,
                                      const char *name, Error **errp)
 {
     Property *prop = opaque;
+    Error *local_err = NULL;
+    char *ptr = NULL;
+    int ret;
 
     if (dev->state != DEV_STATE_CREATED) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
 
-    if (prop->info->parse) {
-        Error *local_err = NULL;
-        char *ptr = NULL;
+    visit_type_str(v, &ptr, name, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
 
-        visit_type_str(v, &ptr, name, &local_err);
-        if (!local_err) {
-            int ret;
-            ret = prop->info->parse(dev, prop, ptr);
-            if (ret != 0) {
-                error_set(errp, QERR_INVALID_PARAMETER_VALUE,
-                          name, prop->info->name);
-            }
-            g_free(ptr);
-        } else {
-            error_propagate(errp, local_err);
-        }
-    } else {
-        error_set(errp, QERR_PERMISSION_DENIED);
+    ret = prop->info->parse(dev, prop, ptr);
+    if (ret != 0) {
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE,
+                  name, prop->info->name);
     }
+    g_free(ptr);
 }
 
 /**
@@ -1194,8 +1186,8 @@ void qdev_property_add_legacy(DeviceState *dev, Property *prop,
     type = g_strdup_printf("legacy<%s>", prop->info->name);
 
     qdev_property_add(dev, prop->name, type,
-                      qdev_get_legacy_property,
-                      qdev_set_legacy_property,
+                      prop->info->print ? qdev_get_legacy_property : NULL,
+                      prop->info->parse ? qdev_set_legacy_property : NULL,
                       NULL,
                       prop, errp);
 
-- 
1.7.7.1

  parent reply	other threads:[~2011-12-16 12:02 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-16 12:01 [Qemu-devel] [PATCH 0/8] qom: introduce non-legacy static properties Paolo Bonzini
2011-12-16 12:01 ` [Qemu-devel] [PATCH 1/8] qapi: fix NULL pointer dereference Paolo Bonzini
2011-12-16 13:55   ` Anthony Liguori
2011-12-16 14:00     ` Paolo Bonzini
2011-12-16 14:10       ` Anthony Liguori
2011-12-16 14:22         ` Paolo Bonzini
2011-12-16 14:46           ` Anthony Liguori
2011-12-16 14:49             ` Paolo Bonzini
2011-12-16 14:56               ` Anthony Liguori
2011-12-16 15:03                 ` Paolo Bonzini
2011-12-16 15:05                   ` Anthony Liguori
2011-12-16 15:13                     ` Paolo Bonzini
2011-12-16 15:23                       ` Anthony Liguori
2011-12-16 15:42                         ` Paolo Bonzini
2011-12-16 15:54                           ` Anthony Liguori
2011-12-16 16:17                             ` Paolo Bonzini
2011-12-16 16:24                   ` Gerd Hoffmann
2011-12-16 12:01 ` [Qemu-devel] [PATCH 2/8] qapi: protect against NULL QObject in qmp_input_get_object Paolo Bonzini
2011-12-16 13:56   ` Anthony Liguori
2011-12-16 12:01 ` [Qemu-devel] [PATCH 3/8] qom: fix swapped parameters Paolo Bonzini
2011-12-16 13:57   ` Anthony Liguori
2011-12-16 12:01 ` Paolo Bonzini [this message]
2011-12-16 13:58   ` [Qemu-devel] [PATCH 4/8] qom: push permission checks up into qdev_property_add_legacy Anthony Liguori
2011-12-16 12:01 ` [Qemu-devel] [PATCH 5/8] qom: introduce QERR_PROPERTY_VALUE_OUT_OF_RANGE Paolo Bonzini
2011-12-16 14:00   ` Anthony Liguori
2011-12-16 14:01     ` Paolo Bonzini
2011-12-16 17:00       ` Paolo Bonzini
2011-12-16 17:01         ` Anthony Liguori
2011-12-16 12:01 ` [Qemu-devel] [PATCH 6/8] qom: introduce get/set methods for Property Paolo Bonzini
2011-12-16 13:11   ` Gerd Hoffmann
2011-12-16 13:51     ` Paolo Bonzini
2011-12-16 14:05       ` Anthony Liguori
2011-12-16 14:18         ` Paolo Bonzini
2011-12-16 14:44           ` Anthony Liguori
2011-12-16 12:01 ` [Qemu-devel] [PATCH 7/8] qom: distinguish "legacy" property type name from QOM type name Paolo Bonzini
2011-12-16 14:06   ` Anthony Liguori
2011-12-16 14:18     ` Paolo Bonzini
2011-12-16 14:43       ` Anthony Liguori
2011-12-16 12:01 ` [Qemu-devel] [PATCH 8/8] qom: register qdev properties also as non-legacy properties Paolo Bonzini
2011-12-16 13:54 ` [Qemu-devel] [PATCH 0/8] qom: introduce non-legacy static properties Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1324036918-2405-5-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).