From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 4E3F85677 for ; Fri, 6 Mar 2015 12:05:55 +0100 (CET) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP; 06 Mar 2015 03:05:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,352,1422950400"; d="scan'208";a="694850820" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by orsmga002.jf.intel.com with ESMTP; 06 Mar 2015 03:05:53 -0800 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id t26B5ppd007637; Fri, 6 Mar 2015 19:05:51 +0800 Received: from shecgisg003.sh.intel.com (localhost [127.0.0.1]) by shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id t26B5m27027191; Fri, 6 Mar 2015 19:05:50 +0800 Received: (from hxie5@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id t26B5mPj027187; Fri, 6 Mar 2015 19:05:48 +0800 From: Huawei Xie To: dev@dpdk.org Date: Fri, 6 Mar 2015 19:05:43 +0800 Message-Id: <1425639943-27157-1-git-send-email-huawei.xie@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1425638358-26523-1-git-send-email-huawei.xie@intel.com> References: <1425638358-26523-1-git-send-email-huawei.xie@intel.com> Subject: [dpdk-dev] [PATCH] test whether file descriptor is valid before close it X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Mar 2015 11:05:55 -0000 This avoids closing -1 in our case. Signed-off-by: Huawei Xie --- lib/librte_vhost/virtio-net.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c index 6917fcf..4672e67 100644 --- a/lib/librte_vhost/virtio-net.c +++ b/lib/librte_vhost/virtio-net.c @@ -185,13 +185,13 @@ cleanup_device(struct virtio_net *dev) } /* Close any event notifiers opened by device. */ - if (dev->virtqueue[VIRTIO_RXQ]->callfd) + if ((int)dev->virtqueue[VIRTIO_RXQ]->callfd >= 0) close((int)dev->virtqueue[VIRTIO_RXQ]->callfd); - if (dev->virtqueue[VIRTIO_RXQ]->kickfd) + if ((int)dev->virtqueue[VIRTIO_RXQ]->kickfd >= 0) close((int)dev->virtqueue[VIRTIO_RXQ]->kickfd); - if (dev->virtqueue[VIRTIO_TXQ]->callfd) + if ((int)dev->virtqueue[VIRTIO_TXQ]->callfd >= 0) close((int)dev->virtqueue[VIRTIO_TXQ]->callfd); - if (dev->virtqueue[VIRTIO_TXQ]->kickfd) + if ((int)dev->virtqueue[VIRTIO_TXQ]->kickfd >= 0) close((int)dev->virtqueue[VIRTIO_TXQ]->kickfd); } -- 1.8.1.4