diff --git a/drivers/block/rnull/configfs.rs b/drivers/block/rnull/configfs.rs index 9b28be215093..24b02256b4cd 100644 --- a/drivers/block/rnull/configfs.rs +++ b/drivers/block/rnull/configfs.rs @@ -186,7 +186,8 @@ impl configfs::AttributeOperations<1> for DeviceConfig { } fn store(this: &DeviceConfig, page: &[u8]) -> Result { - if this.data.lock().powered { + let mut guard = this.data.lock(); + if guard.powered { return Err(EBUSY); } @@ -194,7 +195,7 @@ fn store(this: &DeviceConfig, page: &[u8]) -> Result { let value = text.parse::().map_err(|_| EINVAL)?; GenDiskBuilder::validate_block_size(value)?; - this.data.lock().block_size = value; + guard.block_size = value; Ok(()) } } @@ -216,11 +217,12 @@ impl configfs::AttributeOperations<2> for DeviceConfig { } fn store(this: &DeviceConfig, page: &[u8]) -> Result { - if this.data.lock().powered { + let mut guard = this.data.lock(); + if guard.powered { return Err(EBUSY); } - this.data.lock().rotational = kstrtobool_bytes(page)?; + guard.rotational = kstrtobool_bytes(page)?; Ok(()) } @@ -237,14 +239,15 @@ impl configfs::AttributeOperations<3> for DeviceConfig { } fn store(this: &DeviceConfig, page: &[u8]) -> Result { - if this.data.lock().powered { + let mut guard = this.data.lock(); + if guard.powered { return Err(EBUSY); } let text = core::str::from_utf8(page)?.trim(); let value = text.parse::().map_err(|_| EINVAL)?; - this.data.lock().capacity_mib = value; + guard.capacity_mib = value; Ok(()) } } @@ -260,14 +263,15 @@ impl configfs::AttributeOperations<4> for DeviceConfig { } fn store(this: &DeviceConfig, page: &[u8]) -> Result { - if this.data.lock().powered { + let mut guard = this.data.lock(); + if guard.powered { return Err(EBUSY); } let text = core::str::from_utf8(page)?.trim(); let value = text.parse::().map_err(|_| EINVAL)?; - this.data.lock().irq_mode = IRQMode::try_from(value)?; + guard.irq_mode = IRQMode::try_from(value)?; Ok(()) } }