Skip to content

Commit 2c81f0f

Browse files
committed
bus: ti-sysc: Fix iterating over clocks
Commit d878970 ("bus: ti-sysc: Add separate functions for handling clocks") separated handling of optional clocks from the main clocks, but introduced an issue where we do not necessarily allocate a slot for both fck and ick clocks, but still assume fixed slots for enumerating over the clocks. Let's fix the issue by ensuring we always have slots for both fck and ick even if we don't use ick, and don't attempt to enumerate optional clocks if not allocated. In the long run we might want to simplify things a bit by only allocating space only for the optional clocks as we have only few devices with optional clocks. Fixes: d878970 ("bus: ti-sysc: Add separate functions for handling clocks") Signed-off-by: Tony Lindgren <tony@atomide.com>
1 parent 90bdfa0 commit 2c81f0f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

drivers/bus/ti-sysc.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,12 @@ static int sysc_get_clocks(struct sysc *ddata)
343343
return -EINVAL;
344344
}
345345

346+
/* Always add a slot for main clocks fck and ick even if unused */
347+
if (!nr_fck)
348+
ddata->nr_clocks++;
349+
if (!nr_ick)
350+
ddata->nr_clocks++;
351+
346352
ddata->clocks = devm_kcalloc(ddata->dev,
347353
ddata->nr_clocks, sizeof(*ddata->clocks),
348354
GFP_KERNEL);
@@ -421,7 +427,7 @@ static int sysc_enable_opt_clocks(struct sysc *ddata)
421427
struct clk *clock;
422428
int i, error;
423429

424-
if (!ddata->clocks)
430+
if (!ddata->clocks || ddata->nr_clocks < SYSC_OPTFCK0 + 1)
425431
return 0;
426432

427433
for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {
@@ -455,7 +461,7 @@ static void sysc_disable_opt_clocks(struct sysc *ddata)
455461
struct clk *clock;
456462
int i;
457463

458-
if (!ddata->clocks)
464+
if (!ddata->clocks || ddata->nr_clocks < SYSC_OPTFCK0 + 1)
459465
return;
460466

461467
for (i = SYSC_OPTFCK0; i < SYSC_MAX_CLOCKS; i++) {

0 commit comments

Comments
 (0)