qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Chen Gang <gang.chen.5i5j@gmail.com>
To: aliguori@us.ibm.com
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] vl.c: move "if (fd < 0)" into "if (fd <= STDERR_FILENO)"
Date: Sat, 28 Dec 2013 16:52:45 +0800	[thread overview]
Message-ID: <52BE915D.7090202@gmail.com> (raw)

For valid 'fd' (in most cases), it is enough to only check whether it
is larger than STDERR_FILENO, so recommend to move "if (fd < 0)" into
failure processing block.

Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
---
 vl.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/vl.c b/vl.c
index 2160933..fbea535 100644
--- a/vl.c
+++ b/vl.c
@@ -1064,15 +1064,10 @@ static int parse_add_fd(QemuOpts *opts, void *opaque)
     fdset_id = qemu_opt_get_number(opts, "set", -1);
     fd_opaque = qemu_opt_get(opts, "opaque");
 
-    if (fd < 0) {
-        qerror_report(ERROR_CLASS_GENERIC_ERROR,
-                      "fd option is required and must be non-negative");
-        return -1;
-    }
-
     if (fd <= STDERR_FILENO) {
         qerror_report(ERROR_CLASS_GENERIC_ERROR,
-                      "fd cannot be a standard I/O stream");
+                      fd < 0 ? "fd option is required and must be non-negative"
+                             : "fd cannot be a standard I/O stream");
         return -1;
     }
 
-- 
1.7.11.7

             reply	other threads:[~2013-12-28  8:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-28  8:52 Chen Gang [this message]
2013-12-28 23:43 ` [Qemu-devel] [PATCH] vl.c: move "if (fd < 0)" into "if (fd <= STDERR_FILENO)" Peter Maydell
2013-12-29 11:18   ` Chen Gang

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=52BE915D.7090202@gmail.com \
    --to=gang.chen.5i5j@gmail.com \
    --cc=aliguori@us.ibm.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).