]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
hpet: fix clamping of period
authorPaolo Bonzini <pbonzini@redhat.com>
Wed, 10 Jul 2024 09:56:35 +0000 (11:56 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 16 Jul 2024 16:18:24 +0000 (18:18 +0200)
When writing a new period, the clamping should use a maximum value
rather tyhan a bit mask.  Also, when writing the high bits new_val
is shifted right by 32, so the maximum allowed period should also
be shifted right.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
hw/timer/hpet.c

index 01efe4885db478fddcd562333256ece1a1dfad6f..ad881448bf3b25439e2a0f052193c136d7441026 100644 (file)
@@ -548,7 +548,9 @@ static void hpet_ram_write(void *opaque, hwaddr addr,
                  * FIXME: Clamp period to reasonable min value?
                  * Clamp period to reasonable max value
                  */
-                new_val &= (timer->config & HPET_TN_32BIT ? ~0u : ~0ull) >> 1;
+                if (timer->config & HPET_TN_32BIT) {
+                    new_val = MIN(new_val, ~0u >> 1);
+                }
                 timer->period =
                     (timer->period & 0xffffffff00000000ULL) | new_val;
             }
@@ -567,7 +569,7 @@ static void hpet_ram_write(void *opaque, hwaddr addr,
                  * FIXME: Clamp period to reasonable min value?
                  * Clamp period to reasonable max value
                  */
-                new_val &= (timer->config & HPET_TN_32BIT ? ~0u : ~0ull) >> 1;
+                new_val = MIN(new_val, ~0u >> 1);
                 timer->period =
                     (timer->period & 0xffffffffULL) | new_val << 32;
                 }