* Re: [PATCH] rust: firmware: avoid UB in example by passing parameter
2026-07-11 18:02 [PATCH] rust: firmware: avoid UB in example by passing parameter Miguel Ojeda
@ 2026-07-12 0:08 ` Gary Guo
2026-07-12 0:15 ` Alexandre Courbot
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Gary Guo @ 2026-07-12 0:08 UTC (permalink / raw)
To: Miguel Ojeda, Luis Chamberlain, Russ Weight, Danilo Krummrich
Cc: driver-core, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
Onur Özkan, rust-for-linux
On Sat Jul 11, 2026 at 7:02 PM BST, Miguel Ojeda wrote:
> The `Firmware` example crafts an `ARef<Device>` using a null pointer,
> which breaks the safety requirements of `Device::get_device()`.
>
> Instead, pass an `ARef` via a parameter, which is simpler, avoids UB
> and removes an `unsafe` block.
>
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
> ---
> rust/kernel/firmware.rs | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] rust: firmware: avoid UB in example by passing parameter
2026-07-11 18:02 [PATCH] rust: firmware: avoid UB in example by passing parameter Miguel Ojeda
2026-07-12 0:08 ` Gary Guo
@ 2026-07-12 0:15 ` Alexandre Courbot
2026-07-12 0:15 ` Danilo Krummrich
2026-07-16 19:17 ` Danilo Krummrich
3 siblings, 0 replies; 5+ messages in thread
From: Alexandre Courbot @ 2026-07-12 0:15 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Luis Chamberlain, Russ Weight, Danilo Krummrich, driver-core,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Daniel Almeida,
Tamir Duberstein, Onur Özkan, rust-for-linux
On Sun Jul 12, 2026 at 3:02 AM JST, Miguel Ojeda wrote:
> The `Firmware` example crafts an `ARef<Device>` using a null pointer,
> which breaks the safety requirements of `Device::get_device()`.
>
> Instead, pass an `ARef` via a parameter, which is simpler, avoids UB
> and removes an `unsafe` block.
>
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] rust: firmware: avoid UB in example by passing parameter
2026-07-11 18:02 [PATCH] rust: firmware: avoid UB in example by passing parameter Miguel Ojeda
2026-07-12 0:08 ` Gary Guo
2026-07-12 0:15 ` Alexandre Courbot
@ 2026-07-12 0:15 ` Danilo Krummrich
2026-07-16 19:17 ` Danilo Krummrich
3 siblings, 0 replies; 5+ messages in thread
From: Danilo Krummrich @ 2026-07-12 0:15 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Luis Chamberlain, Russ Weight, driver-core, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
Onur Özkan, rust-for-linux
On Sat Jul 11, 2026 at 8:02 PM CEST, Miguel Ojeda wrote:
> diff --git a/rust/kernel/firmware.rs b/rust/kernel/firmware.rs
> index 71168d8004e2..3aa9de3c4a04 100644
> --- a/rust/kernel/firmware.rs
> +++ b/rust/kernel/firmware.rs
> @@ -51,12 +51,9 @@ fn request_nowarn() -> Self {
> /// # Examples
> ///
> /// ```no_run
> -/// # use kernel::{device::Device, firmware::Firmware};
> -///
> -/// # fn no_run() -> Result<(), Error> {
> -/// # // SAFETY: *NOT* safe, just for the example to get an `ARef<Device>` instance
> -/// # let dev = unsafe { Device::get_device(core::ptr::null_mut()) };
> +/// # use kernel::{device::Device, firmware::Firmware, sync::aref::ARef};
> ///
We could take the chance to also drop this empty line.
> +/// # fn no_run(dev: ARef<Device>) -> Result<(), Error> {
> /// let fw = Firmware::request(c"path/to/firmware.bin", &dev)?;
> /// let blob = fw.data();
> ///
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] rust: firmware: avoid UB in example by passing parameter
2026-07-11 18:02 [PATCH] rust: firmware: avoid UB in example by passing parameter Miguel Ojeda
` (2 preceding siblings ...)
2026-07-12 0:15 ` Danilo Krummrich
@ 2026-07-16 19:17 ` Danilo Krummrich
3 siblings, 0 replies; 5+ messages in thread
From: Danilo Krummrich @ 2026-07-16 19:17 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Luis Chamberlain, Russ Weight, Danilo Krummrich, driver-core,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Özkan,
rust-for-linux
On Sat, 11 Jul 2026 20:02:31 +0200, Miguel Ojeda wrote:
> [PATCH] rust: firmware: avoid UB in example by passing parameter
Applied, thanks!
Branch: driver-core-testing
Tree: git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git
[1/1] rust: firmware: avoid UB in example by passing parameter
commit: c945c8f37a81
[ Also drop the second superfluous empty line. - Danilo ]
The patch will appear in the next linux-next integration (typically within 24
hours on weekdays).
The patch is in the driver-core-testing branch and will be promoted to
driver-core-next after validation.
^ permalink raw reply [flat|nested] 5+ messages in thread