From patchwork Mon Jul 15 13:37:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 2827524 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2B088C0AB2 for ; Mon, 15 Jul 2013 13:37:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 567FE20196 for ; Mon, 15 Jul 2013 13:37:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0D15A2018D for ; Mon, 15 Jul 2013 13:37:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755724Ab3GONhY (ORCPT ); Mon, 15 Jul 2013 09:37:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39705 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755659Ab3GONhW (ORCPT ); Mon, 15 Jul 2013 09:37:22 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6FDbKMQ011057 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 15 Jul 2013 09:37:20 -0400 Received: from t410.redhat.com (ovpn-116-94.ams2.redhat.com [10.36.116.94]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r6FDbCga031219; Mon, 15 Jul 2013 09:37:17 -0400 From: Benjamin Tissoires To: Dmitry Torokhov , Benjamin Tissoires , Peter Hutterer , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Benjamin Tissoires Subject: [PATCH v2 2/2] input/uinput: add UI_GET_SYSPATH ioctl to retrieve the sysfs path Date: Mon, 15 Jul 2013 15:37:09 +0200 Message-Id: <1373895429-8846-2-git-send-email-benjamin.tissoires@redhat.com> In-Reply-To: <1373895429-8846-1-git-send-email-benjamin.tissoires@redhat.com> References: <1373895429-8846-1-git-send-email-benjamin.tissoires@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Evemu [1] uses uinput to replay devices traces it has recorded. However, the way evemu uses uinput is slightly different from how uinput is supposed to be used. Evemu creates the device node through uinput, bu inject events through the input device node directly (and skipping the uinput node). Currently, evemu relies on an heuristic to guess which input node was created. The problem is that is heuristic is subjected to races between different uinput devices or even with physical devices. Having a way to retrieve the sysfs path allows us to find the event node without having to rely on this heuristic. [1] http://www.freedesktop.org/wiki/Evemu/ Signed-off-by: Benjamin Tissoires Tested-by: Peter Hutterer --- drivers/input/misc/uinput.c | 37 ++++++++++++++++++++++++++++++++++++- include/linux/uinput.h | 1 + include/uapi/linux/uinput.h | 3 +++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index 7d518b4..49a9f7d 100644 --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c @@ -22,6 +22,7 @@ * Changes/Revisions: * 0.4 12/07/2013 (Peter Hutterer ) * - update uinput_user_dev struct to allow abs resolution + * - add UI_GET_SYSPATH ioctl * 0.3 09/04/2006 (Anssi Hannula ) * - updated ff support for the changes in kernel interface * - added MODULE_VERSION @@ -667,6 +668,21 @@ static int uinput_ff_upload_from_user(const char __user *buffer, __ret; \ }) +static int uinput_str_to_user(const char *str, unsigned int maxlen, + void __user *p) +{ + int len; + + if (!str) + return -ENOENT; + + len = strlen(str) + 1; + if (len > maxlen) + len = maxlen; + + return copy_to_user(p, str, len) ? -EFAULT : len; +} + static long uinput_ioctl_handler(struct file *file, unsigned int cmd, unsigned long arg, void __user *p) { @@ -676,6 +692,8 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd, struct uinput_ff_erase ff_erase; struct uinput_request *req; char *phys; + const char *path; + unsigned int size; retval = mutex_lock_interruptible(&udev->mutex); if (retval) @@ -828,7 +846,24 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd, break; default: - retval = -EINVAL; + retval = -EAGAIN; + } + + if (retval == -EAGAIN) { + size = _IOC_SIZE(cmd); + + /* Now check variable-length commands */ + switch (cmd & ~IOCSIZE_MASK) { + case UI_GET_SYSPATH(0): + path = kobject_get_path(&udev->dev->dev.kobj, + GFP_KERNEL); + retval = uinput_str_to_user(path, size, p); + kfree(path); + break; + + default: + retval = -EINVAL; + } } out: diff --git a/include/linux/uinput.h b/include/linux/uinput.h index 6291a22..64fab81 100644 --- a/include/linux/uinput.h +++ b/include/linux/uinput.h @@ -22,6 +22,7 @@ * Changes/Revisions: * 0.4 12/07/2013 (Peter Hutterer ) * - update uinput_user_dev struct to allow abs resolution + * - add UI_GET_SYSPATH ioctl * 0.3 24/05/2006 (Anssi Hannula ) * - update ff support for the changes in kernel interface * - add UINPUT_VERSION diff --git a/include/uapi/linux/uinput.h b/include/uapi/linux/uinput.h index f6a393b..d826409 100644 --- a/include/uapi/linux/uinput.h +++ b/include/uapi/linux/uinput.h @@ -22,6 +22,7 @@ * Changes/Revisions: * 0.4 12/07/2013 (Peter Hutterer ) * - update uinput_user_dev struct to allow abs resolution + * - add UI_GET_SYSPATH ioctl * 0.3 24/05/2006 (Anssi Hannula ) * - update ff support for the changes in kernel interface * - add UINPUT_VERSION @@ -75,6 +76,8 @@ struct uinput_ff_erase { #define UI_BEGIN_FF_ERASE _IOWR(UINPUT_IOCTL_BASE, 202, struct uinput_ff_erase) #define UI_END_FF_ERASE _IOW(UINPUT_IOCTL_BASE, 203, struct uinput_ff_erase) +#define UI_GET_SYSPATH(len) _IOC(_IOC_READ, UINPUT_IOCTL_BASE, 300, len) + /* * To write a force-feedback-capable driver, the upload_effect * and erase_effect callbacks in input_dev must be implemented.