[PATCH] rust: simplify Result<()> uses

From: Manas via B4 Relay
Date: Sun Nov 17 2024 - 10:12:06 EST


From: Manas <manas18244@xxxxxxxxxxx>

This patch replaces `Result<()>` with `Result`.

Suggested-by: Miguel Ojeda <ojeda@xxxxxxxxxx>
Link: https://github.com/Rust-for-Linux/linux/issues/1128
Signed-off-by: Manas <manas18244@xxxxxxxxxxx>
---
drivers/net/phy/qt2025.rs | 2 +-
rust/kernel/block/mq/gen_disk.rs | 2 +-
rust/kernel/uaccess.rs | 2 +-
rust/macros/lib.rs | 6 +++---
4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/phy/qt2025.rs b/drivers/net/phy/qt2025.rs
index 1ab065798175b4f54c5f2fd6c871ba2942c48bf1..25c12a02baa255d3d5952e729a890b3ccfe78606 100644
--- a/drivers/net/phy/qt2025.rs
+++ b/drivers/net/phy/qt2025.rs
@@ -39,7 +39,7 @@ impl Driver for PhyQT2025 {
const NAME: &'static CStr = c_str!("QT2025 10Gpbs SFP+");
const PHY_DEVICE_ID: phy::DeviceId = phy::DeviceId::new_with_exact_mask(0x0043a400);

- fn probe(dev: &mut phy::Device) -> Result<()> {
+ fn probe(dev: &mut phy::Device) -> Result {
// Check the hardware revision code.
// Only 0x3b works with this driver and firmware.
let hw_rev = dev.read(C45::new(Mmd::PMAPMD, 0xd001))?;
diff --git a/rust/kernel/block/mq/gen_disk.rs b/rust/kernel/block/mq/gen_disk.rs
index 708125dce96a934f32caab44d5e6cff14c4321a9..798c4ae0bdedd58221b5851a630c0e1052e0face 100644
--- a/rust/kernel/block/mq/gen_disk.rs
+++ b/rust/kernel/block/mq/gen_disk.rs
@@ -45,7 +45,7 @@ pub fn rotational(mut self, rotational: bool) -> Self {

/// Validate block size by verifying that it is between 512 and `PAGE_SIZE`,
/// and that it is a power of two.
- fn validate_block_size(size: u32) -> Result<()> {
+ fn validate_block_size(size: u32) -> Result {
if !(512..=bindings::PAGE_SIZE as u32).contains(&size) || !size.is_power_of_two() {
Err(error::code::EINVAL)
} else {
diff --git a/rust/kernel/uaccess.rs b/rust/kernel/uaccess.rs
index 05b0b8d13b10da731af62be03e1c2c13ced3f706..7c21304344ccd943816e38119a5be2ccf8d8e154 100644
--- a/rust/kernel/uaccess.rs
+++ b/rust/kernel/uaccess.rs
@@ -49,7 +49,7 @@
/// use kernel::error::Result;
/// use kernel::uaccess::{UserPtr, UserSlice};
///
-/// fn bytes_add_one(uptr: UserPtr, len: usize) -> Result<()> {
+/// fn bytes_add_one(uptr: UserPtr, len: usize) -> Result {
/// let (read, mut write) = UserSlice::new(uptr, len).reader_writer();
///
/// let mut buf = KVec::new();
diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs
index 4ab94e44adfe3206faad159e81417ea41a35815b..463920353ca9c408f5d69e2626c13a173bae98d7 100644
--- a/rust/macros/lib.rs
+++ b/rust/macros/lib.rs
@@ -144,11 +144,11 @@ pub fn module(ts: TokenStream) -> TokenStream {
/// // Declares a `#[vtable]` trait
/// #[vtable]
/// pub trait Operations: Send + Sync + Sized {
-/// fn foo(&self) -> Result<()> {
+/// fn foo(&self) -> Result {
/// kernel::build_error(VTABLE_DEFAULT_ERROR)
/// }
///
-/// fn bar(&self) -> Result<()> {
+/// fn bar(&self) -> Result {
/// kernel::build_error(VTABLE_DEFAULT_ERROR)
/// }
/// }
@@ -158,7 +158,7 @@ pub fn module(ts: TokenStream) -> TokenStream {
/// // Implements the `#[vtable]` trait
/// #[vtable]
/// impl Operations for Foo {
-/// fn foo(&self) -> Result<()> {
+/// fn foo(&self) -> Result {
/// # Err(EINVAL)
/// // ...
/// }

---
base-commit: b2603f8ac8217bc59f5c7f248ac248423b9b99cb
change-id: 20241117-simplify-result-cad98af090c9

Best regards,
--
Manas <manas18244@xxxxxxxxxxx>