From patchwork Sat Dec 28 08:52:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Gang X-Patchwork-Id: 305633 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0EB0E2C00C3 for ; Sun, 29 Dec 2013 10:22:47 +1100 (EST) Received: from localhost ([::1]:53638 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vx3DQ-0000Pw-QM for incoming@patchwork.ozlabs.org; Sat, 28 Dec 2013 18:22:44 -0500 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :content-type:content-transfer-encoding; bh=1Q2a3fToOlyoNyjZNmV9g0mS4FdE9VALybGyeL2lg7Y=; b=uxJ9sY1Q+H3kQxAX6vl+BC5PxpBPW+Cd1pPVt+ENGKCdy4491SW0OVZ9a2k6T+3wPZ B2sF0a4exwdohgcZGVGFrwVaHnEcRgim7OMyQDrAHaOCsHheUiV91iwZ0m2KwcKGMi1Q DYpPRcPC0FW0yDhFJCMRkpoaLcsP9qgfdTqLMyadTPEBewqKBJOiBSV/KRm5gDNNNx1a YMDJfKoX8/yTrAeJw1bVn9sPap/vmta4ZUyQ2NiOrCFgpS8tZRAj7rrllEwcDvTc25vG JigeWfn7GrDJGL1n+Jy+LoT5LGpoEoo78IzLCRaFjzgxGsEHdAjdK9HjDu1njUCBv+9t /wsw== X-Received: by 10.68.245.200 with SMTP id xq8mr55433606pbc.21.1388220770933; Sat, 28 Dec 2013 00:52:50 -0800 (PST) Received: from [192.168.1.100] ([223.72.65.18]) by mx.google.com with ESMTPSA id vn10sm67397210pbc.21.2013.12.28.00.52.49 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Sat, 28 Dec 2013 00:52:50 -0800 (PST) Message-ID: <52BE915D.7090202@gmail.com> Date: Sat, 28 Dec 2013 16:52:45 +0800 From: Chen Gang User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130625 Thunderbird/17.0.7 MIME-Version: 1.0 To: aliguori@us.ibm.com X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c02::234 X-Mailman-Approved-At: Sat, 28 Dec 2013 18:21:38 -0500 Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH] vl.c: move "if (fd < 0)" into "if (fd <= STDERR_FILENO)" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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; }