]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
drivers/perf: riscv: Return error for default case
authorAtish Patra <atishp@rivosinc.com>
Fri, 13 Dec 2024 00:09:33 +0000 (16:09 -0800)
committerPalmer Dabbelt <palmer@rivosinc.com>
Thu, 9 Jan 2025 17:37:09 +0000 (09:37 -0800)
If the upper two bits has an invalid valid (0x1), the event mapping
is not reliable as it returns an uninitialized variable.

Return appropriate value for the default case.

Fixes: f0c9363db2dd ("perf/riscv-sbi: Add platform specific firmware event handling")
Signed-off-by: Atish Patra <atishp@rivosinc.com>
Link: https://lore.kernel.org/r/20241212-pmu_event_fixes_v2-v2-2-813e8a4f5962@rivosinc.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
drivers/perf/riscv_pmu_sbi.c

index 3473ba02abf3cb578ef0f6fe1f564c69080ffdad..da3651d329069c18f54ef4b1615ef908b59c956b 100644 (file)
@@ -507,7 +507,7 @@ static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig)
 {
        u32 type = event->attr.type;
        u64 config = event->attr.config;
-       int ret;
+       int ret = -ENOENT;
 
        /*
         * Ensure we are finished checking standard hardware events for
@@ -551,10 +551,11 @@ static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig)
                        ret = SBI_PMU_EVENT_TYPE_FW << 16 | RISCV_PLAT_FW_EVENT;
                        *econfig = config & RISCV_PMU_PLAT_FW_EVENT_MASK;
                        break;
+               default:
+                       break;
                }
                break;
        default:
-               ret = -ENOENT;
                break;
        }