Skip to content

Commit

Permalink
Merge pull request #161 from carlosmn/cmn/ioctl-read-and-write
Browse files Browse the repository at this point in the history
linux-native: provide better signatures for the ioctl wrappers
  • Loading branch information
ruabmbua authored Nov 18, 2024
2 parents 858b66f + cc1b2b3 commit 15b84ec
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
9 changes: 1 addition & 8 deletions src/linux_native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,14 +524,7 @@ impl HidDeviceBackendBase for HidDevice {
return Err(HidError::InvalidZeroSizeData);
}

// Have to crate owned buffer, because its not safe to cast shared
// reference to mutable reference, even if the underlying function never
// tries to mutate it.
let mut d = data.to_vec();

// The ioctl is marked as read-write so we need to mess with the
// mutability even though nothing should get written
let res = match unsafe { hidraw_ioc_set_feature(self.fd.as_raw_fd(), &mut d) } {
let res = match unsafe { hidraw_ioc_set_feature(self.fd.as_raw_fd(), data) } {
Ok(n) => n as usize,
Err(e) => {
return Err(HidError::HidApiError {
Expand Down
6 changes: 3 additions & 3 deletions src/linux_native/ioctl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The IOCTL calls we need for the native linux backend
use nix::{ioctl_read, ioctl_readwrite_buf};
use nix::{ioctl_read, ioctl_read_buf, ioctl_write_buf};

// From linux/hidraw.h
const HIDRAW_IOC_MAGIC: u8 = b'H';
Expand All @@ -15,13 +15,13 @@ ioctl_read!(
libc::c_int
);

ioctl_readwrite_buf!(
ioctl_write_buf!(
hidraw_ioc_set_feature,
HIDRAW_IOC_MAGIC,
HIDRAW_SET_FEATURE,
u8
);
ioctl_readwrite_buf!(
ioctl_read_buf!(
hidraw_ioc_get_feature,
HIDRAW_IOC_MAGIC,
HIDRAW_GET_FEATURE,
Expand Down

0 comments on commit 15b84ec

Please sign in to comment.