* [PATCH] rust: cpufreq: fix `undocumented_unsafe_blocks` in `PolicyCpu::from_cpu()`
@ 2026-10-18 16:37 Miguel Ojeda
2026-10-18 16:45 ` Miguel Ojeda
2026-10-19 4:13 ` Zhongqiu Han
0 siblings, 2 replies; 4+ messages in thread
From: Miguel Ojeda @ 2026-10-18 16:37 UTC (permalink / raw)
To: Rafael J. Wysocki, Viresh Kumar, Miguel Ojeda
Cc: linux-pm, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, rust-for-linux
For Rust <= 1.86, Clippy triggers after commit 02c5d7bfa872 ("rust:
cpufreq: reject NULL from cpufreq_cpu_get()"):
warning: unsafe block missing a safety comment
--> rust/kernel/cpufreq.rs:700:26
|
700 | NonNull::new(unsafe { bindings::cpufreq_cpu_get(u32::from(cpu)) }).ok_or(ENODEV)?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#undocumented_unsafe_blocks
= note: requested on the command line with `-W clippy::undocumented-unsafe-blocks`
Thus clean it up.
Fixes: 02c5d7bfa872 ("rust: cpufreq: reject NULL from cpufreq_cpu_get()")
Assisted-by: LLM
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
rust/kernel/cpufreq.rs | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/rust/kernel/cpufreq.rs b/rust/kernel/cpufreq.rs
index b75d692846a2..5f5beedec88b 100644
--- a/rust/kernel/cpufreq.rs
+++ b/rust/kernel/cpufreq.rs
@@ -695,9 +695,11 @@ fn clear_data<T: ForeignOwnable>(&mut self) -> Option<T> {
impl<'a> PolicyCpu<'a> {
fn from_cpu(cpu: CpuId) -> Result<Self> {
- // SAFETY: It is safe to call `cpufreq_cpu_get` for any valid CPU.
- let ptr =
- NonNull::new(unsafe { bindings::cpufreq_cpu_get(u32::from(cpu)) }).ok_or(ENODEV)?;
+ let ptr = NonNull::new(
+ // SAFETY: It is safe to call `cpufreq_cpu_get` for any valid CPU.
+ unsafe { bindings::cpufreq_cpu_get(u32::from(cpu)) },
+ )
+ .ok_or(ENODEV)?;
Ok(Self(
// SAFETY: `ptr` is non-NULL and `cpufreq_cpu_get()` took a reference on it, so it is
base-commit: 2efb7a11f1aa4d2dc285fe2680cca22cb9f72f64
--
2.56.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] rust: cpufreq: fix `undocumented_unsafe_blocks` in `PolicyCpu::from_cpu()`
2026-10-18 16:37 [PATCH] rust: cpufreq: fix `undocumented_unsafe_blocks` in `PolicyCpu::from_cpu()` Miguel Ojeda
@ 2026-10-18 16:45 ` Miguel Ojeda
2026-10-19 4:13 ` Zhongqiu Han
1 sibling, 0 replies; 4+ messages in thread
From: Miguel Ojeda @ 2026-10-18 16:45 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Rafael J. Wysocki, Viresh Kumar, linux-pm, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, rust-for-linux
On Sun, Oct 18, 2026 at 6:37 PM Miguel Ojeda <ojeda@kernel.org> wrote:
>
> + let ptr = NonNull::new(
> + // SAFETY: It is safe to call `cpufreq_cpu_get` for any valid CPU.
> + unsafe { bindings::cpufreq_cpu_get(u32::from(cpu)) },
> + )
> + .ok_or(ENODEV)?;
The other option is to split the statements in two, which probably
looks better, but this shows how to do it without changing the shape
of the code.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] rust: cpufreq: fix `undocumented_unsafe_blocks` in `PolicyCpu::from_cpu()`
2026-10-18 16:37 [PATCH] rust: cpufreq: fix `undocumented_unsafe_blocks` in `PolicyCpu::from_cpu()` Miguel Ojeda
2026-10-18 16:45 ` Miguel Ojeda
@ 2026-10-19 4:13 ` Zhongqiu Han
2026-10-19 6:32 ` Viresh Kumar
1 sibling, 1 reply; 4+ messages in thread
From: Zhongqiu Han @ 2026-10-19 4:13 UTC (permalink / raw)
To: Miguel Ojeda, Rafael J. Wysocki, Viresh Kumar
Cc: linux-pm, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, rust-for-linux, zhongqiu.han
On 10/19/2026 12:37 AM, Miguel Ojeda wrote:
> For Rust <= 1.86, Clippy triggers after commit 02c5d7bfa872 ("rust:
> cpufreq: reject NULL from cpufreq_cpu_get()"):
>
> warning: unsafe block missing a safety comment
> --> rust/kernel/cpufreq.rs:700:26
> |
> 700 | NonNull::new(unsafe { bindings::cpufreq_cpu_get(u32::from(cpu)) }).ok_or(ENODEV)?;
> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> |
> = help: consider adding a safety comment on the preceding line
> = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#undocumented_unsafe_blocks
> = note: requested on the command line with `-W clippy::undocumented-unsafe-blocks`
>
> Thus clean it up.
>
> Fixes: 02c5d7bfa872 ("rust: cpufreq: reject NULL from cpufreq_cpu_get()")
> Assisted-by: LLM
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Reviewed-by: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
FWIW, splitting it into two statements as you mentioned would read
better to me.
> ---
> rust/kernel/cpufreq.rs | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/rust/kernel/cpufreq.rs b/rust/kernel/cpufreq.rs
> index b75d692846a2..5f5beedec88b 100644
> --- a/rust/kernel/cpufreq.rs
> +++ b/rust/kernel/cpufreq.rs
> @@ -695,9 +695,11 @@ fn clear_data<T: ForeignOwnable>(&mut self) -> Option<T> {
>
> impl<'a> PolicyCpu<'a> {
> fn from_cpu(cpu: CpuId) -> Result<Self> {
> - // SAFETY: It is safe to call `cpufreq_cpu_get` for any valid CPU.
> - let ptr =
> - NonNull::new(unsafe { bindings::cpufreq_cpu_get(u32::from(cpu)) }).ok_or(ENODEV)?;
> + let ptr = NonNull::new(
> + // SAFETY: It is safe to call `cpufreq_cpu_get` for any valid CPU.
> + unsafe { bindings::cpufreq_cpu_get(u32::from(cpu)) },
> + )
> + .ok_or(ENODEV)?;
>
> Ok(Self(
> // SAFETY: `ptr` is non-NULL and `cpufreq_cpu_get()` took a reference on it, so it is
>
> base-commit: 2efb7a11f1aa4d2dc285fe2680cca22cb9f72f64
--
Thx and BRs,
Zhongqiu Han
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] rust: cpufreq: fix `undocumented_unsafe_blocks` in `PolicyCpu::from_cpu()`
2026-10-19 4:13 ` Zhongqiu Han
@ 2026-10-19 6:32 ` Viresh Kumar
0 siblings, 0 replies; 4+ messages in thread
From: Viresh Kumar @ 2026-10-19 6:32 UTC (permalink / raw)
To: Zhongqiu Han
Cc: Miguel Ojeda, Rafael J. Wysocki, linux-pm, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, rust-for-linux
On 19-10-26, 12:13, Zhongqiu Han wrote:
> On 10/19/2026 12:37 AM, Miguel Ojeda wrote:
> > For Rust <= 1.86, Clippy triggers after commit 02c5d7bfa872 ("rust:
> > cpufreq: reject NULL from cpufreq_cpu_get()"):
> >
> > warning: unsafe block missing a safety comment
> > --> rust/kernel/cpufreq.rs:700:26
> > |
> > 700 | NonNull::new(unsafe { bindings::cpufreq_cpu_get(u32::from(cpu)) }).ok_or(ENODEV)?;
> > | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > |
> > = help: consider adding a safety comment on the preceding line
> > = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#undocumented_unsafe_blocks
> > = note: requested on the command line with `-W clippy::undocumented-unsafe-blocks`
> >
> > Thus clean it up.
> >
> > Fixes: 02c5d7bfa872 ("rust: cpufreq: reject NULL from cpufreq_cpu_get()")
> > Assisted-by: LLM
> > Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
>
> Reviewed-by: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
>
> FWIW, splitting it into two statements as you mentioned would read better to
> me.
I agree.
--
viresh
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-10-19 6:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-18 16:37 [PATCH] rust: cpufreq: fix `undocumented_unsafe_blocks` in `PolicyCpu::from_cpu()` Miguel Ojeda
2026-10-18 16:45 ` Miguel Ojeda
2026-10-19 4:13 ` Zhongqiu Han
2026-10-19 6:32 ` Viresh Kumar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox