* [PATCH] Input: uinput - uinput_validate_absbits() cleanup
@ 2014-06-19 13:12 David Herrmann
2014-06-20 0:56 ` Peter Hutterer
0 siblings, 1 reply; 2+ messages in thread
From: David Herrmann @ 2014-06-19 13:12 UTC (permalink / raw
To: linux-input
Cc: Dmitry Torokhov, Peter Hutterer, Benjamin Tissoires,
David Herrmann
This moves basic checks and setup from uinput_setup_device() into
uinput_validate_absbits() to make it easier to use. This way, we can call
it from other places without copying the boilerplate code.
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
---
drivers/input/misc/uinput.c | 40 +++++++++++++++++++++-------------------
1 file changed, 21 insertions(+), 19 deletions(-)
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index 8569362..615324c 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -311,7 +311,13 @@ static int uinput_open(struct inode *inode, struct file *file)
static int uinput_validate_absbits(struct input_dev *dev)
{
unsigned int cnt;
- int retval = 0;
+ int nslot;
+
+ if (!test_bit(EV_ABS, dev->evbit))
+ return 0;
+
+ /* check if absmin/absmax/absfuzz/absflat are filled as
+ * told in Documentation/input/input-programming.txt */
for (cnt = 0; cnt < ABS_CNT; cnt++) {
int min, max;
@@ -327,8 +333,7 @@ static int uinput_validate_absbits(struct input_dev *dev)
UINPUT_NAME, cnt,
input_abs_get_min(dev, cnt),
input_abs_get_max(dev, cnt));
- retval = -EINVAL;
- break;
+ return -EINVAL;
}
if (input_abs_get_flat(dev, cnt) >
@@ -340,11 +345,18 @@ static int uinput_validate_absbits(struct input_dev *dev)
input_abs_get_flat(dev, cnt),
input_abs_get_min(dev, cnt),
input_abs_get_max(dev, cnt));
- retval = -EINVAL;
- break;
+ return -EINVAL;
}
}
- return retval;
+
+ if (test_bit(ABS_MT_SLOT, dev->absbit)) {
+ nslot = input_abs_get_max(dev, ABS_MT_SLOT) + 1;
+ input_mt_init_slots(dev, nslot, 0);
+ } else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) {
+ input_set_events_per_packet(dev, 60);
+ }
+
+ return 0;
}
static int uinput_allocate_device(struct uinput_device *udev)
@@ -410,19 +422,9 @@ static int uinput_setup_device(struct uinput_device *udev,
input_abs_set_flat(dev, i, user_dev->absflat[i]);
}
- /* check if absmin/absmax/absfuzz/absflat are filled as
- * told in Documentation/input/input-programming.txt */
- if (test_bit(EV_ABS, dev->evbit)) {
- retval = uinput_validate_absbits(dev);
- if (retval < 0)
- goto exit;
- if (test_bit(ABS_MT_SLOT, dev->absbit)) {
- int nslot = input_abs_get_max(dev, ABS_MT_SLOT) + 1;
- input_mt_init_slots(dev, nslot, 0);
- } else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) {
- input_set_events_per_packet(dev, 60);
- }
- }
+ retval = uinput_validate_absbits(dev);
+ if (retval < 0)
+ goto exit;
udev->state = UIST_SETUP_COMPLETE;
retval = count;
--
2.0.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Input: uinput - uinput_validate_absbits() cleanup
2014-06-19 13:12 [PATCH] Input: uinput - uinput_validate_absbits() cleanup David Herrmann
@ 2014-06-20 0:56 ` Peter Hutterer
0 siblings, 0 replies; 2+ messages in thread
From: Peter Hutterer @ 2014-06-20 0:56 UTC (permalink / raw
To: David Herrmann; +Cc: linux-input, Dmitry Torokhov, Benjamin Tissoires
On Thu, Jun 19, 2014 at 03:12:59PM +0200, David Herrmann wrote:
> This moves basic checks and setup from uinput_setup_device() into
> uinput_validate_absbits() to make it easier to use. This way, we can call
> it from other places without copying the boilerplate code.
>
> Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Cheers,
Peter
> ---
> drivers/input/misc/uinput.c | 40 +++++++++++++++++++++-------------------
> 1 file changed, 21 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
> index 8569362..615324c 100644
> --- a/drivers/input/misc/uinput.c
> +++ b/drivers/input/misc/uinput.c
> @@ -311,7 +311,13 @@ static int uinput_open(struct inode *inode, struct file *file)
> static int uinput_validate_absbits(struct input_dev *dev)
> {
> unsigned int cnt;
> - int retval = 0;
> + int nslot;
> +
> + if (!test_bit(EV_ABS, dev->evbit))
> + return 0;
> +
> + /* check if absmin/absmax/absfuzz/absflat are filled as
> + * told in Documentation/input/input-programming.txt */
>
> for (cnt = 0; cnt < ABS_CNT; cnt++) {
> int min, max;
> @@ -327,8 +333,7 @@ static int uinput_validate_absbits(struct input_dev *dev)
> UINPUT_NAME, cnt,
> input_abs_get_min(dev, cnt),
> input_abs_get_max(dev, cnt));
> - retval = -EINVAL;
> - break;
> + return -EINVAL;
> }
>
> if (input_abs_get_flat(dev, cnt) >
> @@ -340,11 +345,18 @@ static int uinput_validate_absbits(struct input_dev *dev)
> input_abs_get_flat(dev, cnt),
> input_abs_get_min(dev, cnt),
> input_abs_get_max(dev, cnt));
> - retval = -EINVAL;
> - break;
> + return -EINVAL;
> }
> }
> - return retval;
> +
> + if (test_bit(ABS_MT_SLOT, dev->absbit)) {
> + nslot = input_abs_get_max(dev, ABS_MT_SLOT) + 1;
> + input_mt_init_slots(dev, nslot, 0);
> + } else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) {
> + input_set_events_per_packet(dev, 60);
> + }
> +
> + return 0;
> }
>
> static int uinput_allocate_device(struct uinput_device *udev)
> @@ -410,19 +422,9 @@ static int uinput_setup_device(struct uinput_device *udev,
> input_abs_set_flat(dev, i, user_dev->absflat[i]);
> }
>
> - /* check if absmin/absmax/absfuzz/absflat are filled as
> - * told in Documentation/input/input-programming.txt */
> - if (test_bit(EV_ABS, dev->evbit)) {
> - retval = uinput_validate_absbits(dev);
> - if (retval < 0)
> - goto exit;
> - if (test_bit(ABS_MT_SLOT, dev->absbit)) {
> - int nslot = input_abs_get_max(dev, ABS_MT_SLOT) + 1;
> - input_mt_init_slots(dev, nslot, 0);
> - } else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) {
> - input_set_events_per_packet(dev, 60);
> - }
> - }
> + retval = uinput_validate_absbits(dev);
> + if (retval < 0)
> + goto exit;
>
> udev->state = UIST_SETUP_COMPLETE;
> retval = count;
> --
> 2.0.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-06-20 0:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-19 13:12 [PATCH] Input: uinput - uinput_validate_absbits() cleanup David Herrmann
2014-06-20 0:56 ` Peter Hutterer
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.