Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux-native: provide better signatures for the ioctl wrappers #161

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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