[PATCH] hw/timer/mss_timer: Remove dead code in timer_write()

Peter Maydell posted 1 patch 2 weeks, 4 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260512134750.3543639-1-peter.maydell@linaro.org
Maintainers: Subbaraya Sundeep <sundeep.lkml@gmail.com>, Peter Maydell <peter.maydell@linaro.org>
hw/timer/mss-timer.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
[PATCH] hw/timer/mss_timer: Remove dead code in timer_write()
Posted by Peter Maydell 2 weeks, 4 days ago
In timer_write(), we switch() on the address offset to handle
registers that need special-casing, with a default case that handles
both "unsupported (64-bit mode) register" and "can just write value
to st->regs[]".  However, as Coverity points out, every register is
covered by the special-casing, so the "write to st->regs[]" code path
is dead.  (timer_read() has a similar structure but there several
registers do go through the default code path.)

Replace the dead code with an assertion.

CID: 1613905
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/timer/mss-timer.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/hw/timer/mss-timer.c b/hw/timer/mss-timer.c
index bd3f3e845f..25fcf42aa0 100644
--- a/hw/timer/mss-timer.c
+++ b/hw/timer/mss-timer.c
@@ -189,14 +189,11 @@ timer_write(void *opaque, hwaddr offset,
         break;
 
     default:
-        if (addr < R_TIM1_MAX) {
-            st->regs[addr] = value;
-        } else {
-            qemu_log_mask(LOG_GUEST_ERROR,
-                        TYPE_MSS_TIMER": 64-bit mode not supported\n");
-            return;
-        }
-        break;
+        /* All non-64-bit regs covered by the switch cases */
+        assert(addr >= R_TIM1_MAX);
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      TYPE_MSS_TIMER": 64-bit mode not supported\n");
+        return;
     }
     timer_update_irq(st);
 }
-- 
2.43.0
Re: [PATCH] hw/timer/mss_timer: Remove dead code in timer_write()
Posted by Richard Henderson 1 week, 6 days ago
On 5/12/26 06:47, Peter Maydell wrote:
> In timer_write(), we switch() on the address offset to handle
> registers that need special-casing, with a default case that handles
> both "unsupported (64-bit mode) register" and "can just write value
> to st->regs[]".  However, as Coverity points out, every register is
> covered by the special-casing, so the "write to st->regs[]" code path
> is dead.  (timer_read() has a similar structure but there several
> registers do go through the default code path.)
> 
> Replace the dead code with an assertion.
> 
> CID: 1613905
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
>   hw/timer/mss-timer.c | 13 +++++--------
>   1 file changed, 5 insertions(+), 8 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~