devices: input: fix ioctl handling

- EVIOCGABS returns zero on success
  * https://github.com/torvalds/linux/blob/master/drivers/input/evdev.c#L1204
- Rename ret to map

BUG=b:213929977
TEST=run Cuttlefish

Change-Id: I25a07e5449163a340cc220a7d885966d71b83edc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3475441
Reviewed-by: Jorge Moreira Broche <jemoreira@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Michael Hoyle <mikehoyle@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
This commit is contained in:
Gurchetan Singh 2022-02-18 16:01:35 -08:00 committed by Commit Bot
parent 18c6548614
commit f49acedb83

View file

@ -234,12 +234,12 @@ pub fn supported_events<T: AsRawDescriptor>(
/// Gets the absolute axes of an event device (see EVIOCGABS ioctl for details). /// Gets the absolute axes of an event device (see EVIOCGABS ioctl for details).
pub fn abs_info<T: AsRawDescriptor>(descriptor: &T) -> BTreeMap<u16, virtio_input_absinfo> { pub fn abs_info<T: AsRawDescriptor>(descriptor: &T) -> BTreeMap<u16, virtio_input_absinfo> {
let mut ret: BTreeMap<u16, virtio_input_absinfo> = BTreeMap::new(); let mut map: BTreeMap<u16, virtio_input_absinfo> = BTreeMap::new();
for abs in 0..ABS_MAX { for abs in 0..ABS_MAX {
// Create a new one, zero-ed out every time to avoid carry-overs. // Create a new one, zero-ed out every time to avoid carry-overs.
let mut abs_info = evdev_abs_info::new(); let mut abs_info = evdev_abs_info::new();
let len = unsafe { let ret = unsafe {
// Safe because the kernel won't write more than size of evdev_buffer and we check the // Safe because the kernel won't write more than size of evdev_buffer and we check the
// return value // return value
ioctl_with_mut_ref( ioctl_with_mut_ref(
@ -248,11 +248,11 @@ pub fn abs_info<T: AsRawDescriptor>(descriptor: &T) -> BTreeMap<u16, virtio_inpu
&mut abs_info, &mut abs_info,
) )
}; };
if len > 0 { if ret == 0 {
ret.insert(abs, virtio_input_absinfo::from(abs_info)); map.insert(abs, virtio_input_absinfo::from(abs_info));
} }
} }
ret map
} }
/// Grabs an event device (see EVIOCGGRAB ioctl for details). After this function succeeds the given /// Grabs an event device (see EVIOCGGRAB ioctl for details). After this function succeeds the given