aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorBenjamin Tissoires <benjamin.tissoires@redhat.com>2014-01-30 20:20:24 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2014-02-12 18:00:34 -0500
commite3480a61fca72d40d6dc4baaf37e94fcbfa95e19 (patch)
treea34ddb7b967f9bed73ef31546f81b0bababef773 /drivers/input
parent9d51e801dba0c79ae979ef2f6928e402eb41009b (diff)
Input: uinput - add UI_GET_SYSNAME ioctl to retrieve the sysfs path
uinput is used in the xorg-integration-tests suite and in the wayland test suite. These automated tests suites create many virtual input devices and then hook something to read these newly created devices. Currently, uinput does not provide the created input device, which means that we rely 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 without any doubts the event node. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Reviewed-by: David Herrmann <dh.herrmann@gmail.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/misc/uinput.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index d8ae08d12abf..856936247500 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -20,6 +20,8 @@
20 * Author: Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org> 20 * Author: Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org>
21 * 21 *
22 * Changes/Revisions: 22 * Changes/Revisions:
23 * 0.4 01/09/2014 (Benjamin Tissoires <benjamin.tissoires@redhat.com>)
24 * - add UI_GET_SYSNAME ioctl
23 * 0.3 09/04/2006 (Anssi Hannula <anssi.hannula@gmail.com>) 25 * 0.3 09/04/2006 (Anssi Hannula <anssi.hannula@gmail.com>)
24 * - updated ff support for the changes in kernel interface 26 * - updated ff support for the changes in kernel interface
25 * - added MODULE_VERSION 27 * - added MODULE_VERSION
@@ -670,6 +672,31 @@ static int uinput_ff_upload_from_user(const char __user *buffer,
670 __ret; \ 672 __ret; \
671}) 673})
672 674
675static int uinput_str_to_user(void __user *dest, const char *str,
676 unsigned int maxlen)
677{
678 char __user *p = dest;
679 int len, ret;
680
681 if (!str)
682 return -ENOENT;
683
684 if (maxlen == 0)
685 return -EINVAL;
686
687 len = strlen(str) + 1;
688 if (len > maxlen)
689 len = maxlen;
690
691 ret = copy_to_user(p, str, len);
692 if (ret)
693 return -EFAULT;
694
695 /* force terminating '\0' */
696 ret = put_user(0, p + len - 1);
697 return ret ? -EFAULT : len;
698}
699
673static long uinput_ioctl_handler(struct file *file, unsigned int cmd, 700static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
674 unsigned long arg, void __user *p) 701 unsigned long arg, void __user *p)
675{ 702{
@@ -679,6 +706,8 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
679 struct uinput_ff_erase ff_erase; 706 struct uinput_ff_erase ff_erase;
680 struct uinput_request *req; 707 struct uinput_request *req;
681 char *phys; 708 char *phys;
709 const char *name;
710 unsigned int size;
682 711
683 retval = mutex_lock_interruptible(&udev->mutex); 712 retval = mutex_lock_interruptible(&udev->mutex);
684 if (retval) 713 if (retval)
@@ -831,6 +860,20 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
831 goto out; 860 goto out;
832 } 861 }
833 862
863 size = _IOC_SIZE(cmd);
864
865 /* Now check variable-length commands */
866 switch (cmd & ~IOCSIZE_MASK) {
867 case UI_GET_SYSNAME(0):
868 if (udev->state != UIST_CREATED) {
869 retval = -ENOENT;
870 goto out;
871 }
872 name = dev_name(&udev->dev->dev);
873 retval = uinput_str_to_user(p, name, size);
874 goto out;
875 }
876
834 retval = -EINVAL; 877 retval = -EINVAL;
835 out: 878 out:
836 mutex_unlock(&udev->mutex); 879 mutex_unlock(&udev->mutex);