From 42f5ce2074efc7d7ae6fe15872e0f489c1fd97f9 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sat, 18 Mar 2023 12:30:53 +0100 Subject: [PATCH] clk: renesas: Pack reset identifier before look up 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: 97c9d810b50 ("clk: renesas: Add and enable CPG reset driver") Signed-off-by: Marek Vasut --- 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 d778db6569..c121d82de7 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.5