| From stable+bounces-121473-greg=kroah.com@vger.kernel.org Fri Mar 7 23:51:29 2025 |
| From: Miguel Ojeda <ojeda@kernel.org> |
| Date: Fri, 7 Mar 2025 23:49:25 +0100 |
| Subject: rust: error: make conversion functions public |
| To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Sasha Levin <sashal@kernel.org>, stable@vger.kernel.org |
| Cc: Danilo Krummrich <dakr@kernel.org>, Alice Ryhl <aliceryhl@google.com>, Alyssa Ross <hi@alyssa.is>, NoisyCoil <noisycoil@disroot.org>, patches@lists.linux.dev, Miguel Ojeda <ojeda@kernel.org> |
| Message-ID: <20250307225008.779961-19-ojeda@kernel.org> |
| |
| From: Filipe Xavier <felipe_life@live.com> |
| |
| commit 5ed147473458f8c20f908a03227d8f5bb3cb8f7d upstream. |
| |
| Change visibility to public of functions in error.rs: |
| from_err_ptr, from_errno, from_result and to_ptr. |
| Additionally, remove dead_code annotations. |
| |
| Link: https://github.com/Rust-for-Linux/linux/issues/1105 |
| Reviewed-by: Alice Ryhl <aliceryhl@google.com> |
| Signed-off-by: Filipe Xavier <felipe_life@live.com> |
| Reviewed-by: Benno Lossin <benno.lossin@proton.me> |
| Reviewed-by: Gary Guo <gary@garyguo.net> |
| Link: https://lore.kernel.org/r/DM4PR14MB7276E6948E67B3B23D8EA847E9652@DM4PR14MB7276.namprd14.prod.outlook.com |
| Signed-off-by: Miguel Ojeda <ojeda@kernel.org> |
| Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
| --- |
| rust/kernel/error.rs | 13 ++++--------- |
| 1 file changed, 4 insertions(+), 9 deletions(-) |
| |
| --- a/rust/kernel/error.rs |
| +++ b/rust/kernel/error.rs |
| @@ -95,7 +95,7 @@ impl Error { |
| /// |
| /// It is a bug to pass an out-of-range `errno`. `EINVAL` would |
| /// be returned in such a case. |
| - pub(crate) fn from_errno(errno: core::ffi::c_int) -> Error { |
| + pub fn from_errno(errno: core::ffi::c_int) -> Error { |
| if errno < -(bindings::MAX_ERRNO as i32) || errno >= 0 { |
| // TODO: Make it a `WARN_ONCE` once available. |
| crate::pr_warn!( |
| @@ -133,8 +133,7 @@ impl Error { |
| } |
| |
| /// Returns the error encoded as a pointer. |
| - #[expect(dead_code)] |
| - pub(crate) fn to_ptr<T>(self) -> *mut T { |
| + pub fn to_ptr<T>(self) -> *mut T { |
| #[cfg_attr(target_pointer_width = "32", allow(clippy::useless_conversion))] |
| // SAFETY: `self.0` is a valid error due to its invariant. |
| unsafe { |
| @@ -270,9 +269,7 @@ pub fn to_result(err: core::ffi::c_int) |
| /// from_err_ptr(unsafe { bindings::devm_platform_ioremap_resource(pdev.to_ptr(), index) }) |
| /// } |
| /// ``` |
| -// TODO: Remove `dead_code` marker once an in-kernel client is available. |
| -#[allow(dead_code)] |
| -pub(crate) fn from_err_ptr<T>(ptr: *mut T) -> Result<*mut T> { |
| +pub fn from_err_ptr<T>(ptr: *mut T) -> Result<*mut T> { |
| // CAST: Casting a pointer to `*const core::ffi::c_void` is always valid. |
| let const_ptr: *const core::ffi::c_void = ptr.cast(); |
| // SAFETY: The FFI function does not deref the pointer. |
| @@ -318,9 +315,7 @@ pub(crate) fn from_err_ptr<T>(ptr: *mut |
| /// }) |
| /// } |
| /// ``` |
| -// TODO: Remove `dead_code` marker once an in-kernel client is available. |
| -#[allow(dead_code)] |
| -pub(crate) fn from_result<T, F>(f: F) -> T |
| +pub fn from_result<T, F>(f: F) -> T |
| where |
| T: From<i16>, |
| F: FnOnce() -> Result<T>, |