diff options
Diffstat (limited to 'rust/kernel/i2c.rs')
| -rw-r--r-- | rust/kernel/i2c.rs | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/rust/kernel/i2c.rs b/rust/kernel/i2c.rs index 95b056cc1a71..491e6cc25cf4 100644 --- a/rust/kernel/i2c.rs +++ b/rust/kernel/i2c.rs @@ -44,11 +44,8 @@ impl DeviceId { /// Create a new device id from an I2C 'id' string. #[inline(always)] pub const fn new(id: &'static CStr) -> Self { - build_assert!( - id.len_with_nul() <= Self::I2C_NAME_SIZE, - "ID exceeds 20 bytes" - ); - let src = id.as_bytes_with_nul(); + let src = id.to_bytes_with_nul(); + build_assert!(src.len() <= Self::I2C_NAME_SIZE, "ID exceeds 20 bytes"); let mut i2c: bindings::i2c_device_id = pin_init::zeroed(); let mut i = 0; while i < src.len() { @@ -434,11 +431,8 @@ impl I2cBoardInfo { /// Create a new [`I2cBoardInfo`] for a kernel driver. #[inline(always)] pub const fn new(type_: &'static CStr, addr: u16) -> Self { - build_assert!( - type_.len_with_nul() <= Self::I2C_TYPE_SIZE, - "Type exceeds 20 bytes" - ); - let src = type_.as_bytes_with_nul(); + let src = type_.to_bytes_with_nul(); + build_assert!(src.len() <= Self::I2C_TYPE_SIZE, "Type exceeds 20 bytes"); let mut i2c_board_info: bindings::i2c_board_info = pin_init::zeroed(); let mut i: usize = 0; while i < src.len() { |
