https://github.com/raspberrypi/firmware/issues/1688

From 758f9f6453ef4792c1d72c258c5fc0e1e2ac5faf Mon Sep 17 00:00:00 2001
From: Phil Elwell <phil@raspberrypi.com>
Date: Mon, 24 Jan 2022 14:53:13 +0000
Subject: [PATCH] clk: bcm: rpi: Don't exceed end of firmware clocks

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
---
 drivers/clk/bcm/clk-raspberrypi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/bcm/clk-raspberrypi.c b/drivers/clk/bcm/clk-raspberrypi.c
index 99cc4c856de1..fc89d083ffe1 100644
--- a/drivers/clk/bcm/clk-raspberrypi.c
+++ b/drivers/clk/bcm/clk-raspberrypi.c
@@ -250,7 +250,7 @@ struct rpi_firmware_get_clocks_response {
 static int raspberrypi_discover_clocks(struct raspberrypi_clk *rpi,
 				       struct clk_hw_onecell_data *data)
 {
-	struct rpi_firmware_get_clocks_response *clks;
+	struct rpi_firmware_get_clocks_response *clks, *clks_end;
 	int ret;
 
 	clks = devm_kcalloc(rpi->dev,
@@ -265,7 +265,8 @@ static int raspberrypi_discover_clocks(struct raspberrypi_clk *rpi,
 	if (ret)
 		return ret;
 
-	while (clks->id) {
+	clks_end = clks + RPI_FIRMWARE_NUM_CLK_ID;
+	while (clks < clks_end) {
 		struct clk_hw *hw;
 
 		switch (clks->id) {
-- 
2.25.1


