All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/3] dm: timer: refuse timers with zero clock_rate
@ 2016-01-06 17:33 Stephen Warren
  2016-01-06 17:33 ` [U-Boot] [PATCH 2/3] timer: sandbox: work without device tree Stephen Warren
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Stephen Warren @ 2016-01-06 17:33 UTC (permalink / raw)
  To: u-boot

From: Stephen Warren <swarren@nvidia.com>

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>
---
 drivers/timer/timer-uclass.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/timer/timer-uclass.c b/drivers/timer/timer-uclass.c
index aca421bdea33..0771562c600d 100644
--- a/drivers/timer/timer-uclass.c
+++ b/drivers/timer/timer-uclass.c
@@ -47,6 +47,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 */
@@ -60,5 +70,6 @@ UCLASS_DRIVER(timer) = {
 	.id		= UCLASS_TIMER,
 	.name		= "timer",
 	.pre_probe	= timer_pre_probe,
+	.post_probe	= timer_post_probe,
 	.per_device_auto_alloc_size = sizeof(struct timer_dev_priv),
 };
-- 
2.6.4

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2016-01-21  2:16 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-06 17:33 [U-Boot] [PATCH 1/3] dm: timer: refuse timers with zero clock_rate Stephen Warren
2016-01-06 17:33 ` [U-Boot] [PATCH 2/3] timer: sandbox: work without device tree Stephen Warren
2016-01-07  5:31   ` Bin Meng
2016-01-11 16:58   ` Simon Glass
2016-01-16  1:26     ` Simon Glass
2016-01-06 17:33 ` [U-Boot] [PATCH 3/3] test/py: add a test for the sleep command Stephen Warren
2016-01-11 15:23   ` Simon Glass
2016-01-15 18:24   ` Stephen Warren
2016-01-21  2:16     ` Simon Glass
2016-01-07  5:29 ` [U-Boot] [PATCH 1/3] dm: timer: refuse timers with zero clock_rate Bin Meng
2016-01-11 16:48   ` Stephen Warren
2016-01-11 16:56   ` Simon Glass
2016-01-16  1:26     ` Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.