]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
rust: cpufreq: streamline find_supply_names
authorThorsten Blum <thorsten.blum@linux.dev>
Mon, 15 Sep 2025 13:59:54 +0000 (15:59 +0200)
committerViresh Kumar <viresh.kumar@linaro.org>
Mon, 29 Sep 2025 09:10:46 +0000 (14:40 +0530)
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>
drivers/cpufreq/rcpufreq_dt.rs

index 7e1fbf9a091f74065f9e14e7e9b5195213642452..224d063c7cec1714ce3d5526ae636c01ba5c4d06 100644 (file)
@@ -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.