Skip to contentSkip to conversation

hw/misc/bcm2835_cprman: Treat invalid clock mux source select as GND

PATCH Applied Peter Maydell 3 participants 4 messages Oct 19 – Oct 22

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/misc/bcm2835_cprman: Treat invalid clock mux source select as GND

The clock mux control registers in bcm2835_cprman have a 4 bit SRC field that selects the input clock source to use. There are only 10 valid SRC values. Treat the invalid values as producing no clock output, as if the GND clock source was used or the mux was disabled. This avoids reading off the end of the mux->srcs[] array.

Fixes fc9840850ba ("hw/misc/bcm2835_cprman: implement clock mux behaviour")

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4695

---
 hw/misc/bcm2835_cprman.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/misc/bcm2835_cprman.c +1 -1
index f9a77ff9bb0..10cad07623d 100644
@@ -271,7 +271,7 @@ static void clock_mux_update(CprmanClockMuxState *mux)
 
     *mux->reg_ctl = FIELD_DP32(*mux->reg_ctl, CM_CLOCKx_CTL, BUSY, enabled);
 
-    if (!enabled) {
+    if (!enabled || src >= ARRAY_SIZE(mux->srcs)) {
         clock_update(mux->out, 0);
         return;
     }
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Peter Maydell

The clock mux control registers in bcm2835_cprman have a 4 bit SRC field that selects the input clock source to use. There are only 10 valid SRC values. Treat the invalid values as producing no clock output, as if the GND clock source was used or the mux was disabled. This avoids reading off the end of the mux->srcs[] array.

Fixes fc9840850ba ("hw/misc/bcm2835_cprman: implement clock mux behaviour")

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4695

Quoted 17 lines
---
  hw/misc/bcm2835_cprman.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/misc/bcm2835_cprman.c +1 -1
index f9a77ff9bb0..10cad07623d 100644
@@ -271,7 +271,7 @@ static void clock_mux_update(CprmanClockMuxState *mux)
 
      *mux->reg_ctl = FIELD_DP32(*mux->reg_ctl, CM_CLOCKx_CTL, BUSY, enabled);
 
-    if (!enabled) {
+    if (!enabled || src >= ARRAY_SIZE(mux->srcs)) {
          clock_update(mux->out, 0);
          return;
      }
Reviewed-by on v1 1/1
#2 lore raw
In reply to Peter Maydell
Quoted 10 lines · Peter Maydell

The clock mux control registers in bcm2835_cprman have a 4 bit SRC field that selects the input clock source to use. There are only 10 valid SRC values. Treat the invalid values as producing no clock output, as if the GND clock source was used or the mux was disabled. This avoids reading off the end of the mux->srcs[] array.

Fixes fc9840850ba ("hw/misc/bcm2835_cprman: implement clock mux behaviour")

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4695

Quoted 21 lines
---
 hw/misc/bcm2835_cprman.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/misc/bcm2835_cprman.c +1 -1
index f9a77ff9bb0..10cad07623d 100644
@@ -271,7 +271,7 @@ static void clock_mux_update(CprmanClockMuxState *mux)
 
     *mux->reg_ctl = FIELD_DP32(*mux->reg_ctl, CM_CLOCKx_CTL, BUSY, enabled);
 
-    if (!enabled) {
+    if (!enabled || src >= ARRAY_SIZE(mux->srcs)) {
         clock_update(mux->out, 0);
         return;
     }
Signature · 1 line
2.43.0
author Applied
#3 lore raw
In reply to Peter Maydell
Quoted 7 lines · Peter Maydell

The clock mux control registers in bcm2835_cprman have a 4 bit SRC field that selects the input clock source to use. There are only 10 valid SRC values. Treat the invalid values as producing no clock output, as if the GND clock source was used or the mux was disabled. This avoids reading off the end of the mux->srcs[] array.

Quoted 8 lines
Fixes fc9840850ba ("hw/misc/bcm2835_cprman: implement clock mux behaviour")

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4695

---
 hw/misc/bcm2835_cprman.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to target-arm.next, thanks.

-- PMM