From patchwork Thu Apr 16 11:48:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Boldin X-Patchwork-Id: 4333 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 41537C384; Thu, 16 Apr 2015 13:48:42 +0200 (CEST) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com [209.85.217.176]) by dpdk.org (Postfix) with ESMTP id E434FC346 for ; Thu, 16 Apr 2015 13:48:37 +0200 (CEST) Received: by lbbzk7 with SMTP id zk7so56517519lbb.0 for ; Thu, 16 Apr 2015 04:48:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mirantis.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=maY+NARzJJArHKdJ7W9ifJzb91nUWzMT1jfh0MEcHN0=; b=T7SabEcfLvP48PY4/O0F2ly9d0eJL9BtV0qKyWLEBm8B8RkmqVGfnXYbREIpEx7oXJ 3Gb/OeMpnaB82f1c9/oX3sjL9sSLFPV9bwILzhpS18WwGX4n+qqeG/eOlG+/kWpnkFcB p4TEtYNv6E+3JiuZssRN+M1L3ECfSSGmeeggY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=maY+NARzJJArHKdJ7W9ifJzb91nUWzMT1jfh0MEcHN0=; b=bQgRDQPA21OEXkiNSoDiRrU3hSZI2BtatIU1lAPAZ4TzeLiLUmWoDqTuFOnx5nMaQN kked4RetbIqvoPA/J2bPZf7mIbiLOsfOQYOo1WqH0gTXYOvWpzv5gbXFPWo/E2/rR6HA RE+SIktNUEm9qLcVdLkeFvVT/vNw9dDRMb65EQMTRkDYRaqBRWbLnKArVCT2VED36Zk4 0IhT+oNnDYEJOKqR+IPTSqMIW51QmtOPRK+ZE6gqn/Qgru9VWfoZ5xqnuCHVem0gnk5k JWZQ2w+wE7Z9ErsnyKeTgxZutqWR3VLa+D2V71bfKs4Jia6rEe6q1WCTAphUTEqIgzeZ xlwg== X-Gm-Message-State: ALoCoQm1RSjdZRHDn/7GutoU4p3JXEznUy0uscS23cxqQeWZnduuDcGsPe7aBEEuJhChoDSI9z3P X-Received: by 10.152.88.46 with SMTP id bd14mr27884338lab.71.1429184917679; Thu, 16 Apr 2015 04:48:37 -0700 (PDT) Received: from pboldin-pc.kha.mirantis.net ([194.213.110.67]) by mx.google.com with ESMTPSA id oy3sm1636510lbb.1.2015.04.16.04.48.36 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Apr 2015 04:48:37 -0700 (PDT) From: Pavel Boldin To: dev@dpdk.org Date: Thu, 16 Apr 2015 14:48:28 +0300 Message-Id: <1429184910-30186-4-git-send-email-pboldin@mirantis.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1429184910-30186-1-git-send-email-pboldin@mirantis.com> References: <1427994080-10163-1-git-send-email-pboldin@mirantis.com> <1429184910-30186-1-git-send-email-pboldin@mirantis.com> Subject: [dpdk-dev] [PATCH v5 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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. Signed-off-by: Pavel Boldin --- 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