Skip to content
Snippets Groups Projects
Commit 0a7edce0 authored by Stephen Warren's avatar Stephen Warren Committed by Simon Glass
Browse files

dm: timer: refuse timers with zero clock_rate


If a timer has a zero clock_rate, get_tbclk() will return zero for it,
which will cause tick_to_time() to perform a division-by-zero, which will
crash U-Boot.

Signed-off-by: default avatarStephen Warren <swarren@nvidia.com>
Acked-by: default avatarSimon Glass <sjg@chromium.org>
parent cf204528
No related branches found
No related tags found
No related merge requests found
...@@ -49,6 +49,16 @@ static int timer_pre_probe(struct udevice *dev) ...@@ -49,6 +49,16 @@ static int timer_pre_probe(struct udevice *dev)
return 0; return 0;
} }
static int timer_post_probe(struct udevice *dev)
{
struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
if (!uc_priv->clock_rate)
return -EINVAL;
return 0;
}
u64 timer_conv_64(u32 count) u64 timer_conv_64(u32 count)
{ {
/* increment tbh if tbl has rolled over */ /* increment tbh if tbl has rolled over */
...@@ -105,5 +115,6 @@ UCLASS_DRIVER(timer) = { ...@@ -105,5 +115,6 @@ UCLASS_DRIVER(timer) = {
.name = "timer", .name = "timer",
.pre_probe = timer_pre_probe, .pre_probe = timer_pre_probe,
.flags = DM_UC_FLAG_SEQ_ALIAS, .flags = DM_UC_FLAG_SEQ_ALIAS,
.post_probe = timer_post_probe,
.per_device_auto_alloc_size = sizeof(struct timer_dev_priv), .per_device_auto_alloc_size = sizeof(struct timer_dev_priv),
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment