<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/rust/kernel/error.rs, branch v6.14</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v6.14</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v6.14'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2025-03-05T23:42:13Z</updated>
<entry>
<title>rust: error: add missing newline to pr_warn! calls</title>
<updated>2025-03-05T23:42:13Z</updated>
<author>
<name>Alban Kurti</name>
<email>kurti@invicto.ai</email>
</author>
<published>2025-02-06T21:07:53Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=6f5c36f56d475732981dcf624e0ac0cc7c8984c8'/>
<id>urn:sha1:6f5c36f56d475732981dcf624e0ac0cc7c8984c8</id>
<content type='text'>
Added missing newline at the end of pr_warn! usage
so the log is not missed.

Fixes: 6551a7fe0acb ("rust: error: Add Error::from_errno{_unchecked}()")
Reported-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
Link: https://github.com/Rust-for-Linux/linux/issues/1139
Signed-off-by: Alban Kurti &lt;kurti@invicto.ai&gt;
Link: https://lore.kernel.org/r/20250206-printing_fix-v3-2-a85273b501ae@invicto.ai
[ Replaced Closes with Link since it fixes part of the issue. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: error: import `kernel`'s `LayoutError` instead of `core`'s</title>
<updated>2025-01-13T22:45:13Z</updated>
<author>
<name>Jimmy Ostler</name>
<email>jtostler1@gmail.com</email>
</author>
<published>2024-12-20T06:25:31Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=7871c612cade8943694cc254740a374e3fb42a7c'/>
<id>urn:sha1:7871c612cade8943694cc254740a374e3fb42a7c</id>
<content type='text'>
Import the internal (`kernel::alloc`) version of `LayoutError` instead
of the `core::alloc` one.

In particular, this results in switching the type in the existing
`From&lt;LayoutError&gt; for Error` implementation.

Acked-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
Signed-off-by: Jimmy Ostler &lt;jtostler1@gmail.com&gt;
Link: https://lore.kernel.org/r/fe58a02189e8804a9eabdd01cb1927d4c491d79c.1734674670.git.jtostler1@gmail.com
[ Reworded commit. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: error: modify `from_errno` to use `try_from_errno`</title>
<updated>2024-12-17T22:52:06Z</updated>
<author>
<name>Daniel Sedlak</name>
<email>daniel@sedlak.dev</email>
</author>
<published>2024-12-07T11:24:45Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=9a02cbc5139e668f8b74e75a611d3a04b5241228'/>
<id>urn:sha1:9a02cbc5139e668f8b74e75a611d3a04b5241228</id>
<content type='text'>
Modify the from_errno function to use try_from_errno to
reduce code duplication while still maintaining all existing
behavior and error handling and also reduces unsafe code.

Link: https://github.com/Rust-for-Linux/linux/issues/1125
Suggested-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
Co-developed-by: Guilherme Augusto Martins da Silva &lt;guilhermev2huehue@gmail.com&gt;
Signed-off-by: Guilherme Augusto Martins da Silva &lt;guilhermev2huehue@gmail.com&gt;
Signed-off-by: Daniel Sedlak &lt;daniel@sedlak.dev&gt;
Reviewed-by: Fiona Behrens &lt;me@kloenk.dev&gt;
Link: https://lore.kernel.org/r/20241207112445.55502-1-daniel@sedlak.dev
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: map `long` to `isize` and `char` to `u8`</title>
<updated>2024-12-16T20:49:33Z</updated>
<author>
<name>Gary Guo</name>
<email>gary@garyguo.net</email>
</author>
<published>2024-09-13T21:29:24Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=1bae8729e50a900f41e9a1c17ae81113e4cf62b8'/>
<id>urn:sha1:1bae8729e50a900f41e9a1c17ae81113e4cf62b8</id>
<content type='text'>
The following FFI types are replaced compared to `core::ffi`:

1. `char` type is now always mapped to `u8`, since kernel uses
   `-funsigned-char` on the C code. `core::ffi` maps it to platform
   default ABI, which can be either signed or unsigned.

2. `long` is now always mapped to `isize`. It's very common in the
   kernel to use `long` to represent a pointer-sized integer, and in
   fact `intptr_t` is a typedef of `long` in the kernel. Enforce this
   mapping rather than mapping to `i32/i64` depending on platform can
   save us a lot of unnecessary casts.

Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Link: https://lore.kernel.org/r/20240913213041.395655-5-gary@garyguo.net
[ Moved `uaccess` changes from the next commit, since they were
  irrefutable patterns that Rust &gt;= 1.82.0 warns about. Reworded
  slightly and reformatted a few documentation comments. Rebased on
  top of `rust-next`. Added the removal of two casts to avoid Clippy
  warnings. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: use custom FFI integer types</title>
<updated>2024-11-10T22:58:00Z</updated>
<author>
<name>Gary Guo</name>
<email>gary@garyguo.net</email>
</author>
<published>2024-09-13T21:29:23Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=d072acda4862f095ec9056979b654cc06a22cc68'/>
<id>urn:sha1:d072acda4862f095ec9056979b654cc06a22cc68</id>
<content type='text'>
Currently FFI integer types are defined in libcore. This commit creates
the `ffi` crate and asks bindgen to use that crate for FFI integer types
instead of `core::ffi`.

This commit is preparatory and no type changes are made in this commit
yet.

Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
Link: https://lore.kernel.org/r/20240913213041.395655-4-gary@garyguo.net
[ Added `rustdoc`, `rusttest` and KUnit tests support. Rebased on top of
  `rust-next` (e.g. migrated more `core::ffi` cases). Reworded crate
  docs slightly and formatted. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: error: check for config `test` in `Error::name`</title>
<updated>2024-10-15T21:10:32Z</updated>
<author>
<name>Danilo Krummrich</name>
<email>dakr@kernel.org</email>
</author>
<published>2024-10-04T15:41:27Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=4a28ab469ff01855eb819dfd94754d1792f03f2a'/>
<id>urn:sha1:4a28ab469ff01855eb819dfd94754d1792f03f2a</id>
<content type='text'>
Additional to `testlib` also check for `test` in `Error::name`. This is
required by a subsequent patch that (indirectly) uses `Error` in test
cases.

Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Reviewed-by: Benno Lossin &lt;benno.lossin@proton.me&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Signed-off-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
Link: https://lore.kernel.org/r/20241004154149.93856-24-dakr@kernel.org
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: error: use `core::alloc::LayoutError`</title>
<updated>2024-10-15T21:10:32Z</updated>
<author>
<name>Danilo Krummrich</name>
<email>dakr@kernel.org</email>
</author>
<published>2024-10-04T15:41:26Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=29a48d25ff53c183482dc88a99133a0fb5aa541a'/>
<id>urn:sha1:29a48d25ff53c183482dc88a99133a0fb5aa541a</id>
<content type='text'>
Use `core::alloc::LayoutError` instead of `alloc::alloc::LayoutError` in
preparation to get rid of Rust's alloc crate.

Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Reviewed-by: Benno Lossin &lt;benno.lossin@proton.me&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Signed-off-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
Link: https://lore.kernel.org/r/20241004154149.93856-23-dakr@kernel.org
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: error: optimize error type to use nonzero</title>
<updated>2024-10-09T22:33:42Z</updated>
<author>
<name>Filipe Xavier</name>
<email>felipe_life@live.com</email>
</author>
<published>2024-10-05T19:51:23Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=e9759c5b9ea555d09f426c70c880e9522e9b0576'/>
<id>urn:sha1:e9759c5b9ea555d09f426c70c880e9522e9b0576</id>
<content type='text'>
Optimize `Result&lt;(), Error&gt;` size by changing `Error` type to
`NonZero*` for niche optimization.

This reduces the space used by the `Result` type, as the `NonZero*`
type enables the compiler to apply more efficient memory layout.
For example, the `Result&lt;(), Error&gt;` changes size from 8 to 4 bytes.

Link: https://github.com/Rust-for-Linux/linux/issues/1120
Signed-off-by: Filipe Xavier &lt;felipe_life@live.com&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Reviewed-by: Fiona Behrens &lt;me@kloenk.dev&gt;
Link: https://lore.kernel.org/r/BL0PR02MB4914B9B088865CF237731207E9732@BL0PR02MB4914.namprd02.prod.outlook.com
[ Removed unneeded block around `match`, added backticks in panic
  message and added intra-doc link. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: error: make conversion functions public</title>
<updated>2024-10-07T19:39:57Z</updated>
<author>
<name>Filipe Xavier</name>
<email>felipe_life@live.com</email>
</author>
<published>2024-09-13T10:19:56Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=5ed147473458f8c20f908a03227d8f5bb3cb8f7d'/>
<id>urn:sha1:5ed147473458f8c20f908a03227d8f5bb3cb8f7d</id>
<content type='text'>
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 &lt;aliceryhl@google.com&gt;
Signed-off-by: Filipe Xavier &lt;felipe_life@live.com&gt;
Reviewed-by: Benno Lossin &lt;benno.lossin@proton.me&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Link: https://lore.kernel.org/r/DM4PR14MB7276E6948E67B3B23D8EA847E9652@DM4PR14MB7276.namprd14.prod.outlook.com
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: start using the `#[expect(...)]` attribute</title>
<updated>2024-10-07T19:39:57Z</updated>
<author>
<name>Miguel Ojeda</name>
<email>ojeda@kernel.org</email>
</author>
<published>2024-09-04T20:43:45Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=1f9ed172545687e5c04c77490a45896be6d2e459'/>
<id>urn:sha1:1f9ed172545687e5c04c77490a45896be6d2e459</id>
<content type='text'>
In Rust, it is possible to `allow` particular warnings (diagnostics,
lints) locally, making the compiler ignore instances of a given warning
within a given function, module, block, etc.

It is similar to `#pragma GCC diagnostic push` + `ignored` + `pop` in C:

    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wunused-function"
    static void f(void) {}
    #pragma GCC diagnostic pop

But way less verbose:

    #[allow(dead_code)]
    fn f() {}

By that virtue, it makes it possible to comfortably enable more
diagnostics by default (i.e. outside `W=` levels) that may have some
false positives but that are otherwise quite useful to keep enabled to
catch potential mistakes.

The `#[expect(...)]` attribute [1] takes this further, and makes the
compiler warn if the diagnostic was _not_ produced. For instance, the
following will ensure that, when `f()` is called somewhere, we will have
to remove the attribute:

    #[expect(dead_code)]
    fn f() {}

If we do not, we get a warning from the compiler:

    warning: this lint expectation is unfulfilled
     --&gt; x.rs:3:10
      |
    3 | #[expect(dead_code)]
      |          ^^^^^^^^^
      |
      = note: `#[warn(unfulfilled_lint_expectations)]` on by default

This means that `expect`s do not get forgotten when they are not needed.

See the next commit for more details, nuances on its usage and
documentation on the feature.

The attribute requires the `lint_reasons` [2] unstable feature, but it
is becoming stable in 1.81.0 (to be released on 2024-09-05) and it has
already been useful to clean things up in this patch series, finding
cases where the `allow`s should not have been there.

Thus, enable `lint_reasons` and convert some of our `allow`s to `expect`s
where possible.

This feature was also an example of the ongoing collaboration between
Rust and the kernel -- we tested it in the kernel early on and found an
issue that was quickly resolved [3].

Cc: Fridtjof Stoldt &lt;xfrednet@gmail.com&gt;
Cc: Urgau &lt;urgau@numericable.fr&gt;
Link: https://rust-lang.github.io/rfcs/2383-lint-reasons.html#expect-lint-attribute [1]
Link: https://github.com/rust-lang/rust/issues/54503 [2]
Link: https://github.com/rust-lang/rust/issues/114557 [3]
Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Reviewed-by: Trevor Gross &lt;tmgross@umich.edu&gt;
Tested-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Link: https://lore.kernel.org/r/20240904204347.168520-18-ojeda@kernel.org
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
</feed>
