qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, mdroth@linux.vnet.ibm.com, lcapitulino@redhat.com
Subject: [Qemu-devel] [PATCH v3 05/14] qga: Use return values instead of error_is_set(errp)
Date: Fri,  2 May 2014 13:26:33 +0200	[thread overview]
Message-ID: <1399030002-27222-6-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1399030002-27222-1-git-send-email-armbru@redhat.com>

Using error_is_set(errp) to check whether a function call failed is
fragile: it breaks when errp is null.  ga_get_fd_handle() and
guest_file_handle_add() don't return a useful value when they fail,
but that's just stupid.  Fix that, and check them instead.  As far
as I can tell, errp can't be null there, but this is more robust and
more obviously correct.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 qga/commands-posix.c | 6 +++---
 qga/main.c           | 1 +
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index f6af7d1..6af974f 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -223,8 +223,8 @@ static int64_t guest_file_handle_add(FILE *fh, Error **errp)
     int64_t handle;
 
     handle = ga_get_fd_handle(ga_state, errp);
-    if (error_is_set(errp)) {
-        return 0;
+    if (handle < 0) {
+        return -1;
     }
 
     gfh = g_malloc0(sizeof(GuestFileHandle));
@@ -407,7 +407,7 @@ int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode,
     }
 
     handle = guest_file_handle_add(fh, errp);
-    if (error_is_set(errp)) {
+    if (handle < 0) {
         fclose(fh);
         return -1;
     }
diff --git a/qga/main.c b/qga/main.c
index d838c3e..eb792a3 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -910,6 +910,7 @@ int64_t ga_get_fd_handle(GAState *s, Error **errp)
 
     if (!write_persistent_state(&s->pstate, s->pstate_filepath)) {
         error_setg(errp, "failed to commit persistent state to disk");
+        return -1;
     }
 
     return handle;
-- 
1.8.1.4

  parent reply	other threads:[~2014-05-02 11:27 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-02 11:26 [Qemu-devel] [PATCH v3 00/14] qmp qga: Purge error_is_set() Markus Armbruster
2014-05-02 11:26 ` [Qemu-devel] [PATCH v3 01/14] qmp hmp: Consistently name Error * objects err, and not errp Markus Armbruster
2014-05-02 11:26 ` [Qemu-devel] [PATCH v3 02/14] qga: Consistently name Error ** objects errp, and not err Markus Armbruster
2014-05-02 11:26 ` [Qemu-devel] [PATCH v3 03/14] qmp: " Markus Armbruster
2014-05-02 11:26 ` [Qemu-devel] [PATCH v3 04/14] error: " Markus Armbruster
2014-05-02 11:26 ` Markus Armbruster [this message]
2014-05-02 11:26 ` [Qemu-devel] [PATCH v3 06/14] hmp: Guard against misuse of hmp_handle_error() Markus Armbruster
2014-05-02 11:26 ` [Qemu-devel] [PATCH v3 07/14] qapi: Drop redundant, unclean error_is_set() Markus Armbruster
2014-05-02 11:26 ` [Qemu-devel] [PATCH v3 08/14] tests/qapi-schema: Drop superfluous error_is_set() Markus Armbruster
2014-05-02 11:26 ` [Qemu-devel] [PATCH v3 09/14] qapi: Clean up fragile use of error_is_set() Markus Armbruster
2014-05-02 11:26 ` [Qemu-devel] [PATCH v3 10/14] qga: " Markus Armbruster
2014-05-02 11:26 ` [Qemu-devel] [PATCH v3 11/14] qga: Drop superfluous error_is_set() Markus Armbruster
2014-05-02 11:26 ` [Qemu-devel] [PATCH v3 12/14] qemu-option: Clean up fragile use of error_is_set() Markus Armbruster
2014-05-02 11:26 ` [Qemu-devel] [PATCH v3 13/14] dump: Drop pointless error_is_set(), DumpState member errp Markus Armbruster
2014-05-02 11:26 ` [Qemu-devel] [PATCH v3 14/14] qmp: Don't use error_is_set() to suppress additional errors Markus Armbruster
2014-05-02 12:34   ` Eric Blake
2014-05-07  6:08     ` Markus Armbruster
2014-05-07 14:08       ` Luiz Capitulino
2014-05-07 15:54         ` Markus Armbruster
2014-05-02 12:32 ` [Qemu-devel] [PATCH v3 00/14] qmp qga: Purge error_is_set() Eric Blake
2014-05-07 14:30 ` Luiz Capitulino
2014-05-07 16:00   ` Markus Armbruster

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=1399030002-27222-6-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=pbonzini@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).