* [PATCH] rust: cpufreq: streamline find_supply_names
@ 2025-09-15 13:59 Thorsten Blum
2025-09-29 9:05 ` Viresh Kumar
2025-09-29 9:38 ` Alice Ryhl
0 siblings, 2 replies; 4+ messages in thread
From: Thorsten Blum @ 2025-09-15 13:59 UTC (permalink / raw)
To: Rafael J. Wysocki, Viresh Kumar, Miguel Ojeda, Alex Gaynor,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich
Cc: Thorsten Blum, linux-pm, linux-kernel, rust-for-linux
Remove local variables from find_supply_names() and use .and_then() with
the more concise kernel::kvec![] macro, instead of KVec::with_capacity()
followed by .push() and Some().
No functional changes intended.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
drivers/cpufreq/rcpufreq_dt.rs | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/cpufreq/rcpufreq_dt.rs b/drivers/cpufreq/rcpufreq_dt.rs
index 7e1fbf9a091f..224d063c7cec 100644
--- a/drivers/cpufreq/rcpufreq_dt.rs
+++ b/drivers/cpufreq/rcpufreq_dt.rs
@@ -28,15 +28,11 @@ fn find_supply_name_exact(dev: &Device, name: &str) -> Option<CString> {
/// Finds supply name for the CPU from DT.
fn find_supply_names(dev: &Device, cpu: cpu::CpuId) -> Option<KVec<CString>> {
// Try "cpu0" for older DTs, fallback to "cpu".
- let name = (cpu.as_u32() == 0)
+ (cpu.as_u32() == 0)
.then(|| find_supply_name_exact(dev, "cpu0"))
.flatten()
- .or_else(|| find_supply_name_exact(dev, "cpu"))?;
-
- let mut list = KVec::with_capacity(1, GFP_KERNEL).ok()?;
- list.push(name, GFP_KERNEL).ok()?;
-
- Some(list)
+ .or_else(|| find_supply_name_exact(dev, "cpu"))
+ .and_then(|name| kernel::kvec![name].ok())
}
/// Represents the cpufreq dt device.
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] rust: cpufreq: streamline find_supply_names
2025-09-15 13:59 [PATCH] rust: cpufreq: streamline find_supply_names Thorsten Blum
@ 2025-09-29 9:05 ` Viresh Kumar
2025-09-29 9:38 ` Alice Ryhl
1 sibling, 0 replies; 4+ messages in thread
From: Viresh Kumar @ 2025-09-29 9:05 UTC (permalink / raw)
To: Thorsten Blum
Cc: Rafael J. Wysocki, Miguel Ojeda, Alex Gaynor, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Alice Ryhl, Trevor Gross, Danilo Krummrich, linux-pm,
linux-kernel, rust-for-linux
On 15-09-25, 15:59, Thorsten Blum wrote:
> Remove local variables from find_supply_names() and use .and_then() with
> the more concise kernel::kvec![] macro, instead of KVec::with_capacity()
> followed by .push() and Some().
>
> No functional changes intended.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> drivers/cpufreq/rcpufreq_dt.rs | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/cpufreq/rcpufreq_dt.rs b/drivers/cpufreq/rcpufreq_dt.rs
> index 7e1fbf9a091f..224d063c7cec 100644
> --- a/drivers/cpufreq/rcpufreq_dt.rs
> +++ b/drivers/cpufreq/rcpufreq_dt.rs
> @@ -28,15 +28,11 @@ fn find_supply_name_exact(dev: &Device, name: &str) -> Option<CString> {
> /// Finds supply name for the CPU from DT.
> fn find_supply_names(dev: &Device, cpu: cpu::CpuId) -> Option<KVec<CString>> {
> // Try "cpu0" for older DTs, fallback to "cpu".
> - let name = (cpu.as_u32() == 0)
> + (cpu.as_u32() == 0)
> .then(|| find_supply_name_exact(dev, "cpu0"))
> .flatten()
> - .or_else(|| find_supply_name_exact(dev, "cpu"))?;
> -
> - let mut list = KVec::with_capacity(1, GFP_KERNEL).ok()?;
> - list.push(name, GFP_KERNEL).ok()?;
> -
> - Some(list)
> + .or_else(|| find_supply_name_exact(dev, "cpu"))
> + .and_then(|name| kernel::kvec![name].ok())
> }
>
> /// Represents the cpufreq dt device.
Applied. Thanks.
--
viresh
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] rust: cpufreq: streamline find_supply_names
2025-09-15 13:59 [PATCH] rust: cpufreq: streamline find_supply_names Thorsten Blum
2025-09-29 9:05 ` Viresh Kumar
@ 2025-09-29 9:38 ` Alice Ryhl
2025-09-29 11:02 ` Viresh Kumar
1 sibling, 1 reply; 4+ messages in thread
From: Alice Ryhl @ 2025-09-29 9:38 UTC (permalink / raw)
To: Thorsten Blum
Cc: Rafael J. Wysocki, Viresh Kumar, Miguel Ojeda, Alex Gaynor,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Trevor Gross, Danilo Krummrich, linux-pm,
linux-kernel, rust-for-linux
On Mon, Sep 15, 2025 at 4:01 PM Thorsten Blum <thorsten.blum@linux.dev> wrote:
>
> Remove local variables from find_supply_names() and use .and_then() with
> the more concise kernel::kvec![] macro, instead of KVec::with_capacity()
> followed by .push() and Some().
>
> No functional changes intended.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> drivers/cpufreq/rcpufreq_dt.rs | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/cpufreq/rcpufreq_dt.rs b/drivers/cpufreq/rcpufreq_dt.rs
> index 7e1fbf9a091f..224d063c7cec 100644
> --- a/drivers/cpufreq/rcpufreq_dt.rs
> +++ b/drivers/cpufreq/rcpufreq_dt.rs
> @@ -28,15 +28,11 @@ fn find_supply_name_exact(dev: &Device, name: &str) -> Option<CString> {
> /// Finds supply name for the CPU from DT.
> fn find_supply_names(dev: &Device, cpu: cpu::CpuId) -> Option<KVec<CString>> {
> // Try "cpu0" for older DTs, fallback to "cpu".
> - let name = (cpu.as_u32() == 0)
> + (cpu.as_u32() == 0)
> .then(|| find_supply_name_exact(dev, "cpu0"))
> .flatten()
> - .or_else(|| find_supply_name_exact(dev, "cpu"))?;
> -
> - let mut list = KVec::with_capacity(1, GFP_KERNEL).ok()?;
> - list.push(name, GFP_KERNEL).ok()?;
> -
> - Some(list)
> + .or_else(|| find_supply_name_exact(dev, "cpu"))
> + .and_then(|name| kernel::kvec![name].ok())
This is a pre-existing issue, but ... this treats allocation failure
and non-existence the same way. That sounds wrong.
Alice
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] rust: cpufreq: streamline find_supply_names
2025-09-29 9:38 ` Alice Ryhl
@ 2025-09-29 11:02 ` Viresh Kumar
0 siblings, 0 replies; 4+ messages in thread
From: Viresh Kumar @ 2025-09-29 11:02 UTC (permalink / raw)
To: Alice Ryhl
Cc: Thorsten Blum, Rafael J. Wysocki, Miguel Ojeda, Alex Gaynor,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Trevor Gross, Danilo Krummrich, linux-pm,
linux-kernel, rust-for-linux
On 29-09-25, 11:38, Alice Ryhl wrote:
> This is a pre-existing issue, but ... this treats allocation failure
> and non-existence the same way. That sounds wrong.
What about this over the current patch:
diff --git a/drivers/cpufreq/rcpufreq_dt.rs b/drivers/cpufreq/rcpufreq_dt.rs
index 224d063c7cec..e509b46b64c7 100644
--- a/drivers/cpufreq/rcpufreq_dt.rs
+++ b/drivers/cpufreq/rcpufreq_dt.rs
@@ -26,13 +26,17 @@ fn find_supply_name_exact(dev: &Device, name: &str) -> Option<CString> {
}
/// Finds supply name for the CPU from DT.
-fn find_supply_names(dev: &Device, cpu: cpu::CpuId) -> Option<KVec<CString>> {
+fn find_supply_names(dev: &Device, cpu: cpu::CpuId) -> Result<Option<KVec<CString>>> {
// Try "cpu0" for older DTs, fallback to "cpu".
- (cpu.as_u32() == 0)
+ let name = (cpu.as_u32() == 0)
.then(|| find_supply_name_exact(dev, "cpu0"))
.flatten()
- .or_else(|| find_supply_name_exact(dev, "cpu"))
- .and_then(|name| kernel::kvec![name].ok())
+ .or_else(|| find_supply_name_exact(dev, "cpu"));
+
+ Ok(match name {
+ None => None,
+ Some(n) => Some(kernel::kvec![n]?),
+ })
}
/// Represents the cpufreq dt device.
@@ -68,7 +72,7 @@ fn init(policy: &mut cpufreq::Policy) -> Result<Self::PData> {
mask.set(cpu);
- let token = find_supply_names(dev, cpu)
+ let token = find_supply_names(dev, cpu)?
.map(|names| {
opp::Config::<Self>::new()
.set_regulator_names(names)?
--
viresh
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-09-29 11:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-15 13:59 [PATCH] rust: cpufreq: streamline find_supply_names Thorsten Blum
2025-09-29 9:05 ` Viresh Kumar
2025-09-29 9:38 ` Alice Ryhl
2025-09-29 11:02 ` Viresh Kumar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).