All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rtc: ds1685: Remove superfluous checks for out-of-range u8 values
@ 2015-02-18 10:44 Geert Uytterhoeven
  2015-02-18 13:22 ` Joshua Kinard
  0 siblings, 1 reply; 2+ messages in thread
From: Geert Uytterhoeven @ 2015-02-18 10:44 UTC (permalink / raw)
  To: Joshua Kinard, Alessandro Zummo, Andrew Morton
  Cc: rtc-linux, linux-mips, linux-kernel, Geert Uytterhoeven

drivers/rtc/rtc-ds1685.c: In function ‘ds1685_rtc_read_alarm’:
drivers/rtc/rtc-ds1685.c:402: warning: comparison is always true due to limited range of data type
drivers/rtc/rtc-ds1685.c:409: warning: comparison is always true due to limited range of data type
drivers/rtc/rtc-ds1685.c:416: warning: comparison is always true due to limited range of data type
drivers/rtc/rtc-ds1685.c: In function ‘ds1685_rtc_set_alarm’:
drivers/rtc/rtc-ds1685.c:475: warning: comparison is always true due to limited range of data type
drivers/rtc/rtc-ds1685.c:478: warning: comparison is always true due to limited range of data type
drivers/rtc/rtc-ds1685.c:481: warning: comparison is always true due to limited range of data type

u8 cannot contain a value larger than 0xff, hence drop the checks.
Wrapping the checks in unlikely() indicated some sense of humor, though ;-)

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 drivers/rtc/rtc-ds1685.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/rtc/rtc-ds1685.c b/drivers/rtc/rtc-ds1685.c
index 8c3bfcb115b78731..5077078a9305b9d5 100644
--- a/drivers/rtc/rtc-ds1685.c
+++ b/drivers/rtc/rtc-ds1685.c
@@ -399,21 +399,21 @@ ds1685_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 	 * of this RTC chip.  We check for it anyways in case support is
 	 * added in the future.
 	 */
-	if (unlikely((seconds >= 0xc0) && (seconds <= 0xff)))
+	if (unlikely(seconds >= 0xc0))
 		alrm->time.tm_sec = -1;
 	else
 		alrm->time.tm_sec = ds1685_rtc_bcd2bin(rtc, seconds,
 						       RTC_SECS_BCD_MASK,
 						       RTC_SECS_BIN_MASK);
 
-	if (unlikely((minutes >= 0xc0) && (minutes <= 0xff)))
+	if (unlikely(minutes >= 0xc0))
 		alrm->time.tm_min = -1;
 	else
 		alrm->time.tm_min = ds1685_rtc_bcd2bin(rtc, minutes,
 						       RTC_MINS_BCD_MASK,
 						       RTC_MINS_BIN_MASK);
 
-	if (unlikely((hours >= 0xc0) && (hours <= 0xff)))
+	if (unlikely(hours >= 0xc0))
 		alrm->time.tm_hour = -1;
 	else
 		alrm->time.tm_hour = ds1685_rtc_bcd2bin(rtc, hours,
@@ -472,13 +472,13 @@ ds1685_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 	 * field, and we only support four fields.  We put the support
 	 * here anyways for the future.
 	 */
-	if (unlikely((seconds >= 0xc0) && (seconds <= 0xff)))
+	if (unlikely(seconds >= 0xc0))
 		seconds = 0xff;
 
-	if (unlikely((minutes >= 0xc0) && (minutes <= 0xff)))
+	if (unlikely(minutes >= 0xc0))
 		minutes = 0xff;
 
-	if (unlikely((hours >= 0xc0) && (hours <= 0xff)))
+	if (unlikely(hours >= 0xc0))
 		hours = 0xff;
 
 	alrm->time.tm_mon	= -1;
-- 
1.9.1


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

* Re: [PATCH] rtc: ds1685: Remove superfluous checks for out-of-range u8 values
  2015-02-18 10:44 [PATCH] rtc: ds1685: Remove superfluous checks for out-of-range u8 values Geert Uytterhoeven
@ 2015-02-18 13:22 ` Joshua Kinard
  0 siblings, 0 replies; 2+ messages in thread
From: Joshua Kinard @ 2015-02-18 13:22 UTC (permalink / raw)
  To: Geert Uytterhoeven, Alessandro Zummo, Andrew Morton
  Cc: rtc-linux, linux-mips, linux-kernel

On 02/18/2015 05:44, Geert Uytterhoeven wrote:
> drivers/rtc/rtc-ds1685.c: In function ‘ds1685_rtc_read_alarm’:
> drivers/rtc/rtc-ds1685.c:402: warning: comparison is always true due to limited range of data type
> drivers/rtc/rtc-ds1685.c:409: warning: comparison is always true due to limited range of data type
> drivers/rtc/rtc-ds1685.c:416: warning: comparison is always true due to limited range of data type
> drivers/rtc/rtc-ds1685.c: In function ‘ds1685_rtc_set_alarm’:
> drivers/rtc/rtc-ds1685.c:475: warning: comparison is always true due to limited range of data type
> drivers/rtc/rtc-ds1685.c:478: warning: comparison is always true due to limited range of data type
> drivers/rtc/rtc-ds1685.c:481: warning: comparison is always true due to limited range of data type
> 
> u8 cannot contain a value larger than 0xff, hence drop the checks.
> Wrapping the checks in unlikely() indicated some sense of humor, though ;-)
> 
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>

Actually, I think I was operating in -pedantic mode the night I added those
checks.  Good catch, thanks!

Acked-by: Joshua Kinard <kumba@gentoo.org>


> ---
>  drivers/rtc/rtc-ds1685.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-ds1685.c b/drivers/rtc/rtc-ds1685.c
> index 8c3bfcb115b78731..5077078a9305b9d5 100644
> --- a/drivers/rtc/rtc-ds1685.c
> +++ b/drivers/rtc/rtc-ds1685.c
> @@ -399,21 +399,21 @@ ds1685_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
>  	 * of this RTC chip.  We check for it anyways in case support is
>  	 * added in the future.
>  	 */
> -	if (unlikely((seconds >= 0xc0) && (seconds <= 0xff)))
> +	if (unlikely(seconds >= 0xc0))
>  		alrm->time.tm_sec = -1;
>  	else
>  		alrm->time.tm_sec = ds1685_rtc_bcd2bin(rtc, seconds,
>  						       RTC_SECS_BCD_MASK,
>  						       RTC_SECS_BIN_MASK);
>  
> -	if (unlikely((minutes >= 0xc0) && (minutes <= 0xff)))
> +	if (unlikely(minutes >= 0xc0))
>  		alrm->time.tm_min = -1;
>  	else
>  		alrm->time.tm_min = ds1685_rtc_bcd2bin(rtc, minutes,
>  						       RTC_MINS_BCD_MASK,
>  						       RTC_MINS_BIN_MASK);
>  
> -	if (unlikely((hours >= 0xc0) && (hours <= 0xff)))
> +	if (unlikely(hours >= 0xc0))
>  		alrm->time.tm_hour = -1;
>  	else
>  		alrm->time.tm_hour = ds1685_rtc_bcd2bin(rtc, hours,
> @@ -472,13 +472,13 @@ ds1685_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
>  	 * field, and we only support four fields.  We put the support
>  	 * here anyways for the future.
>  	 */
> -	if (unlikely((seconds >= 0xc0) && (seconds <= 0xff)))
> +	if (unlikely(seconds >= 0xc0))
>  		seconds = 0xff;
>  
> -	if (unlikely((minutes >= 0xc0) && (minutes <= 0xff)))
> +	if (unlikely(minutes >= 0xc0))
>  		minutes = 0xff;
>  
> -	if (unlikely((hours >= 0xc0) && (hours <= 0xff)))
> +	if (unlikely(hours >= 0xc0))
>  		hours = 0xff;
>  
>  	alrm->time.tm_mon	= -1;
> 


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

end of thread, other threads:[~2015-02-18 13:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-18 10:44 [PATCH] rtc: ds1685: Remove superfluous checks for out-of-range u8 values Geert Uytterhoeven
2015-02-18 13:22 ` Joshua Kinard

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.