Skip to content

Commit c5601e0

Browse files
Dan Carpenterbebarino
authored andcommitted
clk: visconti: prevent array overflow in visconti_clk_register_gates()
This code was using -1 to represent that there was no reset function. Unfortunately, the -1 was stored in u8 so the if (clks[i].rs_id >= 0) condition was always true. This lead to an out of bounds access in visconti_clk_register_gates(). Fixes: b4cbe60 ("clk: visconti: Add support common clock driver and reset driver") Signed-off-by: Dan Carpenter <[email protected]> Link: https://lore.kernel.org/r/20220316083533.GA30941@kili Acked-by: Nobuhiro Iwamatsu <[email protected]> Signed-off-by: Stephen Boyd <[email protected]>
1 parent e783362 commit c5601e0

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

drivers/clk/visconti/clkc-tmpv770x.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static const struct visconti_clk_gate_table clk_gate_tables[] = {
176176
{ TMPV770X_CLK_WRCK, "wrck",
177177
clks_parent_data, ARRAY_SIZE(clks_parent_data),
178178
0, 0x68, 0x168, 9, 32,
179-
-1, }, /* No reset */
179+
NO_RESET, },
180180
{ TMPV770X_CLK_PICKMON, "pickmon",
181181
clks_parent_data, ARRAY_SIZE(clks_parent_data),
182182
0, 0x10, 0x110, 8, 4,

drivers/clk/visconti/clkc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ int visconti_clk_register_gates(struct visconti_clk_provider *ctx,
147147
if (!dev_name)
148148
return -ENOMEM;
149149

150-
if (clks[i].rs_id >= 0) {
150+
if (clks[i].rs_id != NO_RESET) {
151151
rson_offset = reset[clks[i].rs_id].rson_offset;
152152
rsoff_offset = reset[clks[i].rs_id].rsoff_offset;
153153
rs_idx = reset[clks[i].rs_id].rs_idx;

drivers/clk/visconti/clkc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,7 @@ int visconti_clk_register_gates(struct visconti_clk_provider *data,
7373
int num_gate,
7474
const struct visconti_reset_data *reset,
7575
spinlock_t *lock);
76+
77+
#define NO_RESET 0xFF
78+
7679
#endif /* _VISCONTI_CLKC_H_ */

0 commit comments

Comments
 (0)