linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 1/2] input/uinput: replace breaks by goto out in uinput_ioctl_handler
@ 2014-01-22 17:23 Benjamin Tissoires
  2014-01-22 17:24 ` [PATCH v4 2/2] input/uinput: add UI_GET_SYSNAME ioctl to retrieve the sysfs path Benjamin Tissoires
  2014-01-23 14:35 ` [PATCH v4 1/2] input/uinput: replace breaks by goto out in uinput_ioctl_handler David Herrmann
  0 siblings, 2 replies; 4+ messages in thread
From: Benjamin Tissoires @ 2014-01-22 17:23 UTC (permalink / raw)
  To: Benjamin Tissoires, Dmitry Torokhov, David Herrmann,
	Peter Hutterer, linux-input, linux-kernel

From: Benjamin Tisssoires <benjamin.tissoires@redhat.com>

The current implementation prevents us to add variable-length ioctl.
Use a bunch of gotos instead of break to allow us to do so.

No functional changes.

Signed-off-by: Benjamin Tisssoires <benjamin.tissoires@redhat.com>
---

changes since v3:
- brand new patch :)

 drivers/input/misc/uinput.c | 56 ++++++++++++++++++++++-----------------------
 1 file changed, 27 insertions(+), 29 deletions(-)

diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index 7728359..d8ae08d 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -693,51 +693,51 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
 	switch (cmd) {
 		case UI_DEV_CREATE:
 			retval = uinput_create_device(udev);
-			break;
+			goto out;
 
 		case UI_DEV_DESTROY:
 			uinput_destroy_device(udev);
-			break;
+			goto out;
 
 		case UI_SET_EVBIT:
 			retval = uinput_set_bit(arg, evbit, EV_MAX);
-			break;
+			goto out;
 
 		case UI_SET_KEYBIT:
 			retval = uinput_set_bit(arg, keybit, KEY_MAX);
-			break;
+			goto out;
 
 		case UI_SET_RELBIT:
 			retval = uinput_set_bit(arg, relbit, REL_MAX);
-			break;
+			goto out;
 
 		case UI_SET_ABSBIT:
 			retval = uinput_set_bit(arg, absbit, ABS_MAX);
-			break;
+			goto out;
 
 		case UI_SET_MSCBIT:
 			retval = uinput_set_bit(arg, mscbit, MSC_MAX);
-			break;
+			goto out;
 
 		case UI_SET_LEDBIT:
 			retval = uinput_set_bit(arg, ledbit, LED_MAX);
-			break;
+			goto out;
 
 		case UI_SET_SNDBIT:
 			retval = uinput_set_bit(arg, sndbit, SND_MAX);
-			break;
+			goto out;
 
 		case UI_SET_FFBIT:
 			retval = uinput_set_bit(arg, ffbit, FF_MAX);
-			break;
+			goto out;
 
 		case UI_SET_SWBIT:
 			retval = uinput_set_bit(arg, swbit, SW_MAX);
-			break;
+			goto out;
 
 		case UI_SET_PROPBIT:
 			retval = uinput_set_bit(arg, propbit, INPUT_PROP_MAX);
-			break;
+			goto out;
 
 		case UI_SET_PHYS:
 			if (udev->state == UIST_CREATED) {
@@ -753,18 +753,18 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
 
 			kfree(udev->dev->phys);
 			udev->dev->phys = phys;
-			break;
+			goto out;
 
 		case UI_BEGIN_FF_UPLOAD:
 			retval = uinput_ff_upload_from_user(p, &ff_up);
 			if (retval)
-				break;
+				goto out;
 
 			req = uinput_request_find(udev, ff_up.request_id);
 			if (!req || req->code != UI_FF_UPLOAD ||
 			    !req->u.upload.effect) {
 				retval = -EINVAL;
-				break;
+				goto out;
 			}
 
 			ff_up.retval = 0;
@@ -775,65 +775,63 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
 				memset(&ff_up.old, 0, sizeof(struct ff_effect));
 
 			retval = uinput_ff_upload_to_user(p, &ff_up);
-			break;
+			goto out;
 
 		case UI_BEGIN_FF_ERASE:
 			if (copy_from_user(&ff_erase, p, sizeof(ff_erase))) {
 				retval = -EFAULT;
-				break;
+				goto out;
 			}
 
 			req = uinput_request_find(udev, ff_erase.request_id);
 			if (!req || req->code != UI_FF_ERASE) {
 				retval = -EINVAL;
-				break;
+				goto out;
 			}
 
 			ff_erase.retval = 0;
 			ff_erase.effect_id = req->u.effect_id;
 			if (copy_to_user(p, &ff_erase, sizeof(ff_erase))) {
 				retval = -EFAULT;
-				break;
+				goto out;
 			}
 
-			break;
+			goto out;
 
 		case UI_END_FF_UPLOAD:
 			retval = uinput_ff_upload_from_user(p, &ff_up);
 			if (retval)
-				break;
+				goto out;
 
 			req = uinput_request_find(udev, ff_up.request_id);
 			if (!req || req->code != UI_FF_UPLOAD ||
 			    !req->u.upload.effect) {
 				retval = -EINVAL;
-				break;
+				goto out;
 			}
 
 			req->retval = ff_up.retval;
 			uinput_request_done(udev, req);
-			break;
+			goto out;
 
 		case UI_END_FF_ERASE:
 			if (copy_from_user(&ff_erase, p, sizeof(ff_erase))) {
 				retval = -EFAULT;
-				break;
+				goto out;
 			}
 
 			req = uinput_request_find(udev, ff_erase.request_id);
 			if (!req || req->code != UI_FF_ERASE) {
 				retval = -EINVAL;
-				break;
+				goto out;
 			}
 
 			req->retval = ff_erase.retval;
 			uinput_request_done(udev, req);
-			break;
-
-		default:
-			retval = -EINVAL;
+			goto out;
 	}
 
+	retval = -EINVAL;
  out:
 	mutex_unlock(&udev->mutex);
 	return retval;
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v4 2/2] input/uinput: add UI_GET_SYSNAME ioctl to retrieve the sysfs path
  2014-01-22 17:23 [PATCH v4 1/2] input/uinput: replace breaks by goto out in uinput_ioctl_handler Benjamin Tissoires
@ 2014-01-22 17:24 ` Benjamin Tissoires
  2014-01-23 14:37   ` David Herrmann
  2014-01-23 14:35 ` [PATCH v4 1/2] input/uinput: replace breaks by goto out in uinput_ioctl_handler David Herrmann
  1 sibling, 1 reply; 4+ messages in thread
From: Benjamin Tissoires @ 2014-01-22 17:24 UTC (permalink / raw)
  To: Benjamin Tissoires, Dmitry Torokhov, David Herrmann,
	Peter Hutterer, linux-input, linux-kernel

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>
---

Hi guys,

a new version of this patch with a brand new commit message.
Happy reviewing :)

changes since v3:
- new commit message (I hope it will be better now)
- removed the -EAGAIN stuff thanks to the previous patch (not in v3)
- used "put_user(0, (char *)dest + len - 1);" instead of "copy_to_user(dest + len - 1, "\0", 1);"
- check if maxlen == 0

changes since v2:
- the ioctl returns only the device name, thus I renamed the ioctl to UI_GET_SYSNAME
- reordered uinput_str_to_user() arguments
- be sure to terminate the user string we send by \0
- abort if udev->state is not UIST_CREATED
- dropped the patch 1/2 (adding resolution to uinput) because I think David has
  already it in one of his queues (ABS2 IIRC)

The corresponding libevdev patch is still here:
http://lists.freedesktop.org/archives/input-tools/2014-January/000757.html

Cheers,
Benjamin

 drivers/input/misc/uinput.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/uinput.h      |  2 ++
 include/uapi/linux/uinput.h | 13 ++++++++++++-
 3 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index d8ae08d..b51269f 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -20,6 +20,8 @@
  * Author: Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org>
  *
  * Changes/Revisions:
+ *	0.4	01/09/2014 (Benjamin Tissoires <benjamin.tissoires@redhat.com>)
+ *		- add UI_GET_SYSNAME ioctl
  *	0.3	09/04/2006 (Anssi Hannula <anssi.hannula@gmail.com>)
  *		- updated ff support for the changes in kernel interface
  *		- added MODULE_VERSION
@@ -670,6 +672,30 @@ static int uinput_ff_upload_from_user(const char __user *buffer,
 	__ret;						\
 })
 
+static int uinput_str_to_user(void __user *dest, const char *str,
+			      unsigned int maxlen)
+{
+	int len, ret;
+
+	if (!str)
+		return -ENOENT;
+
+	if (maxlen == 0)
+		return -EINVAL;
+
+	len = strlen(str) + 1;
+	if (len > maxlen)
+		len = maxlen;
+
+	ret = copy_to_user(dest, str, len);
+	if (ret)
+		return -EFAULT;
+
+	/* force terminating '\0' */
+	ret = put_user(0, (char *)dest + len - 1);
+	return ret ? -EFAULT : len;
+}
+
 static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
 				 unsigned long arg, void __user *p)
 {
@@ -679,6 +705,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		*name;
+	unsigned int		size;
 
 	retval = mutex_lock_interruptible(&udev->mutex);
 	if (retval)
@@ -831,6 +859,20 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
 			goto out;
 	}
 
+	size = _IOC_SIZE(cmd);
+
+	/* Now check variable-length commands */
+	switch (cmd & ~IOCSIZE_MASK) {
+	case UI_GET_SYSNAME(0):
+		if (udev->state != UIST_CREATED) {
+			retval = -ENOENT;
+			goto out;
+		}
+		name = dev_name(&udev->dev->dev);
+		retval = uinput_str_to_user(p, name, size);
+		goto out;
+	}
+
 	retval = -EINVAL;
  out:
 	mutex_unlock(&udev->mutex);
diff --git a/include/linux/uinput.h b/include/linux/uinput.h
index 0a4487d..0994c0d 100644
--- a/include/linux/uinput.h
+++ b/include/linux/uinput.h
@@ -20,6 +20,8 @@
  * Author: Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org>
  *
  * Changes/Revisions:
+ *	0.4	01/09/2014 (Benjamin Tissoires <benjamin.tissoires@redhat.com>)
+ *		- add UI_GET_SYSNAME ioctl
  *	0.3	24/05/2006 (Anssi Hannula <anssi.hannulagmail.com>)
  *		- 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 fe46431..0389b48 100644
--- a/include/uapi/linux/uinput.h
+++ b/include/uapi/linux/uinput.h
@@ -20,6 +20,8 @@
  * Author: Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org>
  *
  * Changes/Revisions:
+ *	0.4	01/09/2014 (Benjamin Tissoires <benjamin.tissoires@redhat.com>)
+ *		- add UI_GET_SYSNAME ioctl
  *	0.3	24/05/2006 (Anssi Hannula <anssi.hannulagmail.com>)
  *		- update ff support for the changes in kernel interface
  *		- add UINPUT_VERSION
@@ -35,7 +37,7 @@
 #include <linux/types.h>
 #include <linux/input.h>
 
-#define UINPUT_VERSION		3
+#define UINPUT_VERSION		4
 
 
 struct uinput_ff_upload {
@@ -73,6 +75,15 @@ 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)
 
+/**
+ * UI_GET_SYSNAME - get the sysfs name of the created uinput device
+ *
+ * @return the sysfs name of the created virtual input device.
+ * The complete sysfs path is then /sys/devices/virtual/input/--NAME--
+ * Usually, it is in the form "inputN"
+ */
+#define UI_GET_SYSNAME(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.
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v4 1/2] input/uinput: replace breaks by goto out in uinput_ioctl_handler
  2014-01-22 17:23 [PATCH v4 1/2] input/uinput: replace breaks by goto out in uinput_ioctl_handler Benjamin Tissoires
  2014-01-22 17:24 ` [PATCH v4 2/2] input/uinput: add UI_GET_SYSNAME ioctl to retrieve the sysfs path Benjamin Tissoires
@ 2014-01-23 14:35 ` David Herrmann
  1 sibling, 0 replies; 4+ messages in thread
From: David Herrmann @ 2014-01-23 14:35 UTC (permalink / raw)
  To: Benjamin Tissoires
  Cc: Benjamin Tissoires, Dmitry Torokhov, Peter Hutterer,
	open list:HID CORE LAYER, linux-kernel

Hi Benjamin

On Wed, Jan 22, 2014 at 6:23 PM, Benjamin Tissoires
<benjamin.tissoires@redhat.com> wrote:
> From: Benjamin Tisssoires <benjamin.tissoires@redhat.com>
>
> The current implementation prevents us to add variable-length ioctl.
> Use a bunch of gotos instead of break to allow us to do so.
>
> No functional changes.

Looks good.

Reviewed-by: David Herrmann <dh.herrmann@gmail.com>

Thanks
David

> Signed-off-by: Benjamin Tisssoires <benjamin.tissoires@redhat.com>
> ---
>
> changes since v3:
> - brand new patch :)
>
>  drivers/input/misc/uinput.c | 56 ++++++++++++++++++++++-----------------------
>  1 file changed, 27 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
> index 7728359..d8ae08d 100644
> --- a/drivers/input/misc/uinput.c
> +++ b/drivers/input/misc/uinput.c
> @@ -693,51 +693,51 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
>         switch (cmd) {
>                 case UI_DEV_CREATE:
>                         retval = uinput_create_device(udev);
> -                       break;
> +                       goto out;
>
>                 case UI_DEV_DESTROY:
>                         uinput_destroy_device(udev);
> -                       break;
> +                       goto out;
>
>                 case UI_SET_EVBIT:
>                         retval = uinput_set_bit(arg, evbit, EV_MAX);
> -                       break;
> +                       goto out;
>
>                 case UI_SET_KEYBIT:
>                         retval = uinput_set_bit(arg, keybit, KEY_MAX);
> -                       break;
> +                       goto out;
>
>                 case UI_SET_RELBIT:
>                         retval = uinput_set_bit(arg, relbit, REL_MAX);
> -                       break;
> +                       goto out;
>
>                 case UI_SET_ABSBIT:
>                         retval = uinput_set_bit(arg, absbit, ABS_MAX);
> -                       break;
> +                       goto out;
>
>                 case UI_SET_MSCBIT:
>                         retval = uinput_set_bit(arg, mscbit, MSC_MAX);
> -                       break;
> +                       goto out;
>
>                 case UI_SET_LEDBIT:
>                         retval = uinput_set_bit(arg, ledbit, LED_MAX);
> -                       break;
> +                       goto out;
>
>                 case UI_SET_SNDBIT:
>                         retval = uinput_set_bit(arg, sndbit, SND_MAX);
> -                       break;
> +                       goto out;
>
>                 case UI_SET_FFBIT:
>                         retval = uinput_set_bit(arg, ffbit, FF_MAX);
> -                       break;
> +                       goto out;
>
>                 case UI_SET_SWBIT:
>                         retval = uinput_set_bit(arg, swbit, SW_MAX);
> -                       break;
> +                       goto out;
>
>                 case UI_SET_PROPBIT:
>                         retval = uinput_set_bit(arg, propbit, INPUT_PROP_MAX);
> -                       break;
> +                       goto out;
>
>                 case UI_SET_PHYS:
>                         if (udev->state == UIST_CREATED) {
> @@ -753,18 +753,18 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
>
>                         kfree(udev->dev->phys);
>                         udev->dev->phys = phys;
> -                       break;
> +                       goto out;
>
>                 case UI_BEGIN_FF_UPLOAD:
>                         retval = uinput_ff_upload_from_user(p, &ff_up);
>                         if (retval)
> -                               break;
> +                               goto out;
>
>                         req = uinput_request_find(udev, ff_up.request_id);
>                         if (!req || req->code != UI_FF_UPLOAD ||
>                             !req->u.upload.effect) {
>                                 retval = -EINVAL;
> -                               break;
> +                               goto out;
>                         }
>
>                         ff_up.retval = 0;
> @@ -775,65 +775,63 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
>                                 memset(&ff_up.old, 0, sizeof(struct ff_effect));
>
>                         retval = uinput_ff_upload_to_user(p, &ff_up);
> -                       break;
> +                       goto out;
>
>                 case UI_BEGIN_FF_ERASE:
>                         if (copy_from_user(&ff_erase, p, sizeof(ff_erase))) {
>                                 retval = -EFAULT;
> -                               break;
> +                               goto out;
>                         }
>
>                         req = uinput_request_find(udev, ff_erase.request_id);
>                         if (!req || req->code != UI_FF_ERASE) {
>                                 retval = -EINVAL;
> -                               break;
> +                               goto out;
>                         }
>
>                         ff_erase.retval = 0;
>                         ff_erase.effect_id = req->u.effect_id;
>                         if (copy_to_user(p, &ff_erase, sizeof(ff_erase))) {
>                                 retval = -EFAULT;
> -                               break;
> +                               goto out;
>                         }
>
> -                       break;
> +                       goto out;
>
>                 case UI_END_FF_UPLOAD:
>                         retval = uinput_ff_upload_from_user(p, &ff_up);
>                         if (retval)
> -                               break;
> +                               goto out;
>
>                         req = uinput_request_find(udev, ff_up.request_id);
>                         if (!req || req->code != UI_FF_UPLOAD ||
>                             !req->u.upload.effect) {
>                                 retval = -EINVAL;
> -                               break;
> +                               goto out;
>                         }
>
>                         req->retval = ff_up.retval;
>                         uinput_request_done(udev, req);
> -                       break;
> +                       goto out;
>
>                 case UI_END_FF_ERASE:
>                         if (copy_from_user(&ff_erase, p, sizeof(ff_erase))) {
>                                 retval = -EFAULT;
> -                               break;
> +                               goto out;
>                         }
>
>                         req = uinput_request_find(udev, ff_erase.request_id);
>                         if (!req || req->code != UI_FF_ERASE) {
>                                 retval = -EINVAL;
> -                               break;
> +                               goto out;
>                         }
>
>                         req->retval = ff_erase.retval;
>                         uinput_request_done(udev, req);
> -                       break;
> -
> -               default:
> -                       retval = -EINVAL;
> +                       goto out;
>         }
>
> +       retval = -EINVAL;
>   out:
>         mutex_unlock(&udev->mutex);
>         return retval;
> --
> 1.8.4.2
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v4 2/2] input/uinput: add UI_GET_SYSNAME ioctl to retrieve the sysfs path
  2014-01-22 17:24 ` [PATCH v4 2/2] input/uinput: add UI_GET_SYSNAME ioctl to retrieve the sysfs path Benjamin Tissoires
@ 2014-01-23 14:37   ` David Herrmann
  0 siblings, 0 replies; 4+ messages in thread
From: David Herrmann @ 2014-01-23 14:37 UTC (permalink / raw)
  To: Benjamin Tissoires
  Cc: Benjamin Tissoires, Dmitry Torokhov, Peter Hutterer,
	open list:HID CORE LAYER, linux-kernel

Hi Benjamin

On Wed, Jan 22, 2014 at 6:24 PM, Benjamin Tissoires
<benjamin.tissoires@redhat.com> wrote:
> 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>
> ---
>
> Hi guys,
>
> a new version of this patch with a brand new commit message.
> Happy reviewing :)
>
> changes since v3:
> - new commit message (I hope it will be better now)
> - removed the -EAGAIN stuff thanks to the previous patch (not in v3)
> - used "put_user(0, (char *)dest + len - 1);" instead of "copy_to_user(dest + len - 1, "\0", 1);"
> - check if maxlen == 0
>
> changes since v2:
> - the ioctl returns only the device name, thus I renamed the ioctl to UI_GET_SYSNAME
> - reordered uinput_str_to_user() arguments
> - be sure to terminate the user string we send by \0
> - abort if udev->state is not UIST_CREATED
> - dropped the patch 1/2 (adding resolution to uinput) because I think David has
>   already it in one of his queues (ABS2 IIRC)
>
> The corresponding libevdev patch is still here:
> http://lists.freedesktop.org/archives/input-tools/2014-January/000757.html
>
> Cheers,
> Benjamin
>
>  drivers/input/misc/uinput.c | 42 ++++++++++++++++++++++++++++++++++++++++++
>  include/linux/uinput.h      |  2 ++
>  include/uapi/linux/uinput.h | 13 ++++++++++++-
>  3 files changed, 56 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
> index d8ae08d..b51269f 100644
> --- a/drivers/input/misc/uinput.c
> +++ b/drivers/input/misc/uinput.c
> @@ -20,6 +20,8 @@
>   * Author: Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org>
>   *
>   * Changes/Revisions:
> + *     0.4     01/09/2014 (Benjamin Tissoires <benjamin.tissoires@redhat.com>)
> + *             - add UI_GET_SYSNAME ioctl
>   *     0.3     09/04/2006 (Anssi Hannula <anssi.hannula@gmail.com>)
>   *             - updated ff support for the changes in kernel interface
>   *             - added MODULE_VERSION
> @@ -670,6 +672,30 @@ static int uinput_ff_upload_from_user(const char __user *buffer,
>         __ret;                                          \
>  })
>
> +static int uinput_str_to_user(void __user *dest, const char *str,
> +                             unsigned int maxlen)
> +{
> +       int len, ret;
> +
> +       if (!str)
> +               return -ENOENT;
> +
> +       if (maxlen == 0)
> +               return -EINVAL;
> +
> +       len = strlen(str) + 1;
> +       if (len > maxlen)
> +               len = maxlen;
> +
> +       ret = copy_to_user(dest, str, len);

Technically you could use "len - 1" here, but it's fine.

Reviewed-by: David Herrmann <dh.herrmann@gmail.com>

Thanks
David

> +       if (ret)
> +               return -EFAULT;
> +
> +       /* force terminating '\0' */
> +       ret = put_user(0, (char *)dest + len - 1);
> +       return ret ? -EFAULT : len;
> +}
> +
>  static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
>                                  unsigned long arg, void __user *p)
>  {
> @@ -679,6 +705,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              *name;
> +       unsigned int            size;
>
>         retval = mutex_lock_interruptible(&udev->mutex);
>         if (retval)
> @@ -831,6 +859,20 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
>                         goto out;
>         }
>
> +       size = _IOC_SIZE(cmd);
> +
> +       /* Now check variable-length commands */
> +       switch (cmd & ~IOCSIZE_MASK) {
> +       case UI_GET_SYSNAME(0):
> +               if (udev->state != UIST_CREATED) {
> +                       retval = -ENOENT;
> +                       goto out;
> +               }
> +               name = dev_name(&udev->dev->dev);
> +               retval = uinput_str_to_user(p, name, size);
> +               goto out;
> +       }
> +
>         retval = -EINVAL;
>   out:
>         mutex_unlock(&udev->mutex);
> diff --git a/include/linux/uinput.h b/include/linux/uinput.h
> index 0a4487d..0994c0d 100644
> --- a/include/linux/uinput.h
> +++ b/include/linux/uinput.h
> @@ -20,6 +20,8 @@
>   * Author: Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org>
>   *
>   * Changes/Revisions:
> + *     0.4     01/09/2014 (Benjamin Tissoires <benjamin.tissoires@redhat.com>)
> + *             - add UI_GET_SYSNAME ioctl
>   *     0.3     24/05/2006 (Anssi Hannula <anssi.hannulagmail.com>)
>   *             - 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 fe46431..0389b48 100644
> --- a/include/uapi/linux/uinput.h
> +++ b/include/uapi/linux/uinput.h
> @@ -20,6 +20,8 @@
>   * Author: Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org>
>   *
>   * Changes/Revisions:
> + *     0.4     01/09/2014 (Benjamin Tissoires <benjamin.tissoires@redhat.com>)
> + *             - add UI_GET_SYSNAME ioctl
>   *     0.3     24/05/2006 (Anssi Hannula <anssi.hannulagmail.com>)
>   *             - update ff support for the changes in kernel interface
>   *             - add UINPUT_VERSION
> @@ -35,7 +37,7 @@
>  #include <linux/types.h>
>  #include <linux/input.h>
>
> -#define UINPUT_VERSION         3
> +#define UINPUT_VERSION         4
>
>
>  struct uinput_ff_upload {
> @@ -73,6 +75,15 @@ 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)
>
> +/**
> + * UI_GET_SYSNAME - get the sysfs name of the created uinput device
> + *
> + * @return the sysfs name of the created virtual input device.
> + * The complete sysfs path is then /sys/devices/virtual/input/--NAME--
> + * Usually, it is in the form "inputN"
> + */
> +#define UI_GET_SYSNAME(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.
> --
> 1.8.4.2
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-01-23 14:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-22 17:23 [PATCH v4 1/2] input/uinput: replace breaks by goto out in uinput_ioctl_handler Benjamin Tissoires
2014-01-22 17:24 ` [PATCH v4 2/2] input/uinput: add UI_GET_SYSNAME ioctl to retrieve the sysfs path Benjamin Tissoires
2014-01-23 14:37   ` David Herrmann
2014-01-23 14:35 ` [PATCH v4 1/2] input/uinput: replace breaks by goto out in uinput_ioctl_handler David Herrmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).