From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pboldin@mirantis.com>
Received: from mail-wg0-f48.google.com (mail-wg0-f48.google.com [74.125.82.48])
 by dpdk.org (Postfix) with ESMTP id 2E8159A97
 for <dev@dpdk.org>; Thu,  2 Apr 2015 19:01:42 +0200 (CEST)
Received: by wgra20 with SMTP id a20so91399833wgr.3
 for <dev@dpdk.org>; Thu, 02 Apr 2015 10:01:42 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mirantis.com; s=google;
 h=from:to:subject:date:message-id:in-reply-to:references;
 bh=RiCy9mDJ48LOq0zhDboc5GAidggTTnjf0z0XIdsHl/Y=;
 b=Qfk2C0P4L1dAtGd4WkVeiYaGNjVMFOcuY/F+C1T6CY05Q20Zqk9wUpXlf+LTJ4tTcb
 fUghIsyelUTT7lQ+qs9+meMvSCFGO6d5lK2D7/QotAMXwWsSPM1gp/hIIwJHut0rp5bm
 wd8q8DeanNuK4m8FMmq6vGX1ziPSBY4gYWT68=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20130820;
 h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to
 :references;
 bh=RiCy9mDJ48LOq0zhDboc5GAidggTTnjf0z0XIdsHl/Y=;
 b=bXc6BTroNaZSelAfx8QSugk5EAh6LN2J/dgvy9oy3TcF28ge6lKkRDwUmEEXIQkvy9
 6I4KMhRm598gIENAA3YSo8Eh1wnlgvhYzMVlBGUgBSM0kF8LBrlBgDeBUhlD5uT7GS1g
 PCDrHPD3ZIQxOes+0WW041XzbvqfEpZoQp90NjPWS9qeUyrojM1c5fbCV4PaUCGQef7R
 RmPP8vSVA+5+e/AJTzfkIyLmjSnk9NDhXBGM1bmV4zh+fQSmALCP5ZH/0zaND+gkaWbb
 xpl6e8WZE+vWQLo5E9DIFnah9bocRggPmEuhrBMyjjJl0paFONMJceSqMiYDy9E2efcB
 2coQ==
X-Gm-Message-State: ALoCoQle8Gxia6dicuSQdXg64kqYueLJ8z0Acf16mJafC0VcB2u0McBgeZZwI6+xjipZUHNr/aGi
X-Received: by 10.180.24.233 with SMTP id x9mr26988369wif.9.1427994101966;
 Thu, 02 Apr 2015 10:01:41 -0700 (PDT)
Received: from pboldin-pc.kha.mirantis.net ([194.213.110.67])
 by mx.google.com with ESMTPSA id md2sm30801242wic.19.2015.04.02.10.01.41
 for <dev@dpdk.org>
 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
 Thu, 02 Apr 2015 10:01:41 -0700 (PDT)
From: Pavel Boldin <pboldin@mirantis.com>
To: dev@dpdk.org
Date: Thu,  2 Apr 2015 20:01:18 +0300
Message-Id: <1427994080-10163-4-git-send-email-pboldin@mirantis.com>
X-Mailer: git-send-email 1.9.1
In-Reply-To: <1427994080-10163-1-git-send-email-pboldin@mirantis.com>
References: <1427123731-15654-1-git-send-email-pboldin@mirantis.com>
 <1427994080-10163-1-git-send-email-pboldin@mirantis.com>
Subject: [dpdk-dev] [PATCH v4 3/5] vhost: eventfd_link: fix ioctl return
	values
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Thu, 02 Apr 2015 17:01:42 -0000

Fix ioctl return values:
 * `-EFAULT' when unable to fetch user supplied arguments,
 * `-ESRCH' when no target process is found,
 * `-ESTALE' when unable to get `struct files',
 * `-EBADF' when unable to get `struct file' for fd.
---
 lib/librte_vhost/eventfd_link/eventfd_link.c | 46 ++++++++++++++++++----------
 1 file changed, 30 insertions(+), 16 deletions(-)

diff --git a/lib/librte_vhost/eventfd_link/eventfd_link.c b/lib/librte_vhost/eventfd_link/eventfd_link.c
index 2a29999..0a06594 100644
--- a/lib/librte_vhost/eventfd_link/eventfd_link.c
+++ b/lib/librte_vhost/eventfd_link/eventfd_link.c
@@ -92,33 +92,38 @@ eventfd_link_ioctl_copy(unsigned long arg)
 	struct files_struct *files;
 	struct fdtable *fdt;
 	struct eventfd_copy eventfd_copy;
+	long ret = -EFAULT;
 
-	if (copy_from_user(&eventfd_copy, argp,
-		sizeof(struct eventfd_copy)))
-		return -EFAULT;
+	if (copy_from_user(&eventfd_copy, argp, sizeof(struct eventfd_copy)))
+		goto out;
 
 	/*
 	 * Find the task struct for the target pid
 	 */
+	ret = -ESRCH;
+
 	task_target =
-		pid_task(find_vpid(eventfd_copy.target_pid), PIDTYPE_PID);
+		get_pid_task(find_vpid(eventfd_copy.target_pid), PIDTYPE_PID);
 	if (task_target == NULL) {
-		pr_debug("Failed to get mem ctx for target pid\n");
-		return -EFAULT;
+		pr_info("Unable to find pid %d\n", eventfd_copy.target_pid);
+		goto out;
 	}
 
+	ret = -ESTALE;
 	files = get_files_struct(current);
 	if (files == NULL) {
-		pr_debug("Failed to get files struct\n");
-		return -EFAULT;
+		pr_info("Failed to get current files struct\n");
+		goto out_task;
 	}
 
+	ret = -EBADF;
 	file = fget_from_files(files, eventfd_copy.source_fd);
-	put_files_struct(files);
 
 	if (file == NULL) {
-		pr_debug("Failed to get file from source pid\n");
-		return 0;
+		pr_info("Failed to get fd %d from source\n",
+			eventfd_copy.source_fd);
+		put_files_struct(files);
+		goto out_task;
 	}
 
 	/*
@@ -131,22 +136,27 @@ eventfd_link_ioctl_copy(unsigned long arg)
 	fdt->fd[eventfd_copy.source_fd] = NULL;
 	spin_unlock(&files->file_lock);
 
+	put_files_struct(files);
+
 	/*
 	 * Find the file struct associated with the target fd.
 	 */
 
+	ret = -ESTALE;
 	files = get_files_struct(task_target);
 	if (files == NULL) {
-		pr_debug("Failed to get files struct\n");
-		return -EFAULT;
+		pr_info("Failed to get target files struct\n");
+		goto out_task;
 	}
 
+	ret = -EBADF;
 	file = fget_from_files(files, eventfd_copy.target_fd);
 	put_files_struct(files);
 
 	if (file == NULL) {
-		pr_debug("Failed to get file from target pid\n");
-		return 0;
+		pr_info("Failed to get fd %d from target\n",
+			eventfd_copy.target_fd);
+		goto out_task;
 	}
 
 	/*
@@ -155,8 +165,12 @@ eventfd_link_ioctl_copy(unsigned long arg)
 	 */
 
 	fd_install(eventfd_copy.source_fd, file);
+	ret = 0;
 
-	return 0;
+out_task:
+	put_task_struct(task_target);
+out:
+	return ret;
 }
 
 static long
-- 
1.9.1