Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Tamir Duberstein and committed by
Miguel Ojeda
9ce084e5 3b46f653

+8 -5
+8 -5
rust/kernel/regulator.rs
··· 84 84 pub fn devm_enable(dev: &Device<Bound>, name: &CStr) -> Result { 85 85 // SAFETY: `dev` is a valid and bound device, while `name` is a valid C 86 86 // 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()) }) 88 88 } 89 89 90 90 /// Same as [`devm_enable`], but calls `devm_regulator_get_enable_optional` ··· 102 102 pub fn devm_enable_optional(dev: &Device<Bound>, name: &CStr) -> Result { 103 103 // SAFETY: `dev` is a valid and bound device, while `name` is a valid C 104 104 // 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 + }) 106 108 } 107 109 108 110 /// A `struct regulator` abstraction. ··· 268 266 } 269 267 270 268 fn get_internal(dev: &Device, name: &CStr) -> Result<Regulator<T>> { 271 - // SAFETY: It is safe to call `regulator_get()`, on a device pointer 272 - // received from the C code. 273 - let inner = from_err_ptr(unsafe { bindings::regulator_get(dev.as_raw(), name.as_ptr()) })?; 269 + let inner = 270 + // SAFETY: It is safe to call `regulator_get()`, on a device pointer 271 + // received from the C code. 272 + from_err_ptr(unsafe { bindings::regulator_get(dev.as_raw(), name.as_char_ptr()) })?; 274 273 275 274 // SAFETY: We can safely trust `inner` to be a pointer to a valid 276 275 // regulator if `ERR_PTR` was not returned.