Skip to content

Commit 24287f9

Browse files
tobluxvireshk
authored andcommitted
rust: cpufreq: streamline find_supply_names
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> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
1 parent ebc4ed1 commit 24287f9

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

drivers/cpufreq/rcpufreq_dt.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,11 @@ fn find_supply_name_exact(dev: &Device, name: &str) -> Option<CString> {
2828
/// Finds supply name for the CPU from DT.
2929
fn find_supply_names(dev: &Device, cpu: cpu::CpuId) -> Option<KVec<CString>> {
3030
// Try "cpu0" for older DTs, fallback to "cpu".
31-
let name = (cpu.as_u32() == 0)
31+
(cpu.as_u32() == 0)
3232
.then(|| find_supply_name_exact(dev, "cpu0"))
3333
.flatten()
34-
.or_else(|| find_supply_name_exact(dev, "cpu"))?;
35-
36-
let mut list = KVec::with_capacity(1, GFP_KERNEL).ok()?;
37-
list.push(name, GFP_KERNEL).ok()?;
38-
39-
Some(list)
34+
.or_else(|| find_supply_name_exact(dev, "cpu"))
35+
.and_then(|name| kernel::kvec![name].ok())
4036
}
4137

4238
/// Represents the cpufreq dt device.

0 commit comments

Comments
 (0)