drivers/devfreq: guard backtrace code with CONFIG_LIBC_BACKTRACE_DEPTH

When CONFIG_LIBC_BACKTRACE_DEPTH is not set or <= 0, backtrace_get()
is a macro that always sets depth to 0, making the for-loop body
unreachable (Coverity CID 8405332 DEADCODE).

Wrap backtrace_get() call, the loop, and related variable declarations
with #if CONFIG_LIBC_BACKTRACE_DEPTH > 0 to eliminate the dead code
and avoid unused variable warnings.

Signed-off-by: guanyi3 <guanyi3@xiaomi.com>
This commit is contained in:
guanyi3 2026-03-13 16:41:23 +08:00 committed by Alan C. Assis
parent 31041f84ea
commit 2d66436185

View file

@ -169,8 +169,10 @@ static ssize_t devfreq_read(FAR struct file *filep,
FAR struct devfreq_s *devfreq = devfreq_procfs->devfreq;
#ifdef CONFIG_DEVFREQ_PROCFS_QOS
FAR struct qos_request_s *qos;
void **stack;
#if defined(CONFIG_LIBC_BACKTRACE_BUFFSIZE) && CONFIG_LIBC_BACKTRACE_BUFFSIZE > 0
FAR void **stack;
int depth;
#endif
#endif
off_t offset = filep->f_pos;
size_t i;
@ -209,14 +211,16 @@ static ssize_t devfreq_read(FAR struct file *filep,
" qos_list(min, max, backtrace):\n");
plist_for_each_entry(qos, &devfreq->constraints.min_requests, min_req)
{
stack = backtrace_get(qos->backtrace, &depth);
procfs_sprintf(buffer, buflen, &offset,
" %"PRIu32", %"PRIu32",",
qos->min_req.prio, qos->max_req.prio);
#if defined(CONFIG_LIBC_BACKTRACE_BUFFSIZE) && CONFIG_LIBC_BACKTRACE_BUFFSIZE > 0
stack = backtrace_get(qos->backtrace, &depth);
for (i = 0; i < depth; i++)
{
procfs_sprintf(buffer, buflen, &offset, " %p", stack[i]);
}
#endif
procfs_sprintf(buffer, buflen, &offset, "\n");
}