From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44771) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vwpdl-0001UL-6x for qemu-devel@nongnu.org; Sat, 28 Dec 2013 03:53:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vwpdc-0004Y2-Q1 for qemu-devel@nongnu.org; Sat, 28 Dec 2013 03:53:01 -0500 Received: from mail-pd0-x234.google.com ([2607:f8b0:400e:c02::234]:53466) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vwpdc-0004Xm-Iw for qemu-devel@nongnu.org; Sat, 28 Dec 2013 03:52:52 -0500 Received: by mail-pd0-f180.google.com with SMTP id q10so9802165pdj.11 for ; Sat, 28 Dec 2013 00:52:51 -0800 (PST) Message-ID: <52BE915D.7090202@gmail.com> Date: Sat, 28 Dec 2013 16:52:45 +0800 From: Chen Gang MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH] vl.c: move "if (fd < 0)" into "if (fd <= STDERR_FILENO)" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: aliguori@us.ibm.com Cc: qemu-devel@nongnu.org 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 --- 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