Skip to contentSkip to conversation

drivers/perf/riscv_ctr.c:435 riscv_pmu_ctr_sched_task() warn: variable dereferenced before check 'pmu_ctx' (see line 427)

PATCH kernel test robot 1 participant 1 message Nov 22

lore
Share & tools
lore

kernel test robot

author build bot
#0 lore raw

Unfiltered warning: this smatch report is sent as-is and has not been reviewed for false positives, so please treat it with due skepticism.

BCC: [email protected]
CC: [email protected]
TO: Vikram Singh <[email protected]>
CC: Anup Patel <[email protected]>
CC: Rajnesh Kanwal <[email protected]>

tree:   https://github.com/avpatel/linux.git riscv_sbi_watchdog_v3
head:   e16e3a60fbbf3fa3da230a7151235d2e7aac1066
commit: 9a740a6a4e590a1cc20dc8aa7d80a73171ba6229 [118/122] riscv: pmu: Add driver for Control Transfer Records Ext

:::::: branch date: 4 hours ago
:::::: commit date: 4 hours ago
config: riscv-randconfig-2200-20261122 (https://download.01.org/0day-ci/archive/20261122/[email protected]/config)
compiler: riscv64-linux-gcc (GCC) 8.5.0
smatch: v0.5.0-9187-g5189e3fb

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

smatch warnings:
drivers/perf/riscv_ctr.c:435 riscv_pmu_ctr_sched_task() warn: variable dereferenced before check 'pmu_ctx' (see line 427)

vim +/pmu_ctx +435 drivers/perf/riscv_ctr.c

9a740a6a4e590a Vikram Singh 2026-11-18  416  
9a740a6a4e590a Vikram Singh 2026-11-18  417  /*
9a740a6a4e590a Vikram Singh 2026-11-18  418   * On context switch in, we need to make sure no samples from previous tasks
9a740a6a4e590a Vikram Singh 2026-11-18  419   * are left in the CTR.
9a740a6a4e590a Vikram Singh 2026-11-18  420   *
9a740a6a4e590a Vikram Singh 2026-11-18  421   * On ctxswin, sched_in = true, called after the PMU has started
9a740a6a4e590a Vikram Singh 2026-11-18  422   * On ctxswout, sched_in = false, called before the PMU is stopped
9a740a6a4e590a Vikram Singh 2026-11-18  423   */
9a740a6a4e590a Vikram Singh 2026-11-18  424  void riscv_pmu_ctr_sched_task(struct perf_event_pmu_context *pmu_ctx, struct task_struct *task,
9a740a6a4e590a Vikram Singh 2026-11-18  425  			      bool sched_in)
9a740a6a4e590a Vikram Singh 2026-11-18  426  {
9a740a6a4e590a Vikram Singh 2026-11-18 @427  	struct riscv_pmu *rvpmu = to_riscv_pmu(pmu_ctx->pmu);
9a740a6a4e590a Vikram Singh 2026-11-18  428  	struct cpu_hw_events *cpuc = this_cpu_ptr(rvpmu->hw_events);
9a740a6a4e590a Vikram Singh 2026-11-18  429  	void *task_ctx;
9a740a6a4e590a Vikram Singh 2026-11-18  430  
9a740a6a4e590a Vikram Singh 2026-11-18  431  	if (!cpuc->ctr_users)
9a740a6a4e590a Vikram Singh 2026-11-18  432  		return;
9a740a6a4e590a Vikram Singh 2026-11-18  433  
9a740a6a4e590a Vikram Singh 2026-11-18  434  	/* Save branch records in task_ctx on sched out */
9a740a6a4e590a Vikram Singh 2026-11-18 @435  	task_ctx = pmu_ctx ? task->perf_ctx_data : NULL;
9a740a6a4e590a Vikram Singh 2026-11-18  436  	if (task_ctx) {
9a740a6a4e590a Vikram Singh 2026-11-18  437  		if (sched_in)
9a740a6a4e590a Vikram Singh 2026-11-18  438  			riscv_pmu_ctr_restore(task_ctx);
9a740a6a4e590a Vikram Singh 2026-11-18  439  		else
9a740a6a4e590a Vikram Singh 2026-11-18  440  			riscv_pmu_ctr_save(task_ctx, rvpmu->ctr_depth);
9a740a6a4e590a Vikram Singh 2026-11-18  441  		return;
9a740a6a4e590a Vikram Singh 2026-11-18  442  	}
9a740a6a4e590a Vikram Singh 2026-11-18  443  
9a740a6a4e590a Vikram Singh 2026-11-18  444  	/* Reset branch records on sched in */
9a740a6a4e590a Vikram Singh 2026-11-18  445  	if (sched_in)
9a740a6a4e590a Vikram Singh 2026-11-18  446  		riscv_pmu_ctr_reset();
9a740a6a4e590a Vikram Singh 2026-11-18  447  }
9a740a6a4e590a Vikram Singh 2026-11-18  448  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki