Skip to contentSkip to conversation

rust: net: replace `kernel::c_str!` with C-Strings

PATCH Superseded Tamir Duberstein 4 participants 8 messages Dec 22, 2025 – Jan 4

Subsystems (7)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Tamir Duberstein

author reviewer
#0 lore raw

cover rust: net: replace `kernel::c_str!` with C-Strings

C-String literals were added in Rust 1.77. Replace instances of kernel::c_str! with C-String literals where possible.

---
Tamir Duberstein (2):
rust: net: replace kernel::c_str! with C-Strings
drivers: net: replace kernel::c_str! with C-Strings

 drivers/net/phy/ax88796b_rust.rs | 7 +++----
 drivers/net/phy/qt2025.rs        | 5 ++---
 rust/kernel/net/phy.rs           | 6 ++----
 3 files changed, 7 insertions(+), 11 deletions(-)

---
base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
change-id: 20251222-cstr-net-3bfd7b35acc1

Best regards,

Signature · 1 line
Tamir Duberstein <[email protected]>
author reviewer
#1 lore raw

PATCH 1/2 rust: net: replace `kernel::c_str!` with C-Strings

From: Tamir Duberstein <[email protected]>

C-String literals were added in Rust 1.77. Replace instances of kernel::c_str! with C-String literals where possible.

---
 rust/kernel/net/phy.rs | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
rust/kernel/net/phy.rs +2 -4
index bf6272d87a7b..3ca99db5cccf 100644
@@ -777,7 +777,6 @@ const fn as_int(&self) -> u32 {
 ///
 /// ```
 /// # mod module_phy_driver_sample {
-/// use kernel::c_str;
 /// use kernel::net::phy::{self, DeviceId};
 /// use kernel::prelude::*;
 ///
@@ -796,7 +795,7 @@ const fn as_int(&self) -> u32 {
 ///
 /// #[vtable]
 /// impl phy::Driver for PhySample {
-///     const NAME: &'static CStr = c_str!("PhySample");
+///     const NAME: &'static CStr = c"PhySample";
 ///     const PHY_DEVICE_ID: phy::DeviceId = phy::DeviceId::new_with_exact_mask(0x00000001);
 /// }
 /// # }
@@ -805,7 +804,6 @@ const fn as_int(&self) -> u32 {
 /// This expands to the following code:
 ///
 /// ```ignore
-/// use kernel::c_str;
 /// use kernel::net::phy::{self, DeviceId};
 /// use kernel::prelude::*;
 ///
@@ -825,7 +823,7 @@ const fn as_int(&self) -> u32 {
 ///
 /// #[vtable]
 /// impl phy::Driver for PhySample {
-///     const NAME: &'static CStr = c_str!("PhySample");
+///     const NAME: &'static CStr = c"PhySample";
 ///     const PHY_DEVICE_ID: phy::DeviceId = phy::DeviceId::new_with_exact_mask(0x00000001);
 /// }
 ///
Signature · 1 line
2.52.0
author reviewer
#2 lore raw

PATCH 2/2 drivers: net: replace `kernel::c_str!` with C-Strings

In reply to Tamir Duberstein

From: Tamir Duberstein <[email protected]>

C-String literals were added in Rust 1.77. Replace instances of kernel::c_str! with C-String literals where possible.

---
 drivers/net/phy/ax88796b_rust.rs | 7 +++----
 drivers/net/phy/qt2025.rs        | 5 ++---
 2 files changed, 5 insertions(+), 7 deletions(-)
drivers/net/phy/ax88796b_rust.rs +3 -4
index bc73ebccc2aa..2d24628a4e58 100644
@@ -5,7 +5,6 @@
 //!
 //! C version of this driver: [`drivers/net/phy/ax88796b.c`](./ax88796b.c)
 use kernel::{
-    c_str,
     net::phy::{self, reg::C22, DeviceId, Driver},
     prelude::*,
     uapi,
@@ -41,7 +40,7 @@ fn asix_soft_reset(dev: &mut phy::Device) -> Result {
 #[vtable]
 impl Driver for PhyAX88772A {
     const FLAGS: u32 = phy::flags::IS_INTERNAL;
-    const NAME: &'static CStr = c_str!("Asix Electronics AX88772A");
+    const NAME: &'static CStr = c"Asix Electronics AX88772A";
     const PHY_DEVICE_ID: DeviceId = DeviceId::new_with_exact_mask(0x003b1861);
 
     // AX88772A is not working properly with some old switches (NETGEAR EN 108TP):
@@ -105,7 +104,7 @@ fn link_change_notify(dev: &mut phy::Device) {
 #[vtable]
 impl Driver for PhyAX88772C {
     const FLAGS: u32 = phy::flags::IS_INTERNAL;
-    const NAME: &'static CStr = c_str!("Asix Electronics AX88772C");
+    const NAME: &'static CStr = c"Asix Electronics AX88772C";
     const PHY_DEVICE_ID: DeviceId = DeviceId::new_with_exact_mask(0x003b1881);
 
     fn suspend(dev: &mut phy::Device) -> Result {
@@ -125,7 +124,7 @@ fn soft_reset(dev: &mut phy::Device) -> Result {
 
 #[vtable]
 impl Driver for PhyAX88796B {
-    const NAME: &'static CStr = c_str!("Asix Electronics AX88796B");
+    const NAME: &'static CStr = c"Asix Electronics AX88796B";
     const PHY_DEVICE_ID: DeviceId = DeviceId::new_with_model_mask(0x003b1841);
 
     fn soft_reset(dev: &mut phy::Device) -> Result {
drivers/net/phy/qt2025.rs +2 -3
index aaaead6512a0..470d89a0ac00 100644
@@ -9,7 +9,6 @@
 //!
 //! The QT2025 PHY integrates an Intel 8051 micro-controller.
 
-use kernel::c_str;
 use kernel::error::code;
 use kernel::firmware::Firmware;
 use kernel::io::poll::read_poll_timeout;
@@ -38,7 +37,7 @@
 
 #[vtable]
 impl Driver for PhyQT2025 {
-    const NAME: &'static CStr = c_str!("QT2025 10Gpbs SFP+");
+    const NAME: &'static CStr = c"QT2025 10Gpbs SFP+";
     const PHY_DEVICE_ID: phy::DeviceId = phy::DeviceId::new_with_exact_mask(0x0043a400);
 
     fn probe(dev: &mut phy::Device) -> Result<()> {
@@ -71,7 +70,7 @@ fn probe(dev: &mut phy::Device) -> Result<()> {
         // The micro-controller will start running from the boot ROM.
         dev.write(C45::new(Mmd::PCS, 0xe854), 0x00c0)?;
 
-        let fw = Firmware::request(c_str!("qt2025-2.0.3.3.fw"), dev.as_ref())?;
+        let fw = Firmware::request(c"qt2025-2.0.3.3.fw", dev.as_ref())?;
         if fw.data().len() > SZ_16K + SZ_8K {
             return Err(code::EFBIG);
         }
Signature · 1 line
2.52.0
maintainer
#3 lore raw

Re: [PATCH 2/2] drivers: net: replace `kernel::c_str!` with C-Strings

Quoted 5 lines · Tamir Duberstein

From: Tamir Duberstein <[email protected]>

C-String literals were added in Rust 1.77. Replace instances of kernel::c_str! with C-String literals where possible.

Quoted 8 lines
---
 drivers/net/phy/ax88796b_rust.rs | 7 +++----
 drivers/net/phy/qt2025.rs        | 5 ++---
 2 files changed, 5 insertions(+), 7 deletions(-)

It's not clear to me if this is targeting the net-next tree. In such case:

## Form letter - net-next-closed

The net-next tree is closed for new drivers, features, code refactoring and optimizations due to the merge window and the winter break. We are currently accepting bug fixes only.

Please repost when net-next reopens after Jan 2nd.

RFC patches sent for review only are obviously welcome at any time.

author reviewer
#4 lore raw

Re: [PATCH 2/2] drivers: net: replace `kernel::c_str!` with C-Strings

Quoted 20 lines · Paolo Abeni
Quoted 5 lines · Tamir Duberstein

From: Tamir Duberstein <[email protected]>

C-String literals were added in Rust 1.77. Replace instances of kernel::c_str! with C-String literals where possible.

Quoted 8 lines
---
 drivers/net/phy/ax88796b_rust.rs | 7 +++----
 drivers/net/phy/qt2025.rs        | 5 ++---
 2 files changed, 5 insertions(+), 7 deletions(-)

It's not clear to me if this is targeting the net-next tree. In such case:

## Form letter - net-next-closed

Quoted 7 lines

The net-next tree is closed for new drivers, features, code refactoring and optimizations due to the merge window and the winter break. We are currently accepting bug fixes only.

Please repost when net-next reopens after Jan 2nd.

RFC patches sent for review only are obviously welcome at any time.

Yes, this is targeting net-next (unless you folks are OK with it going through rust-next, which is also OK with me). Thank you for including the date to resend.

author reviewer
#5 lore raw

Re: [PATCH 2/2] drivers: net: replace `kernel::c_str!` with C-Strings

Quoted 26 lines · Tamir Duberstein
Quoted 24 lines · Paolo Abeni
Quoted 5 lines · Tamir Duberstein

From: Tamir Duberstein <[email protected]>

C-String literals were added in Rust 1.77. Replace instances of kernel::c_str! with C-String literals where possible.

Quoted 8 lines
---
 drivers/net/phy/ax88796b_rust.rs | 7 +++----
 drivers/net/phy/qt2025.rs        | 5 ++---
 2 files changed, 5 insertions(+), 7 deletions(-)

It's not clear to me if this is targeting the net-next tree. In such case:

## Form letter - net-next-closed

The net-next tree is closed for new drivers, features, code refactoring and optimizations due to the merge window and the winter break. We are currently accepting bug fixes only.

Quoted 7 lines
Quoted 3 lines

Please repost when net-next reopens after Jan 2nd.

RFC patches sent for review only are obviously welcome at any time.

Yes, this is targeting net-next (unless you folks are OK with it going through rust-next, which is also OK with me). Thank you for including the date to resend.

v2 (same as v1 + tags):
https://lore.kernel.org/all/[email protected]/.

Cheers.

Tamir

reviewer Reviewed-by on the v1 series
#6 lore raw
In reply to Tamir Duberstein
Quoted 17 lines · Tamir Duberstein

C-String literals were added in Rust 1.77. Replace instances of kernel::c_str! with C-String literals where possible.

---
Tamir Duberstein (2):
rust: net: replace kernel::c_str! with C-Strings
drivers: net: replace kernel::c_str! with C-Strings

drivers/net/phy/ax88796b_rust.rs | 7 +++----
drivers/net/phy/qt2025.rs        | 5 ++---
rust/kernel/net/phy.rs           | 6 ++----
3 files changed, 7 insertions(+), 11 deletions(-)
Quoted 9 lines

---
base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
change-id: 20251222-cstr-net-3bfd7b35acc1

Best regards,

Signature · 1 line
Tamir Duberstein <[email protected]>
maintainer Reviewed-by on the v1 series
#7 lore raw
In reply to Tamir Duberstein
Quoted 9 lines · On Mon, 22 Dec 2025 13:32:26 +0100 Tamir Duberstein <[email protected]> wrote:

C-String literals were added in Rust 1.77. Replace instances of kernel::c_str! with C-String literals where possible.

---
Tamir Duberstein (2):
rust: net: replace kernel::c_str! with C-Strings
drivers: net: replace kernel::c_str! with C-Strings

Quoted 7 lines
 drivers/net/phy/ax88796b_rust.rs | 7 +++----
 drivers/net/phy/qt2025.rs        | 5 ++---
 rust/kernel/net/phy.rs           | 6 ++----
 3 files changed, 7 insertions(+), 11 deletions(-)

---
base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
change-id: 20251222-cstr-net-3bfd7b35acc1