Skip to contentSkip to conversation

clk: imx: off by one in imx_lpcg_parse_clks_from_dt()

PATCH Applied Dan Carpenter 2 participants 3 messages Feb 28, 2022

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

PATCH 1/1 clk: imx: off by one in imx_lpcg_parse_clks_from_dt()

The > needs to be >= to prevent an off by one access.

Fixes d5f1e6a2bb61 ("clk: imx: imx8qxp-lpcg: add parsing clocks from device tree")
---
 drivers/clk/imx/clk-imx8qxp-lpcg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/imx/clk-imx8qxp-lpcg.c +1 -1
index b23758083ce5..5e31a6a24b3a 100644
@@ -248,7 +248,7 @@ static int imx_lpcg_parse_clks_from_dt(struct platform_device *pdev,
 
 	for (i = 0; i < count; i++) {
 		idx = bit_offset[i] / 4;
-		if (idx > IMX_LPCG_MAX_CLKS) {
+		if (idx >= IMX_LPCG_MAX_CLKS) {
 			dev_warn(&pdev->dev, "invalid bit offset of clock %d\n",
 				 i);
 			ret = -EINVAL;
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Dan Carpenter

The > needs to be >= to prevent an off by one access.

Fixes d5f1e6a2bb61 ("clk: imx: imx8qxp-lpcg: add parsing clocks from device tree")

Makes sense.

Quoted 20 lines
---
 drivers/clk/imx/clk-imx8qxp-lpcg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/imx/clk-imx8qxp-lpcg.c +1 -1
index b23758083ce5..5e31a6a24b3a 100644
@@ -248,7 +248,7 @@ static int imx_lpcg_parse_clks_from_dt(struct platform_device *pdev,
 
 	for (i = 0; i < count; i++) {
 		idx = bit_offset[i] / 4;
-		if (idx > IMX_LPCG_MAX_CLKS) {
+		if (idx >= IMX_LPCG_MAX_CLKS) {
 			dev_warn(&pdev->dev, "invalid bit offset of clock %d\n",
 				 i);
 			ret = -EINVAL;
Signature · 1 line
2.20.1
Applied
#2 lore raw
In reply to Dan Carpenter
Quoted 5 lines · Dan Carpenter

The > needs to be >= to prevent an off by one access.

Fixes d5f1e6a2bb61 ("clk: imx: imx8qxp-lpcg: add parsing clocks from device tree")

Applied, thanks!

Quoted 20 lines
---
 drivers/clk/imx/clk-imx8qxp-lpcg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/imx/clk-imx8qxp-lpcg.c +1 -1
index b23758083ce5..5e31a6a24b3a 100644
@@ -248,7 +248,7 @@ static int imx_lpcg_parse_clks_from_dt(struct platform_device *pdev,
 
 	for (i = 0; i < count; i++) {
 		idx = bit_offset[i] / 4;
-		if (idx > IMX_LPCG_MAX_CLKS) {
+		if (idx >= IMX_LPCG_MAX_CLKS) {
 			dev_warn(&pdev->dev, "invalid bit offset of clock %d\n",
 				 i);
 			ret = -EINVAL;
Signature · 1 line
2.20.1