diff mbox series

[v2] clk: bcm: rpi: Fix off by one in raspberrypi_discover_clocks()

Message ID 5a850b08-d2f5-4794-aceb-a6b468965139@kili.mountain (mailing list archive)
State Accepted, archived
Headers show
Series [v2] clk: bcm: rpi: Fix off by one in raspberrypi_discover_clocks() | expand

Commit Message

Dan Carpenter April 21, 2023, 10:41 a.m. UTC
Smatch detected an off by one in this code:
    drivers/clk/bcm/clk-raspberrypi.c:374 raspberrypi_discover_clocks()
    error: buffer overflow 'data->hws' 16 <= 16

The data->hws[] array has RPI_FIRMWARE_NUM_CLK_ID elements so the >
comparison needs to changed to >=.

Fixes: 12c90f3f27bb ("clk: bcm: rpi: Add variant structure")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
v2: Update the error message as well

 drivers/clk/bcm/clk-raspberrypi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Stefan Wahren April 21, 2023, 11:05 a.m. UTC | #1
Am 21.04.23 um 12:41 schrieb Dan Carpenter:
> Smatch detected an off by one in this code:
>      drivers/clk/bcm/clk-raspberrypi.c:374 raspberrypi_discover_clocks()
>      error: buffer overflow 'data->hws' 16 <= 16
> 
> The data->hws[] array has RPI_FIRMWARE_NUM_CLK_ID elements so the >
> comparison needs to changed to >=.
> 
> Fixes: 12c90f3f27bb ("clk: bcm: rpi: Add variant structure")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Reviewed-by: Stefan Wahren <stefan.wahren@i2se.com>
Florian Fainelli April 24, 2023, 10:36 p.m. UTC | #2
On 4/21/23 03:41, Dan Carpenter wrote:
> Smatch detected an off by one in this code:
>      drivers/clk/bcm/clk-raspberrypi.c:374 raspberrypi_discover_clocks()
>      error: buffer overflow 'data->hws' 16 <= 16
> 
> The data->hws[] array has RPI_FIRMWARE_NUM_CLK_ID elements so the >
> comparison needs to changed to >=.
> 
> Fixes: 12c90f3f27bb ("clk: bcm: rpi: Add variant structure")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
diff mbox series

Patch

diff --git a/drivers/clk/bcm/clk-raspberrypi.c b/drivers/clk/bcm/clk-raspberrypi.c
index eb399a4d141b..829406dc44a2 100644
--- a/drivers/clk/bcm/clk-raspberrypi.c
+++ b/drivers/clk/bcm/clk-raspberrypi.c
@@ -356,9 +356,9 @@  static int raspberrypi_discover_clocks(struct raspberrypi_clk *rpi,
 	while (clks->id) {
 		struct raspberrypi_clk_variant *variant;
 
-		if (clks->id > RPI_FIRMWARE_NUM_CLK_ID) {
+		if (clks->id >= RPI_FIRMWARE_NUM_CLK_ID) {
 			dev_err(rpi->dev, "Unknown clock id: %u (max: %u)\n",
-					   clks->id, RPI_FIRMWARE_NUM_CLK_ID);
+					   clks->id, RPI_FIRMWARE_NUM_CLK_ID - 1);
 			return -EINVAL;
 		}