mirror of https://github.com/torvalds/linux.git
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 <tamird@gmail.com> Acked-by: Mark Brown <broonie@kernel.org> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com> Link: https://patch.msgid.link/20251018-cstr-core-v18-13-9378a54385f8@gmail.com [ Move safety comment below to support older Clippy. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
This commit is contained in:
parent
3b46f65355
commit
9ce084e579
|
|
@ -84,7 +84,7 @@ pub struct Error<State: RegulatorState> {
|
||||||
pub fn devm_enable(dev: &Device<Bound>, name: &CStr) -> Result {
|
pub fn devm_enable(dev: &Device<Bound>, name: &CStr) -> Result {
|
||||||
// SAFETY: `dev` is a valid and bound device, while `name` is a valid C
|
// SAFETY: `dev` is a valid and bound device, while `name` is a valid C
|
||||||
// string.
|
// string.
|
||||||
to_result(unsafe { bindings::devm_regulator_get_enable(dev.as_raw(), name.as_ptr()) })
|
to_result(unsafe { bindings::devm_regulator_get_enable(dev.as_raw(), name.as_char_ptr()) })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Same as [`devm_enable`], but calls `devm_regulator_get_enable_optional`
|
/// 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 {
|
||||||
pub fn devm_enable_optional(dev: &Device<Bound>, name: &CStr) -> Result {
|
pub fn devm_enable_optional(dev: &Device<Bound>, name: &CStr) -> Result {
|
||||||
// SAFETY: `dev` is a valid and bound device, while `name` is a valid C
|
// SAFETY: `dev` is a valid and bound device, while `name` is a valid C
|
||||||
// string.
|
// string.
|
||||||
to_result(unsafe { bindings::devm_regulator_get_enable_optional(dev.as_raw(), name.as_ptr()) })
|
to_result(unsafe {
|
||||||
|
bindings::devm_regulator_get_enable_optional(dev.as_raw(), name.as_char_ptr())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A `struct regulator` abstraction.
|
/// A `struct regulator` abstraction.
|
||||||
|
|
@ -266,9 +268,10 @@ pub fn get_voltage(&self) -> Result<Voltage> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_internal(dev: &Device, name: &CStr) -> Result<Regulator<T>> {
|
fn get_internal(dev: &Device, name: &CStr) -> Result<Regulator<T>> {
|
||||||
|
let inner =
|
||||||
// SAFETY: It is safe to call `regulator_get()`, on a device pointer
|
// SAFETY: It is safe to call `regulator_get()`, on a device pointer
|
||||||
// received from the C code.
|
// received from the C code.
|
||||||
let inner = from_err_ptr(unsafe { bindings::regulator_get(dev.as_raw(), name.as_ptr()) })?;
|
from_err_ptr(unsafe { bindings::regulator_get(dev.as_raw(), name.as_char_ptr()) })?;
|
||||||
|
|
||||||
// SAFETY: We can safely trust `inner` to be a pointer to a valid
|
// SAFETY: We can safely trust `inner` to be a pointer to a valid
|
||||||
// regulator if `ERR_PTR` was not returned.
|
// regulator if `ERR_PTR` was not returned.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue