[PATCH] rust: error.rs: Remove dead_code marker and make from_err_=

From: Filipe Xavier
Date: Sat Sep 07 2024 - 08:50:33 EST


Remove dead_code annotation from from_err_ptr, from_result and to_ptr funct=
ions in error.rs file and change visibility to public, making it accessible=
outside the kernel crate(issue #1105).

Signed-off-by: Filipe Xavier <felipe_life@xxxxxxxx>
---
diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs
index 6f1587a2524e..ecfa6aa41034 100644
--- a/rust/kernel/error.rs
+++ b/rust/kernel/error.rs
@@ -133,8 +133,7 @@ pub(crate) fn to_blk_status(self) -> bindings::blk_stat=
us_t {
}

/// Returns the error encoded as a pointer.
- #[allow(dead_code)]
- pub(crate) fn to_ptr<T>(self) -> *mut T {
+ pub fn to_ptr<T>(self) -> *mut T {
#[cfg_attr(target_pointer_width =3D "32", allow(clippy::useless_co=
nversion))]
// SAFETY: `self.0` is a valid error due to its invariant.
unsafe {
@@ -268,9 +267,7 @@ pub fn to_result(err: core::ffi::c_int) -> Result {
/// from_err_ptr(unsafe { bindings::devm_platform_ioremap_resource(pde=
v.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 val=
id.
let const_ptr: *const core::ffi::c_void =3D ptr.cast();
// SAFETY: The FFI function does not deref the pointer.
@@ -315,9 +312,7 @@ pub(crate) fn from_err_ptr<T>(ptr: *mut T) -> Result<*m=
ut T> {
/// })
/// }
/// ```
-// 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>,

--_000_DM4PR14MB72760296911674F92C7A6C01E99F2DM4PR14MB7276namp_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-=
1">
<style type=3D"text/css" style=3D"display:none;"> P {margin-top:0;margin-bo=
ttom:0;} </style>
</head>
<body dir=3D"ltr">
<div style=3D"background-color: rgb(31, 31, 31);">
<div style=3D"line-height: 19px; white-space: pre; font-family: &quot;Droid=
Sans Mono&quot;, &quot;monospace&quot;, monospace; font-size: 14px; color:=
rgb(204, 204, 204);">
>From 93dc3be19450447a3a7090bd1dfb9f3daac3e8d2 Mon Sep 17 00:00:00 2001</div=
>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
From: Filipe Xavier &lt;felipe_life@xxxxxxxx&gt;</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
Date: Sat, 7 Sep 2024 14:50:33 +0200</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
Subject: [PATCH] rust: error.rs: Remove dead_code marker and make from_err_=
ptr, from_result and to_ptr public</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
<br>
</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
Remove dead_code annotation from from_err_ptr, from_result and to_ptr funct=
ions in error.rs file and change visibility to public, making it accessible=
outside the kernel crate(issue #1105).</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
<br>
</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
Signed-off-by: Filipe Xavier &lt;felipe_life@xxxxxxxx&gt;</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
---</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
index 6f1587a2524e..ecfa6aa41034 100644</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
--- a/rust/kernel/error.rs</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
+++ b/rust/kernel/error.rs</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
@@ -133,8 +133,7 @@ pub(crate) fn to_blk_status(self) -&gt; bindings::blk_s=
tatus_t {</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
&nbsp; &nbsp; &nbsp;}</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
&nbsp;</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
&nbsp; &nbsp; &nbsp;/// Returns the error encoded as a pointer.</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
- &nbsp; &nbsp;#[allow(dead_code)]</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
- &nbsp; &nbsp;pub(crate) fn to_ptr&lt;T&gt;(self) -&gt; *mut T {</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
+ &nbsp; &nbsp;pub fn to_ptr&lt;T&gt;(self) -&gt; *mut T {</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#[cfg_attr(target_pointer_width =3D &quot=
;32&quot;, allow(clippy::useless_conversion))]</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// SAFETY: `self.0` is a valid error due =
to its invariant.</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;unsafe {</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
@@ -268,9 +267,7 @@ pub fn to_result(err: core::ffi::c_int) -&gt; Result {<=
/div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
&nbsp;/// &nbsp; &nbsp; from_err_ptr(unsafe { bindings::devm_platform_iorem=
ap_resource(pdev.to_ptr(), index) })</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
&nbsp;/// }</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
&nbsp;/// ```</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
-// TODO: Remove `dead_code` marker once an in-kernel client is available.<=
/div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
-#[allow(dead_code)]</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
-pub(crate) fn from_err_ptr&lt;T&gt;(ptr: *mut T) -&gt; Result&lt;*mut T&gt=
; {</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
+pub fn from_err_ptr&lt;T&gt;(ptr: *mut T) -&gt; Result&lt;*mut T&gt; {</di=
v>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
&nbsp; &nbsp; &nbsp;// CAST: Casting a pointer to `*const core::ffi::c_void=
` is always valid.</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
&nbsp; &nbsp; &nbsp;let const_ptr: *const core::ffi::c_void =3D ptr.cast();=
</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
&nbsp; &nbsp; &nbsp;// SAFETY: The FFI function does not deref the pointer.=
</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
@@ -315,9 +312,7 @@ pub(crate) fn from_err_ptr&lt;T&gt;(ptr: *mut T) -&gt; =
Result&lt;*mut T&gt; {</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
&nbsp;/// &nbsp; &nbsp; })</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
&nbsp;/// }</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
&nbsp;/// ```</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
-// TODO: Remove `dead_code` marker once an in-kernel client is available.<=
/div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
-#[allow(dead_code)]</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
-pub(crate) fn from_result&lt;T, F&gt;(f: F) -&gt; T</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
+pub fn from_result&lt;T, F&gt;(f: F) -&gt; T</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
&nbsp;where</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
&nbsp; &nbsp; &nbsp;T: From&lt;i16&gt;,</div>
<div style=3D"font-family: &quot;Droid Sans Mono&quot;, &quot;monospace&quo=
t;, monospace; font-size: 14px; color: rgb(204, 204, 204);">
&nbsp; &nbsp; &nbsp;F: FnOnce() -&gt; Result&lt;T&gt;,</div>
</div>
</body>
</html>

--_000_DM4PR14MB72760296911674F92C7A6C01E99F2DM4PR14MB7276namp_--

--_004_DM4PR14MB72760296911674F92C7A6C01E99F2DM4PR14MB7276namp_
Content-Type: text/x-patch;
name="0001-make-public-functions-on-error-rs.patch"
Content-Description: 0001-make-public-functions-on-error-rs.patch
Content-Disposition: attachment;
filename="0001-make-public-functions-on-error-rs.patch"; size=2029;
creation-date="Sat, 07 Sep 2024 18:18:55 GMT";
modification-date="Sat, 07 Sep 2024 18:19:00 GMT"
Content-Transfer-Encoding: base64

RnJvbSA5M2RjM2JlMTk0NTA0NDdhM2E3MDkwYmQxZGZiOWYzZGFhYzNlOGQyIE1vbiBTZXAgMTcg
MDA6MDA6MDAgMjAwMQpGcm9tOiBGaWxpcGUgWGF2aWVyIDxmZWxpcGVfbGlmZUBsaXZlLmNvbT4K
RGF0ZTogU2F0LCA3IFNlcCAyMDI0IDE0OjUwOjMzICswMjAwClN1YmplY3Q6IFtQQVRDSF0gcnVz
dDogZXJyb3IucnM6IFJlbW92ZSBkZWFkX2NvZGUgbWFya2VyIGFuZCBtYWtlIGZyb21fZXJyX3B0
ciwgZnJvbV9yZXN1bHQgYW5kIHRvX3B0ciBwdWJsaWMKClJlbW92ZSBkZWFkX2NvZGUgYW5ub3Rh
dGlvbiBmcm9tIGZyb21fZXJyX3B0ciwgZnJvbV9yZXN1bHQgYW5kIHRvX3B0ciBmdW5jdGlvbnMg
aW4gZXJyb3IucnMgZmlsZSBhbmQgY2hhbmdlIHZpc2liaWxpdHkgdG8gcHVibGljLCBtYWtpbmcg
aXQgYWNjZXNzaWJsZSBvdXRzaWRlIHRoZSBrZXJuZWwgY3JhdGUoaXNzdWUgIzExMDUpLgoKU2ln
bmVkLW9mZi1ieTogRmlsaXBlIFhhdmllciA8ZmVsaXBlX2xpZmVAbGl2ZS5jb20+Ci0tLQpkaWZm
IC0tZ2l0IGEvcnVzdC9rZXJuZWwvZXJyb3IucnMgYi9ydXN0L2tlcm5lbC9lcnJvci5ycwppbmRl
eCA2ZjE1ODdhMjUy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