[PATCH] clk: renesas: Pack reset identifier before look up

Marek Vasut marek.vasut+renesas at mailbox.org
Sun Mar 19 17:58:50 CET 2023


The reset identifier must be processed via MOD_CLK_PACK() before it is
used to look up register and bit within reset_regs or reset_clear_regs
arrays, otherwise completely bogus register and bit is picked from the
arrays, one which may even be out of range.

Fixes: 326e05c5e21 ("clk: renesas: Add and enable CPG reset driver")
Signed-off-by: Marek Vasut <marek.vasut+renesas at mailbox.org>
---
 drivers/clk/renesas/clk-rcar-gen3.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/renesas/clk-rcar-gen3.c b/drivers/clk/renesas/clk-rcar-gen3.c
index d778db6569d..c121d82de7e 100644
--- a/drivers/clk/renesas/clk-rcar-gen3.c
+++ b/drivers/clk/renesas/clk-rcar-gen3.c
@@ -479,8 +479,9 @@ static int gen3_reset_assert(struct reset_ctl *reset_ctl)
 {
 	struct udevice *cdev = (struct udevice *)dev_get_driver_data(reset_ctl->dev);
 	struct gen3_clk_priv *priv = dev_get_priv(cdev);
-	unsigned int reg = reset_ctl->id / 32;
-	unsigned int bit = reset_ctl->id % 32;
+	unsigned int packed_id = MOD_CLK_PACK(reset_ctl->id);
+	unsigned int reg = packed_id / 32;
+	unsigned int bit = packed_id % 32;
 	u32 bitmask = BIT(bit);
 
 	writel(bitmask, priv->base + priv->info->reset_regs[reg]);
@@ -492,8 +493,9 @@ static int gen3_reset_deassert(struct reset_ctl *reset_ctl)
 {
 	struct udevice *cdev = (struct udevice *)dev_get_driver_data(reset_ctl->dev);
 	struct gen3_clk_priv *priv = dev_get_priv(cdev);
-	unsigned int reg = reset_ctl->id / 32;
-	unsigned int bit = reset_ctl->id % 32;
+	unsigned int packed_id = MOD_CLK_PACK(reset_ctl->id);
+	unsigned int reg = packed_id / 32;
+	unsigned int bit = packed_id % 32;
 	u32 bitmask = BIT(bit);
 
 	writel(bitmask, priv->base + priv->info->reset_clear_regs[reg]);
-- 
2.39.2



More information about the U-Boot mailing list