* [rtc-linux] [bug report] rtc: add STM32 RTC driver
@ 2017-01-16 12:13 Dan Carpenter
2017-01-16 12:19 ` [rtc-linux] " Amelie DELAUNAY
2017-01-16 12:21 ` [rtc-linux] " Dan Carpenter
0 siblings, 2 replies; 5+ messages in thread
From: Dan Carpenter @ 2017-01-16 12:13 UTC (permalink / raw)
To: amelie.delaunay; +Cc: rtc-linux
Hello Amelie Delaunay,
The patch 4e64350f42e2: "rtc: add STM32 RTC driver" from Jan 11,
2017, leads to the following static checker warning:
drivers/rtc/rtc-stm32.c:514 stm32_rtc_init()
warn: always true condition '(pred_a >= 0) => (0-u32max >= 0)'
drivers/rtc/rtc-stm32.c
499 static int stm32_rtc_init(struct platform_device *pdev,
500 struct stm32_rtc *rtc)
501 {
502 unsigned int prer, pred_a, pred_s, pred_a_max, pred_s_max, cr;
503 unsigned int rate;
504 int ret = 0;
505
506 rate = clk_get_rate(rtc->ck_rtc);
507
508 /* Find prediv_a and prediv_s to obtain the 1Hz calendar clock */
509 pred_a_max = STM32_RTC_PRER_PRED_A >> STM32_RTC_PRER_PRED_A_SHIFT;
510 pred_s_max = STM32_RTC_PRER_PRED_S >> STM32_RTC_PRER_PRED_S_SHIFT;
511
512 for (pred_a = pred_a_max; pred_a >= 0; pred_a--) {
^^^^^^^^^^^
We should probably make pred_a, pred_s, pred_a_max and pred_s_max
signed.
513 pred_s = (rate / (pred_a + 1)) - 1;
514
515 if (((pred_s + 1) * (pred_a + 1)) == rate)
516 break;
517 }
518
regards,
dan carpenter
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [rtc-linux] RE: [bug report] rtc: add STM32 RTC driver
2017-01-16 12:13 [rtc-linux] [bug report] rtc: add STM32 RTC driver Dan Carpenter
@ 2017-01-16 12:19 ` Amelie DELAUNAY
2017-01-16 12:21 ` [rtc-linux] " Dan Carpenter
1 sibling, 0 replies; 5+ messages in thread
From: Amelie DELAUNAY @ 2017-01-16 12:19 UTC (permalink / raw)
To: Dan Carpenter; +Cc: rtc-linux
Hi Dan,
Thanks for reporting this issue.
I've already send a fix ("rtc: stm32: fix comparison warnings"): https://patchwork.kernel.org/patch/9518411/.
Regards,
Amelie
> -----Original Message-----
> From: Dan Carpenter [mailto:dan.carpenter@oracle.com]
> Sent: lundi 16 janvier 2017 13:14
> To: Amelie DELAUNAY <amelie.delaunay@st.com>
> Cc: rtc-linux@googlegroups.com
> Subject: [bug report] rtc: add STM32 RTC driver
>
> Hello Amelie Delaunay,
>
> The patch 4e64350f42e2: "rtc: add STM32 RTC driver" from Jan 11, 2017, leads
> to the following static checker warning:
>
> drivers/rtc/rtc-stm32.c:514 stm32_rtc_init()
> warn: always true condition '(pred_a >= 0) => (0-u32max >= 0)'
>
> drivers/rtc/rtc-stm32.c
> 499 static int stm32_rtc_init(struct platform_device *pdev,
> 500 struct stm32_rtc *rtc)
> 501 {
> 502 unsigned int prer, pred_a, pred_s, pred_a_max, pred_s_max, cr;
> 503 unsigned int rate;
> 504 int ret = 0;
> 505
> 506 rate = clk_get_rate(rtc->ck_rtc);
> 507
> 508 /* Find prediv_a and prediv_s to obtain the 1Hz calendar clock */
> 509 pred_a_max = STM32_RTC_PRER_PRED_A >>
> STM32_RTC_PRER_PRED_A_SHIFT;
> 510 pred_s_max = STM32_RTC_PRER_PRED_S >>
> STM32_RTC_PRER_PRED_S_SHIFT;
> 511
> 512 for (pred_a = pred_a_max; pred_a >= 0; pred_a--) {
> ^^^^^^^^^^^ We should probably make pred_a,
> pred_s, pred_a_max and pred_s_max signed.
>
> 513 pred_s = (rate / (pred_a + 1)) - 1;
> 514
> 515 if (((pred_s + 1) * (pred_a + 1)) == rate)
> 516 break;
> 517 }
> 518
>
> regards,
> dan carpenter
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [rtc-linux] Re: [bug report] rtc: add STM32 RTC driver
2017-01-16 12:13 [rtc-linux] [bug report] rtc: add STM32 RTC driver Dan Carpenter
2017-01-16 12:19 ` [rtc-linux] " Amelie DELAUNAY
@ 2017-01-16 12:21 ` Dan Carpenter
2017-01-16 12:26 ` Amelie DELAUNAY
1 sibling, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2017-01-16 12:21 UTC (permalink / raw)
To: amelie.delaunay; +Cc: rtc-linux
Oh. That still won't fix this:
drivers/rtc/rtc-stm32.c
519 /*
520 * Can't find a 1Hz, so give priority to RTC power consumption
521 * by choosing the higher possible value for prediv_a
522 */
523 if ((pred_s > pred_s_max) || (pred_a > pred_a_max)) {
524 pred_a = pred_a_max;
525 pred_s = (rate / (pred_a + 1)) - 1;
526
527 dev_warn(&pdev->dev, "ck_rtc is %s\n",
528 (rate - ((pred_a + 1) * (pred_s + 1)) < 0) ?
This is type promoted to unsigned int < 0.
529 "fast" : "slow");
530 }
regards,
dan carpenter
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [rtc-linux] Re: [bug report] rtc: add STM32 RTC driver
2017-01-16 12:21 ` [rtc-linux] " Dan Carpenter
@ 2017-01-16 12:26 ` Amelie DELAUNAY
2017-01-16 12:29 ` Dan Carpenter
0 siblings, 1 reply; 5+ messages in thread
From: Amelie DELAUNAY @ 2017-01-16 12:26 UTC (permalink / raw)
To: Dan Carpenter; +Cc: rtc-linux
I've changed the comparison:
@@ -525,7 +525,7 @@ static int stm32_rtc_init(struct platform_device *pdev,
pred_s = (rate / (pred_a + 1)) - 1;
dev_warn(&pdev->dev, "ck_rtc is %s\n",
- (rate - ((pred_a + 1) * (pred_s + 1)) < 0) ?
+ (rate < ((pred_a + 1) * (pred_s + 1))) ?
"fast" : "slow");
}
Now, rate (unsigned) is compared to ((pred_a + 1) * (pred_s + 1))
(unsigned), so no further "unsigned expression < 0 is always false".
Regards,
Amelie
On 01/16/2017 01:21 PM, Dan Carpenter wrote:
> Oh. That still won't fix this:
>
> drivers/rtc/rtc-stm32.c
> 519 /*
> 520 * Can't find a 1Hz, so give priority to RTC power consumption
> 521 * by choosing the higher possible value for prediv_a
> 522 */
> 523 if ((pred_s > pred_s_max) || (pred_a > pred_a_max)) {
> 524 pred_a = pred_a_max;
> 525 pred_s = (rate / (pred_a + 1)) - 1;
> 526
> 527 dev_warn(&pdev->dev, "ck_rtc is %s\n",
> 528 (rate - ((pred_a + 1) * (pred_s + 1)) < 0) ?
>
> This is type promoted to unsigned int < 0.
>
> 529 "fast" : "slow");
> 530 }
>
> regards,
> dan carpenter
>
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-01-16 12:29 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-16 12:13 [rtc-linux] [bug report] rtc: add STM32 RTC driver Dan Carpenter
2017-01-16 12:19 ` [rtc-linux] " Amelie DELAUNAY
2017-01-16 12:21 ` [rtc-linux] " Dan Carpenter
2017-01-16 12:26 ` Amelie DELAUNAY
2017-01-16 12:29 ` Dan Carpenter
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.