* [PATCH] rtc-s3c.c: fix time setting checks
@ 2006-08-15 9:24 Ben Dooks
2006-08-15 10:27 ` Jiri Slaby
0 siblings, 1 reply; 3+ messages in thread
From: Ben Dooks @ 2006-08-15 9:24 UTC (permalink / raw)
To: linux-kernel, akpm
Fix the checking of the range for the year when
setting time with the S3C24XX RTC driver
Signed-off-by: Ben Dooks <ben-linux@fluff.org>
diff -urpN -X ../dontdiff linux-2.6.18-rc4-all1/drivers/rtc/rtc-s3c.c linux-2.6.18-rc4-all2/drivers/rtc/rtc-s3c.c
--- linux-2.6.18-rc4-all1/drivers/rtc/rtc-s3c.c 2006-08-14 09:04:57.000000000 +0100
+++ linux-2.6.18-rc4-all2/drivers/rtc/rtc-s3c.c 2006-08-14 09:59:47.000000000 +0100
@@ -11,6 +11,8 @@
* S3C2410/S3C2440/S3C24XX Internal RTC Driver
*/
+//B#define DEBUG
+
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/string.h>
@@ -153,24 +155,25 @@ static int s3c_rtc_gettime(struct device
static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
{
void __iomem *base = s3c_rtc_base;
+ int year = tm->tm_year - 100;
+
+ pr_debug("set time %02d.%02d.%02d %02d/%02d/%02d\n",
+ tm->tm_year, tm->tm_mon, tm->tm_mday,
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
- /* the rtc gets round the y2k problem by just not supporting it */
+ /* we get around y2k by simply not supporting it */
- if (tm->tm_year > 100) {
+ if (year < 0 || year >= 100) {
dev_err(dev, "rtc only supports 100 years\n");
return -EINVAL;
}
- pr_debug("set time %02d.%02d.%02d %02d/%02d/%02d\n",
- tm->tm_year, tm->tm_mon, tm->tm_mday,
- tm->tm_hour, tm->tm_min, tm->tm_sec);
-
writeb(BIN2BCD(tm->tm_sec), base + S3C2410_RTCSEC);
writeb(BIN2BCD(tm->tm_min), base + S3C2410_RTCMIN);
writeb(BIN2BCD(tm->tm_hour), base + S3C2410_RTCHOUR);
writeb(BIN2BCD(tm->tm_mday), base + S3C2410_RTCDATE);
writeb(BIN2BCD(tm->tm_mon + 1), base + S3C2410_RTCMON);
- writeb(BIN2BCD(tm->tm_year - 100), base + S3C2410_RTCYEAR);
+ writeb(BIN2BCD(year), base + S3C2410_RTCYEAR);
return 0;
}
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] rtc-s3c.c: fix time setting checks
2006-08-15 9:24 [PATCH] rtc-s3c.c: fix time setting checks Ben Dooks
@ 2006-08-15 10:27 ` Jiri Slaby
0 siblings, 0 replies; 3+ messages in thread
From: Jiri Slaby @ 2006-08-15 10:27 UTC (permalink / raw)
To: Ben Dooks; +Cc: linux-kernel, akpm
Ben Dooks wrote:
> Fix the checking of the range for the year when
> setting time with the S3C24XX RTC driver
>
> Signed-off-by: Ben Dooks <ben-linux@fluff.org>
>
> diff -urpN -X ../dontdiff linux-2.6.18-rc4-all1/drivers/rtc/rtc-s3c.c linux-2.6.18-rc4-all2/drivers/rtc/rtc-s3c.c
> --- linux-2.6.18-rc4-all1/drivers/rtc/rtc-s3c.c 2006-08-14 09:04:57.000000000 +0100
> +++ linux-2.6.18-rc4-all2/drivers/rtc/rtc-s3c.c 2006-08-14 09:59:47.000000000 +0100
> @@ -11,6 +11,8 @@
> * S3C2410/S3C2440/S3C24XX Internal RTC Driver
> */
>
> +//B#define DEBUG
> +
But what's this?
> #include <linux/module.h>
> #include <linux/fs.h>
> #include <linux/string.h>
> @@ -153,24 +155,25 @@ static int s3c_rtc_gettime(struct device
> static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
> {
> void __iomem *base = s3c_rtc_base;
> + int year = tm->tm_year - 100;
> +
> + pr_debug("set time %02d.%02d.%02d %02d/%02d/%02d\n",
> + tm->tm_year, tm->tm_mon, tm->tm_mday,
> + tm->tm_hour, tm->tm_min, tm->tm_sec);
>
> - /* the rtc gets round the y2k problem by just not supporting it */
> + /* we get around y2k by simply not supporting it */
>
> - if (tm->tm_year > 100) {
> + if (year < 0 || year >= 100) {
> dev_err(dev, "rtc only supports 100 years\n");
> return -EINVAL;
> }
>
> - pr_debug("set time %02d.%02d.%02d %02d/%02d/%02d\n",
> - tm->tm_year, tm->tm_mon, tm->tm_mday,
> - tm->tm_hour, tm->tm_min, tm->tm_sec);
> -
> writeb(BIN2BCD(tm->tm_sec), base + S3C2410_RTCSEC);
> writeb(BIN2BCD(tm->tm_min), base + S3C2410_RTCMIN);
> writeb(BIN2BCD(tm->tm_hour), base + S3C2410_RTCHOUR);
> writeb(BIN2BCD(tm->tm_mday), base + S3C2410_RTCDATE);
> writeb(BIN2BCD(tm->tm_mon + 1), base + S3C2410_RTCMON);
> - writeb(BIN2BCD(tm->tm_year - 100), base + S3C2410_RTCYEAR);
> + writeb(BIN2BCD(year), base + S3C2410_RTCYEAR);
>
> return 0;
> }
regards,
--
http://www.fi.muni.cz/~xslaby/ Jiri Slaby
faculty of informatics, masaryk university, brno, cz
e-mail: jirislaby gmail com, gpg pubkey fingerprint:
B674 9967 0407 CE62 ACC8 22A0 32CC 55C3 39D4 7A7E
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] rtc-s3c.c: fix time setting checks
@ 2006-08-15 20:53 Ben Dooks
0 siblings, 0 replies; 3+ messages in thread
From: Ben Dooks @ 2006-08-15 20:53 UTC (permalink / raw)
To: linux-kernel; +Cc: akpm
Fix the year check on setting the time with the S3C24XX
RTC driver. Also move the debug to before the set to see
what is going on if it does fail.
Signed-off-by: Ben Dooks <ben-linux@fluff.org>
diff -urpN -X ../dontdiff linux-2.6.18-rc4-rtc1/drivers/rtc/rtc-s3c.c linux-2.6.18-rc4-rtc2/drivers/rtc/rtc-s3c.c
--- linux-2.6.18-rc4-rtc1/drivers/rtc/rtc-s3c.c 2006-08-11 22:13:21.000000000 +0100
+++ linux-2.6.18-rc4-rtc2/drivers/rtc/rtc-s3c.c 2006-08-15 21:50:23.000000000 +0100
@@ -153,24 +153,25 @@ static int s3c_rtc_gettime(struct device
static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
{
void __iomem *base = s3c_rtc_base;
+ int year = tm->tm_year - 100;
- /* the rtc gets round the y2k problem by just not supporting it */
+ pr_debug("set time %02d.%02d.%02d %02d/%02d/%02d\n",
+ tm->tm_year, tm->tm_mon, tm->tm_mday,
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
+
+ /* we get around y2k by simply not supporting it */
- if (tm->tm_year > 100) {
+ if (year < 0 || year >= 100) {
dev_err(dev, "rtc only supports 100 years\n");
return -EINVAL;
}
- pr_debug("set time %02d.%02d.%02d %02d/%02d/%02d\n",
- tm->tm_year, tm->tm_mon, tm->tm_mday,
- tm->tm_hour, tm->tm_min, tm->tm_sec);
-
writeb(BIN2BCD(tm->tm_sec), base + S3C2410_RTCSEC);
writeb(BIN2BCD(tm->tm_min), base + S3C2410_RTCMIN);
writeb(BIN2BCD(tm->tm_hour), base + S3C2410_RTCHOUR);
writeb(BIN2BCD(tm->tm_mday), base + S3C2410_RTCDATE);
writeb(BIN2BCD(tm->tm_mon + 1), base + S3C2410_RTCMON);
- writeb(BIN2BCD(tm->tm_year - 100), base + S3C2410_RTCYEAR);
+ writeb(BIN2BCD(year), base + S3C2410_RTCYEAR);
return 0;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-08-15 20:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-15 9:24 [PATCH] rtc-s3c.c: fix time setting checks Ben Dooks
2006-08-15 10:27 ` Jiri Slaby
-- strict thread matches above, loose matches on Subject: below --
2006-08-15 20:53 Ben Dooks
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox