From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Warren Date: Mon, 11 Jan 2016 09:48:50 -0700 Subject: [U-Boot] [PATCH 1/3] dm: timer: refuse timers with zero clock_rate In-Reply-To: References: <1452101585-25933-1-git-send-email-swarren@wwwdotorg.org> Message-ID: <5693DCF2.20701@wwwdotorg.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 01/06/2016 10:29 PM, Bin Meng wrote: > On Thu, Jan 7, 2016 at 1:33 AM, Stephen Warren wrote: >> From: Stephen Warren >> >> 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 >> --- >> 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; > > Should we just panic here? That would prevent the system operating correctly if multiple timers happened to be registered and the other one didn't have this issue. Still, it does seem reasonable to highlight this error. Simon, what do you think here?