Skip to content

Commit 9ce084e

Browse files
tamirdojeda
authored andcommitted
rust: regulator: use CStr::as_char_ptr
Replace the use of `as_ptr` which works through `<CStr as Deref<Target=&[u8]>::deref()` in preparation for replacing `kernel::str::CStr` with `core::ffi::CStr` as the latter does not implement `Deref<Target=&[u8]>`. Signed-off-by: Tamir Duberstein <[email protected]> Acked-by: Mark Brown <[email protected]> Reviewed-by: Daniel Almeida <[email protected]> Link: https://patch.msgid.link/[email protected] [ Move safety comment below to support older Clippy. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 3b46f65 commit 9ce084e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

rust/kernel/regulator.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub struct Error<State: RegulatorState> {
8484
pub fn devm_enable(dev: &Device<Bound>, name: &CStr) -> Result {
8585
// SAFETY: `dev` is a valid and bound device, while `name` is a valid C
8686
// string.
87-
to_result(unsafe { bindings::devm_regulator_get_enable(dev.as_raw(), name.as_ptr()) })
87+
to_result(unsafe { bindings::devm_regulator_get_enable(dev.as_raw(), name.as_char_ptr()) })
8888
}
8989

9090
/// Same as [`devm_enable`], but calls `devm_regulator_get_enable_optional`
@@ -102,7 +102,9 @@ pub fn devm_enable(dev: &Device<Bound>, name: &CStr) -> Result {
102102
pub fn devm_enable_optional(dev: &Device<Bound>, name: &CStr) -> Result {
103103
// SAFETY: `dev` is a valid and bound device, while `name` is a valid C
104104
// string.
105-
to_result(unsafe { bindings::devm_regulator_get_enable_optional(dev.as_raw(), name.as_ptr()) })
105+
to_result(unsafe {
106+
bindings::devm_regulator_get_enable_optional(dev.as_raw(), name.as_char_ptr())
107+
})
106108
}
107109

108110
/// A `struct regulator` abstraction.
@@ -266,9 +268,10 @@ impl<T: RegulatorState> Regulator<T> {
266268
}
267269

268270
fn get_internal(dev: &Device, name: &CStr) -> Result<Regulator<T>> {
269-
// SAFETY: It is safe to call `regulator_get()`, on a device pointer
270-
// received from the C code.
271-
let inner = from_err_ptr(unsafe { bindings::regulator_get(dev.as_raw(), name.as_ptr()) })?;
271+
let inner =
272+
// SAFETY: It is safe to call `regulator_get()`, on a device pointer
273+
// received from the C code.
274+
from_err_ptr(unsafe { bindings::regulator_get(dev.as_raw(), name.as_char_ptr()) })?;
272275

273276
// SAFETY: We can safely trust `inner` to be a pointer to a valid
274277
// regulator if `ERR_PTR` was not returned.

0 commit comments

Comments
 (0)