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

Peter Maydell posted 1 patch 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20261019161900.3271815-1-peter.maydell@linaro.org
Maintainers: Peter Maydell <peter.maydell@linaro.org>, "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>
hw/misc/bcm2835_cprman.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] hw/misc/bcm2835_cprman: Treat invalid clock mux source select as GND
Posted by Peter Maydell 1 month ago
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.

Cc: qemu-stable@nongnu.org
Fixes: fc9840850ba ("hw/misc/bcm2835_cprman: implement clock mux behaviour")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4695
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/misc/bcm2835_cprman.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
index f9a77ff9bb0..10cad07623d 100644
--- a/hw/misc/bcm2835_cprman.c
+++ b/hw/misc/bcm2835_cprman.c
@@ -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;
     }
-- 
2.43.0
Re: [PATCH] hw/misc/bcm2835_cprman: Treat invalid clock mux source select as GND
Posted by Peter Maydell 1 month ago
On Mon, 19 Oct 2026 at 17:19, Peter Maydell <peter.maydell@linaro.org> wrote:
>
> 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.
>
> Cc: qemu-stable@nongnu.org
> Fixes: fc9840850ba ("hw/misc/bcm2835_cprman: implement clock mux behaviour")
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4695
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  hw/misc/bcm2835_cprman.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>



Applied to target-arm.next, thanks.

-- PMM
Re: [PATCH] hw/misc/bcm2835_cprman: Treat invalid clock mux source select as GND
Posted by Luc Michel 1 month ago
On 17:19 Mon 19 Oct     , Peter Maydell wrote:
> 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.
> 
> Cc: qemu-stable@nongnu.org
> Fixes: fc9840850ba ("hw/misc/bcm2835_cprman: implement clock mux behaviour")
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4695
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Reviewed-by: Luc Michel <luc@lmichel.fr>

> ---
>  hw/misc/bcm2835_cprman.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
> index f9a77ff9bb0..10cad07623d 100644
> --- a/hw/misc/bcm2835_cprman.c
> +++ b/hw/misc/bcm2835_cprman.c
> @@ -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;
>      }
> -- 
> 2.43.0
> 
> 

--
Re: [PATCH] hw/misc/bcm2835_cprman: Treat invalid clock mux source select as GND
Posted by Philippe Mathieu-Daudé 1 month ago
On 19/10/26 18:19, Peter Maydell wrote:
> 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.
> 
> Cc: qemu-stable@nongnu.org
> Fixes: fc9840850ba ("hw/misc/bcm2835_cprman: implement clock mux behaviour")
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4695
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>

> ---
>   hw/misc/bcm2835_cprman.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
> index f9a77ff9bb0..10cad07623d 100644
> --- a/hw/misc/bcm2835_cprman.c
> +++ b/hw/misc/bcm2835_cprman.c
> @@ -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;
>       }