evdev: fix decoding of EVIOCGBIT(0, ...)

There is a comment in drivers/input/evdev.c which says:
/* EV_SYN==0 is EV_CNT, _not_ SYN_CNT, see EVIOCGBIT */

That is, EVIOCGBIT(0, ...) should return a bit mask with supported
event types instead of SYN_* event codes.

* defs.h (evdev_ev): New prototype.
* evdev.c: Include "xlat/evdev_ev.h" and remove "xlat/evdev_sync.h".
(bit_ioctl) <case EV_SYN>: Replace EV_SYN with 0, use evdev_ev
with XT_SORTED in decode_bitset invocation instead.
* ioctl.c: Do not include "xlat/evdev_ev.h".
(evdev_decode_number): Print nr == 0x20 as "0" instead of "EV_SYN".
* tests/ioctl_evdev.c (main): Use 0 instead of EV_SYN in EVIOCGBIT
output.
* xlat/evdev_sync.in: Remove.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Fixes: v4.10~89 "Add decoding for evdev ioctls"
This commit is contained in:
Zhibin Li 2018-08-01 17:53:57 +08:00 committed by Dmitry V. Levin
parent 99300f217b
commit 5ee385e2eb
5 changed files with 10 additions and 13 deletions

1
defs.h
View File

@ -330,6 +330,7 @@ extern const struct xlat evdev_abs[];
/** Number of elements in evdev_abs array without the terminating record. */
extern const size_t evdev_abs_size;
extern const struct xlat evdev_ev[];
extern const struct xlat iffflags[];
extern const struct xlat ip_type_of_services[];
extern const struct xlat ipc_private[];

View File

@ -30,6 +30,7 @@
#include "defs.h"
#include "xlat/evdev_abs.h"
#include "xlat/evdev_ev.h"
#ifdef HAVE_LINUX_INPUT_H
@ -47,7 +48,6 @@
# include "xlat/evdev_relative_axes.h"
# include "xlat/evdev_snd.h"
# include "xlat/evdev_switch.h"
# include "xlat/evdev_sync.h"
# ifndef SYN_MAX
# define SYN_MAX 0xf
@ -258,9 +258,9 @@ bit_ioctl(struct tcb *const tcp, const unsigned int ev_nr,
const kernel_ulong_t arg)
{
switch (ev_nr) {
case EV_SYN:
return decode_bitset(tcp, arg, evdev_sync,
SYN_MAX, "SYN_???", XT_INDEXED);
case 0:
return decode_bitset(tcp, arg, evdev_ev,
EV_MAX, "EV_???", XT_SORTED);
case EV_KEY:
return decode_bitset(tcp, arg, evdev_keycode,
KEY_MAX, "KEY_???", XT_INDEXED);

View File

@ -33,8 +33,6 @@
#include <linux/ioctl.h>
#include "xlat/ioctl_dirs.h"
#include "xlat/evdev_ev.h"
static int
compare(const void *a, const void *b)
{
@ -99,7 +97,10 @@ evdev_decode_number(const unsigned int code)
if (nr >= 0x20 && nr <= 0x20 + 0x1f) {
tprints("EVIOCGBIT(");
printxval(evdev_ev, nr - 0x20, "EV_???");
if (nr == 0x20)
tprintf("0");
else
printxval(evdev_ev, nr - 0x20, "EV_???");
tprintf(", %u)", _IOC_SIZE(code));
return 1;
} else if (nr >= 0x40 && nr <= 0x40 + 0x3f) {

View File

@ -138,7 +138,7 @@ main(void)
TEST_NULL_ARG_EX(EVIOCGABS(0x3f), "EVIOCGABS(0x3f /* ABS_??? */)");
TEST_NULL_ARG_EX(EVIOCSABS(0x3f), "EVIOCSABS(0x3f /* ABS_??? */)");
TEST_NULL_ARG(EVIOCGBIT(EV_SYN, 0));
TEST_NULL_ARG(EVIOCGBIT(0, 0));
TEST_NULL_ARG(EVIOCGBIT(EV_KEY, 1));
TEST_NULL_ARG(EVIOCGBIT(EV_REL, 2));
TEST_NULL_ARG(EVIOCGBIT(EV_ABS, 3));

View File

@ -1,5 +0,0 @@
#value_indexed
SYN_REPORT 0
SYN_CONFIG 1
SYN_MT_REPORT 2
SYN_DROPPED 3