Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Alice Ryhl <aliceryhl@google.com>
To: tamird@gmail.com
Cc: Liam.Howlett@oracle.com, a.hindborg@kernel.org,
	airlied@gmail.com,  alex.gaynor@gmail.com, aliceryhl@google.com,
	arve@android.com,  axboe@kernel.dk, bhelgaas@google.com,
	bjorn3_gh@protonmail.com,  boqun.feng@gmail.com,
	brauner@kernel.org, broonie@kernel.org,  cmllamas@google.com,
	dakr@kernel.org, dri-devel@lists.freedesktop.org,
	 gary@garyguo.net, gregkh@linuxfoundation.org, jack@suse.cz,
	 joelagnelf@nvidia.com, justinstitt@google.com,
	kwilczynski@kernel.org,  leitao@debian.org, lgirdwood@gmail.com,
	linux-block@vger.kernel.org,  linux-clk@vger.kernel.org,
	linux-fsdevel@vger.kernel.org,  linux-kernel@vger.kernel.org,
	linux-pci@vger.kernel.org,  linux-pm@vger.kernel.org,
	llvm@lists.linux.dev, longman@redhat.com,
	 lorenzo.stoakes@oracle.com, lossin@kernel.org, maco@android.com,
	 mcgrof@kernel.org, mingo@redhat.com, mmaurer@google.com,
	morbo@google.com,  mturquette@baylibre.com, nathan@kernel.org,
	nick.desaulniers+lkml@gmail.com,  nm@ti.com, ojeda@kernel.org,
	peterz@infradead.org, rafael@kernel.org,  russ.weight@linux.dev,
	rust-for-linux@vger.kernel.org, sboyd@kernel.org,
	 simona@ffwll.ch, surenb@google.com, tkjos@android.com,
	tmgross@umich.edu,  urezki@gmail.com, vbabka@suse.cz,
	vireshk@kernel.org, viro@zeniv.linux.org.uk,  will@kernel.org
Subject: [PATCH v18 13/16] rust: regulator: use `CStr::as_char_ptr`
Date: Sat, 18 Oct 2025 18:03:12 +0000	[thread overview]
Message-ID: <20251018180313.3615630-1-aliceryhl@google.com> (raw)
In-Reply-To: <20251018-cstr-core-v18-0-ef3d02760804@gmail.com>

From: Tamir Duberstein <tamird@gmail.com>

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>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
 rust/kernel/regulator.rs | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/rust/kernel/regulator.rs b/rust/kernel/regulator.rs
index b55a201e5029..65a4eb096cae 100644
--- a/rust/kernel/regulator.rs
+++ b/rust/kernel/regulator.rs
@@ -84,7 +84,7 @@ pub struct Error<State: RegulatorState> {
 pub fn devm_enable(dev: &Device<Bound>, name: &CStr) -> Result {
     // SAFETY: `dev` is a valid and bound device, while `name` is a valid C
     // 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`
@@ -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 {
     // SAFETY: `dev` is a valid and bound device, while `name` is a valid C
     // 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.
@@ -268,7 +270,8 @@ pub fn get_voltage(&self) -> Result<Voltage> {
     fn get_internal(dev: &Device, name: &CStr) -> Result<Regulator<T>> {
         // SAFETY: It is safe to call `regulator_get()`, on a device pointer
         // received from the C code.
-        let inner = from_err_ptr(unsafe { bindings::regulator_get(dev.as_raw(), name.as_ptr()) })?;
+        let inner =
+            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
         // regulator if `ERR_PTR` was not returned.
-- 
2.51.0.915.g61a8936c21-goog


  parent reply	other threads:[~2025-10-18 18:03 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-18 17:45 [PATCH v18 00/16] rust: replace kernel::str::CStr w/ core::ffi::CStr Tamir Duberstein
2025-10-18 17:45 ` [PATCH v18 01/16] samples: rust: platform: remove trailing commas Tamir Duberstein
2025-10-18 17:45 ` [PATCH v18 02/16] rust_binder: remove trailing comma Tamir Duberstein
2025-10-18 17:45 ` [PATCH v18 03/16] rust_binder: use `kernel::fmt` Tamir Duberstein
2025-10-18 17:45 ` [PATCH v18 04/16] rust_binder: use `core::ffi::CStr` method names Tamir Duberstein
2025-10-18 17:45 ` [PATCH v18 05/16] rnull: use `kernel::fmt` Tamir Duberstein
2025-10-18 17:45 ` [PATCH v18 06/16] rust: alloc: " Tamir Duberstein
2025-10-18 17:45 ` [PATCH v18 07/16] rust: debugfs: " Tamir Duberstein
2025-10-18 17:45 ` [PATCH v18 08/16] rust: pci: " Tamir Duberstein
2025-10-18 17:45 ` [PATCH v18 09/16] rust: remove spurious `use core::fmt::Debug` Tamir Duberstein
2025-10-18 17:45 ` [PATCH v18 10/16] rust: opp: use `CStr::as_char_ptr` Tamir Duberstein
2025-10-22  2:26   ` Viresh Kumar
2025-10-18 17:45 ` [PATCH v18 11/16] rust: opp: fix broken rustdoc link Tamir Duberstein
2025-10-22  2:27   ` Viresh Kumar
2025-10-22  4:01     ` Viresh Kumar
2025-10-18 18:03 ` [PATCH v18 12/16] rust: configfs: use `CStr::as_char_ptr` Alice Ryhl
2025-10-20 12:44   ` Andreas Hindborg
2025-10-18 18:03 ` Alice Ryhl [this message]
2025-10-18 18:03 ` [PATCH v18 14/16] rust: clk: " Alice Ryhl
2025-10-22  2:27   ` Viresh Kumar
2025-10-18 18:03 ` [PATCH v18 15/16] rust: support formatting of foreign types Alice Ryhl
2025-10-18 18:05 ` [PATCH v18 16/16] rust: replace `CStr` with `core::ffi::CStr` Alice Ryhl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251018180313.3615630-1-aliceryhl@google.com \
    --to=aliceryhl@google.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=a.hindborg@kernel.org \
    --cc=airlied@gmail.com \
    --cc=alex.gaynor@gmail.com \
    --cc=arve@android.com \
    --cc=axboe@kernel.dk \
    --cc=bhelgaas@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=brauner@kernel.org \
    --cc=broonie@kernel.org \
    --cc=cmllamas@google.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=jack@suse.cz \
    --cc=joelagnelf@nvidia.com \
    --cc=justinstitt@google.com \
    --cc=kwilczynski@kernel.org \
    --cc=leitao@debian.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=longman@redhat.com \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=lossin@kernel.org \
    --cc=maco@android.com \
    --cc=mcgrof@kernel.org \
    --cc=mingo@redhat.com \
    --cc=mmaurer@google.com \
    --cc=morbo@google.com \
    --cc=mturquette@baylibre.com \
    --cc=nathan@kernel.org \
    --cc=nick.desaulniers+lkml@gmail.com \
    --cc=nm@ti.com \
    --cc=ojeda@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rafael@kernel.org \
    --cc=russ.weight@linux.dev \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=sboyd@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=surenb@google.com \
    --cc=tamird@gmail.com \
    --cc=tkjos@android.com \
    --cc=tmgross@umich.edu \
    --cc=urezki@gmail.com \
    --cc=vbabka@suse.cz \
    --cc=vireshk@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox