]> git.sur5r.net Git - u-boot/commitdiff
dm: timer: refuse timers with zero clock_rate
authorStephen Warren <swarren@nvidia.com>
Wed, 6 Jan 2016 17:33:03 +0000 (10:33 -0700)
committerSimon Glass <sjg@chromium.org>
Thu, 21 Jan 2016 02:06:23 +0000 (19:06 -0700)
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: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>
drivers/timer/timer-uclass.c

index b1f4868416fbcff52fddb9f85bfbb1a83903f7e9..83d1a35e0622afc325fcc250a91d5aec52c20eb9 100644 (file)
@@ -49,6 +49,16 @@ static int timer_pre_probe(struct udevice *dev)
        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)
 {
        /* increment tbh if tbl has rolled over */
@@ -105,5 +115,6 @@ UCLASS_DRIVER(timer) = {
        .name           = "timer",
        .pre_probe      = timer_pre_probe,
        .flags          = DM_UC_FLAG_SEQ_ALIAS,
+       .post_probe     = timer_post_probe,
        .per_device_auto_alloc_size = sizeof(struct timer_dev_priv),
 };