default to configuration 0 if the bConfigurationValue file is empty (#181)
Co-authored-by: Kevin Mehall <km@kevinmehall.net>
This commit is contained in:
parent
b8e8938975
commit
94dffc4311
2 changed files with 24 additions and 7 deletions
|
|
@ -29,7 +29,10 @@ use super::{
|
|||
};
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
use super::SysfsPath;
|
||||
use super::{
|
||||
enumeration::{SysfsError, SysfsErrorKind},
|
||||
SysfsPath,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
bitset::EndpointBitSet,
|
||||
|
|
@ -140,10 +143,20 @@ impl LinuxDevice {
|
|||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
let active_config: u8 = if let Some(sysfs) = sysfs.as_ref() {
|
||||
sysfs.read_attr("bConfigurationValue").map_err(|e| {
|
||||
warn!("failed to read sysfs bConfigurationValue: {e}");
|
||||
Error::new(ErrorKind::Other, "failed to read sysfs bConfigurationValue")
|
||||
})?
|
||||
match sysfs.read_attr("bConfigurationValue") {
|
||||
Ok(v) => v,
|
||||
// Linux returns an empty string when the device is unconfigured.
|
||||
// We'll assume all parse errors are the empty string.
|
||||
Err(SysfsError(_, SysfsErrorKind::Parse(_))) => 0,
|
||||
|
||||
Err(e) => {
|
||||
warn!("failed to read sysfs bConfigurationValue: {e}");
|
||||
return Err(Error::new(
|
||||
ErrorKind::Other,
|
||||
"failed to read sysfs bConfigurationValue",
|
||||
));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
guess_active_configuration(&fd, &descriptors)
|
||||
};
|
||||
|
|
@ -325,6 +338,10 @@ impl LinuxDevice {
|
|||
self.active_config.store(v, Ordering::SeqCst);
|
||||
return v;
|
||||
}
|
||||
Err(SysfsError(_, SysfsErrorKind::Parse(_))) => {
|
||||
self.active_config.store(0, Ordering::SeqCst);
|
||||
return 0;
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Failed to read sysfs bConfigurationValue: {e}, using cached value");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,10 +15,10 @@ use crate::{BusInfo, DeviceInfo, Error, Speed, UsbControllerType};
|
|||
pub struct SysfsPath(pub(crate) PathBuf);
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SysfsError(PathBuf, SysfsErrorKind);
|
||||
pub struct SysfsError(pub(crate) PathBuf, pub(crate) SysfsErrorKind);
|
||||
|
||||
#[derive(Debug)]
|
||||
enum SysfsErrorKind {
|
||||
pub(crate) enum SysfsErrorKind {
|
||||
Io(io::Error),
|
||||
Parse(String),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue