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"))]
|
#[cfg(not(target_os = "android"))]
|
||||||
use super::SysfsPath;
|
use super::{
|
||||||
|
enumeration::{SysfsError, SysfsErrorKind},
|
||||||
|
SysfsPath,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
bitset::EndpointBitSet,
|
bitset::EndpointBitSet,
|
||||||
|
|
@ -140,10 +143,20 @@ impl LinuxDevice {
|
||||||
|
|
||||||
#[cfg(not(target_os = "android"))]
|
#[cfg(not(target_os = "android"))]
|
||||||
let active_config: u8 = if let Some(sysfs) = sysfs.as_ref() {
|
let active_config: u8 = if let Some(sysfs) = sysfs.as_ref() {
|
||||||
sysfs.read_attr("bConfigurationValue").map_err(|e| {
|
match sysfs.read_attr("bConfigurationValue") {
|
||||||
warn!("failed to read sysfs bConfigurationValue: {e}");
|
Ok(v) => v,
|
||||||
Error::new(ErrorKind::Other, "failed to read sysfs bConfigurationValue")
|
// 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 {
|
} else {
|
||||||
guess_active_configuration(&fd, &descriptors)
|
guess_active_configuration(&fd, &descriptors)
|
||||||
};
|
};
|
||||||
|
|
@ -325,6 +338,10 @@ impl LinuxDevice {
|
||||||
self.active_config.store(v, Ordering::SeqCst);
|
self.active_config.store(v, Ordering::SeqCst);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
Err(SysfsError(_, SysfsErrorKind::Parse(_))) => {
|
||||||
|
self.active_config.store(0, Ordering::SeqCst);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Failed to read sysfs bConfigurationValue: {e}, using cached value");
|
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);
|
pub struct SysfsPath(pub(crate) PathBuf);
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SysfsError(PathBuf, SysfsErrorKind);
|
pub struct SysfsError(pub(crate) PathBuf, pub(crate) SysfsErrorKind);
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum SysfsErrorKind {
|
pub(crate) enum SysfsErrorKind {
|
||||||
Io(io::Error),
|
Io(io::Error),
|
||||||
Parse(String),
|
Parse(String),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue