]> git.hungrycats.org Git - linux/commitdiff
clk: bcm: rpi: Fix off by one in raspberrypi_discover_clocks()
authorDan Carpenter <dan.carpenter@linaro.org>
Fri, 21 Apr 2023 10:41:01 +0000 (13:41 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 11 Jul 2023 17:39:42 +0000 (19:39 +0200)
[ Upstream commit da2edb3e3c09fd1451b7f400ccd1070ef086619a ]

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>
Link: https://lore.kernel.org/r/5a850b08-d2f5-4794-aceb-a6b468965139@kili.mountain
Reviewed-by: Stefan Wahren <stefan.wahren@i2se.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/clk/bcm/clk-raspberrypi.c

index ce2f9347973697eaaa7a672633e987f4f3fc4cfa..5df19f571a474e02e1339566f04376b209471363 100644 (file)
@@ -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;
                }