@@ -29,7 +29,10 @@ use super::{
2929} ;
3030
3131#[ cfg( not( target_os = "android" ) ) ]
32- use super :: SysfsPath ;
32+ use super :: {
33+ enumeration:: { SysfsError , SysfsErrorKind } ,
34+ SysfsPath ,
35+ } ;
3336
3437use crate :: {
3538 bitset:: EndpointBitSet ,
@@ -140,10 +143,20 @@ impl LinuxDevice {
140143
141144 #[ cfg( not( target_os = "android" ) ) ]
142145 let active_config: u8 = if let Some ( sysfs) = sysfs. as_ref ( ) {
143- sysfs. read_attr ( "bConfigurationValue" ) . map_err ( |e| {
144- warn ! ( "failed to read sysfs bConfigurationValue: {e}" ) ;
145- Error :: new ( ErrorKind :: Other , "failed to read sysfs bConfigurationValue" )
146- } ) ?
146+ match sysfs. read_attr ( "bConfigurationValue" ) {
147+ Ok ( v) => v,
148+ // Linux returns an empty string when the device is unconfigured.
149+ // We'll assume all parse errors are the empty string.
150+ Err ( SysfsError ( _, SysfsErrorKind :: Parse ( _) ) ) => 0 ,
151+
152+ Err ( e) => {
153+ warn ! ( "failed to read sysfs bConfigurationValue: {e}" ) ;
154+ return Err ( Error :: new (
155+ ErrorKind :: Other ,
156+ "failed to read sysfs bConfigurationValue" ,
157+ ) ) ;
158+ }
159+ }
147160 } else {
148161 guess_active_configuration ( & fd, & descriptors)
149162 } ;
@@ -325,6 +338,10 @@ impl LinuxDevice {
325338 self . active_config . store ( v, Ordering :: SeqCst ) ;
326339 return v;
327340 }
341+ Err ( SysfsError ( _, SysfsErrorKind :: Parse ( _) ) ) => {
342+ self . active_config . store ( 0 , Ordering :: SeqCst ) ;
343+ return 0 ;
344+ }
328345 Err ( e) => {
329346 error ! ( "Failed to read sysfs bConfigurationValue: {e}, using cached value" ) ;
330347 }
0 commit comments