input-compat.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * 32bit compatibility wrappers for the input subsystem.
  3. *
  4. * Very heavily based on evdev.c - Copyright (c) 1999-2002 Vojtech Pavlik
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. */
  10. #include <linux/export.h>
  11. #include <asm/uaccess.h>
  12. #include "input-compat.h"
  13. #ifdef CONFIG_COMPAT
  14. int input_event_from_user(const char __user *buffer,
  15. struct input_event *event)
  16. {
  17. if (INPUT_COMPAT_TEST && !COMPAT_USE_64BIT_TIME) {
  18. struct input_event_compat compat_event;
  19. if (copy_from_user(&compat_event, buffer,
  20. sizeof(struct input_event_compat)))
  21. return -EFAULT;
  22. event->time.tv_sec = compat_event.time.tv_sec;
  23. event->time.tv_usec = compat_event.time.tv_usec;
  24. event->type = compat_event.type;
  25. event->code = compat_event.code;
  26. event->value = compat_event.value;
  27. } else {
  28. if (copy_from_user(event, buffer, sizeof(struct input_event)))
  29. return -EFAULT;
  30. }
  31. return 0;
  32. }
  33. int input_event_to_user(char __user *buffer,
  34. const struct input_event *event)
  35. {
  36. if (INPUT_COMPAT_TEST && !COMPAT_USE_64BIT_TIME) {
  37. struct input_event_compat compat_event;
  38. compat_event.time.tv_sec = event->time.tv_sec;
  39. compat_event.time.tv_usec = event->time.tv_usec;
  40. compat_event.type = event->type;
  41. compat_event.code = event->code;
  42. compat_event.value = event->value;
  43. if (copy_to_user(buffer, &compat_event,
  44. sizeof(struct input_event_compat)))
  45. return -EFAULT;
  46. } else {
  47. if (copy_to_user(buffer, event, sizeof(struct input_event)))
  48. return -EFAULT;
  49. }
  50. return 0;
  51. }
  52. int input_ff_effect_from_user(const char __user *buffer, size_t size,
  53. struct ff_effect *effect)
  54. {
  55. if (INPUT_COMPAT_TEST) {
  56. struct ff_effect_compat *compat_effect;
  57. if (size != sizeof(struct ff_effect_compat))
  58. return -EINVAL;
  59. /*
  60. * It so happens that the pointer which needs to be changed
  61. * is the last field in the structure, so we can retrieve the
  62. * whole thing and replace just the pointer.
  63. */
  64. compat_effect = (struct ff_effect_compat *)effect;
  65. if (copy_from_user(compat_effect, buffer,
  66. sizeof(struct ff_effect_compat)))
  67. return -EFAULT;
  68. if (compat_effect->type == FF_PERIODIC &&
  69. compat_effect->u.periodic.waveform == FF_CUSTOM)
  70. effect->u.periodic.custom_data =
  71. compat_ptr(compat_effect->u.periodic.custom_data);
  72. } else {
  73. if (size != sizeof(struct ff_effect))
  74. return -EINVAL;
  75. if (copy_from_user(effect, buffer, sizeof(struct ff_effect)))
  76. return -EFAULT;
  77. }
  78. return 0;
  79. }
  80. #else
  81. int input_event_from_user(const char __user *buffer,
  82. struct input_event *event)
  83. {
  84. if (copy_from_user(event, buffer, sizeof(struct input_event)))
  85. return -EFAULT;
  86. return 0;
  87. }
  88. int input_event_to_user(char __user *buffer,
  89. const struct input_event *event)
  90. {
  91. if (copy_to_user(buffer, event, sizeof(struct input_event)))
  92. return -EFAULT;
  93. return 0;
  94. }
  95. int input_ff_effect_from_user(const char __user *buffer, size_t size,
  96. struct ff_effect *effect)
  97. {
  98. if (size != sizeof(struct ff_effect))
  99. return -EINVAL;
  100. if (copy_from_user(effect, buffer, sizeof(struct ff_effect)))
  101. return -EFAULT;
  102. return 0;
  103. }
  104. #endif /* CONFIG_COMPAT */
  105. EXPORT_SYMBOL_GPL(input_event_from_user);
  106. EXPORT_SYMBOL_GPL(input_event_to_user);
  107. EXPORT_SYMBOL_GPL(input_ff_effect_from_user);