From 2d66436185df293ca3832c2e326067892e0fcebc Mon Sep 17 00:00:00 2001 From: guanyi3 Date: Fri, 13 Mar 2026 16:41:23 +0800 Subject: [PATCH] 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 --- drivers/devfreq/devfreq_procfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/devfreq/devfreq_procfs.c b/drivers/devfreq/devfreq_procfs.c index 99f92d50ac2..d97b2f3deb1 100644 --- a/drivers/devfreq/devfreq_procfs.c +++ b/drivers/devfreq/devfreq_procfs.c @@ -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"); }