1 // SPDX-License-Identifier: GPL-2.0-only
3 * 32bit compatibility wrappers for the input subsystem.
5 * Very heavily based on evdev.c - Copyright (c) 1999-2002 Vojtech Pavlik
8 #include <linux/export.h>
9 #include <linux/uaccess.h>
10 #include "input-compat.h"
14 int input_event_from_user(const char __user *buffer,
15 struct input_event *event)
17 if (in_compat_syscall() && !COMPAT_USE_64BIT_TIME) {
18 struct input_event_compat compat_event;
20 if (copy_from_user(&compat_event, buffer,
21 sizeof(struct input_event_compat)))
24 event->input_event_sec = compat_event.sec;
25 event->input_event_usec = compat_event.usec;
26 event->type = compat_event.type;
27 event->code = compat_event.code;
28 event->value = compat_event.value;
31 if (copy_from_user(event, buffer, sizeof(struct input_event)))
38 int input_event_to_user(char __user *buffer,
39 const struct input_event *event)
41 if (in_compat_syscall() && !COMPAT_USE_64BIT_TIME) {
42 struct input_event_compat compat_event;
44 compat_event.sec = event->input_event_sec;
45 compat_event.usec = event->input_event_usec;
46 compat_event.type = event->type;
47 compat_event.code = event->code;
48 compat_event.value = event->value;
50 if (copy_to_user(buffer, &compat_event,
51 sizeof(struct input_event_compat)))
55 if (copy_to_user(buffer, event, sizeof(struct input_event)))
62 int input_ff_effect_from_user(const char __user *buffer, size_t size,
63 struct ff_effect *effect)
65 if (in_compat_syscall()) {
66 struct ff_effect_compat *compat_effect;
68 if (size != sizeof(struct ff_effect_compat))
72 * It so happens that the pointer which needs to be changed
73 * is the last field in the structure, so we can retrieve the
74 * whole thing and replace just the pointer.
76 compat_effect = (struct ff_effect_compat *)effect;
78 if (copy_from_user(compat_effect, buffer,
79 sizeof(struct ff_effect_compat)))
82 if (compat_effect->type == FF_PERIODIC &&
83 compat_effect->u.periodic.waveform == FF_CUSTOM)
84 effect->u.periodic.custom_data =
85 compat_ptr(compat_effect->u.periodic.custom_data);
87 if (size != sizeof(struct ff_effect))
90 if (copy_from_user(effect, buffer, sizeof(struct ff_effect)))
99 int input_event_from_user(const char __user *buffer,
100 struct input_event *event)
102 if (copy_from_user(event, buffer, sizeof(struct input_event)))
108 int input_event_to_user(char __user *buffer,
109 const struct input_event *event)
111 if (copy_to_user(buffer, event, sizeof(struct input_event)))
117 int input_ff_effect_from_user(const char __user *buffer, size_t size,
118 struct ff_effect *effect)
120 if (size != sizeof(struct ff_effect))
123 if (copy_from_user(effect, buffer, sizeof(struct ff_effect)))
129 #endif /* CONFIG_COMPAT */
131 EXPORT_SYMBOL_GPL(input_event_from_user);
132 EXPORT_SYMBOL_GPL(input_event_to_user);
133 EXPORT_SYMBOL_GPL(input_ff_effect_from_user);