From patchwork Thu Feb 24 15:28:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [3/3] rtc core: use pointers to pass rtc_time to and from ktime conversion routines Date: Thu, 24 Feb 2011 05:28:40 -0000 From: Roman Fietze X-Patchwork-Id: 84406 Message-Id: <201102241628.40267.roman.fietze@telemotive.de> To: John Stultz Cc: rtc-linux@googlegroups.com Hello John, Now the one where I'm really awaiting some comments ... eventually. >From 36019404e6a3525dc6b87e826750a5e5a371646b Mon Sep 17 00:00:00 2001 From: Roman Fietze Date: Thu, 24 Feb 2011 16:11:25 +0100 Subject: [PATCH 3/3] rtc core: use pointers to pass rtc_time to and from ktime conversion routines Use a const struct rtc_time pointer to pass the RTC time to rtc_tm_to_ktime() instead of by value. Use a struct rtc_time pointer to return the RTC time from rtc_ktime_to_tm(). This change saves a little code space. The struct rtc_time consts of nine integers, structures this big shouldn't be passed or returned by value. This way the way of passing and returning rtc_time also matches the other functions handling rtc_time. Signed-off-by: Roman Fietze --- drivers/rtc/interface.c | 14 +++++++------- drivers/rtc/rtc-lib.c | 10 ++++------ include/linux/rtc.h | 4 ++-- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index cb2f072..06a401c 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c @@ -130,7 +130,7 @@ int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) else { memset(alarm, 0, sizeof(struct rtc_wkalrm)); alarm->enabled = rtc->aie_timer.enabled; - alarm->time = rtc_ktime_to_tm(rtc->aie_timer.node.expires); + rtc_ktime_to_tm(rtc->aie_timer.node.expires, &alarm->time); } mutex_unlock(&rtc->ops_lock); @@ -185,7 +185,7 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) if (rtc->aie_timer.enabled) { rtc_timer_remove(rtc, &rtc->aie_timer); } - rtc->aie_timer.node.expires = rtc_tm_to_ktime(alarm->time); + rtc->aie_timer.node.expires = rtc_tm_to_ktime(&alarm->time); rtc->aie_timer.period = ktime_set(0, 0); if (alarm->enabled) { err = rtc_timer_enqueue(rtc, &rtc->aie_timer); @@ -244,7 +244,7 @@ int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled) __rtc_read_time(rtc, &tm); onesec = ktime_set(1, 0); - now = rtc_tm_to_ktime(tm); + now = rtc_tm_to_ktime(&tm); rtc->uie_rtctimer.node.expires = ktime_add(now, onesec); rtc->uie_rtctimer.period = ktime_set(1, 0); err = rtc_timer_enqueue(rtc, &rtc->uie_rtctimer); @@ -521,7 +521,7 @@ static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer) if (&timer->node == timerqueue_getnext(&rtc->timerqueue)) { struct rtc_wkalrm alarm; int err; - alarm.time = rtc_ktime_to_tm(timer->node.expires); + rtc_ktime_to_tm(timer->node.expires, &alarm.time); alarm.enabled = 1; err = __rtc_set_alarm(rtc, &alarm); if (err == -ETIME) @@ -558,7 +558,7 @@ static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer) next = timerqueue_getnext(&rtc->timerqueue); if (!next) return; - alarm.time = rtc_ktime_to_tm(next->expires); + rtc_ktime_to_tm(next->expires, &alarm.time); alarm.enabled = 1; err = __rtc_set_alarm(rtc, &alarm); if (err == -ETIME) @@ -589,7 +589,7 @@ void rtc_timer_do_work(struct work_struct *work) mutex_lock(&rtc->ops_lock); again: __rtc_read_time(rtc, &tm); - now = rtc_tm_to_ktime(tm); + now = rtc_tm_to_ktime(&tm); while ((next = timerqueue_getnext(&rtc->timerqueue))) { if (next->expires.tv64 > now.tv64) break; @@ -614,7 +614,7 @@ again: if (next) { struct rtc_wkalrm alarm; int err; - alarm.time = rtc_ktime_to_tm(next->expires); + rtc_ktime_to_tm(next->expires, &alarm.time); alarm.enabled = 1; err = __rtc_set_alarm(rtc, &alarm); if (err == -ETIME) diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c index 2341ce6..40c37b6 100644 --- a/drivers/rtc/rtc-lib.c +++ b/drivers/rtc/rtc-lib.c @@ -120,10 +120,10 @@ EXPORT_SYMBOL(rtc_tm_to_time); /* * Convert rtc_time to ktime */ -ktime_t rtc_tm_to_ktime(struct rtc_time tm) +ktime_t rtc_tm_to_ktime(const struct rtc_time *tm) { time_t time; - rtc_tm_to_time(&tm, &time); + rtc_tm_to_time(tm, &time); return ktime_set(time, 0); } EXPORT_SYMBOL_GPL(rtc_tm_to_ktime); @@ -131,17 +131,15 @@ EXPORT_SYMBOL_GPL(rtc_tm_to_ktime); /* * Convert ktime to rtc_time */ -struct rtc_time rtc_ktime_to_tm(ktime_t kt) +void rtc_ktime_to_tm(ktime_t kt, struct rtc_time *tm) { struct timespec ts; - struct rtc_time ret; ts = ktime_to_timespec(kt); /* Round up any ns */ if (ts.tv_nsec) ts.tv_sec++; - rtc_time_to_tm(ts.tv_sec, &ret); - return ret; + rtc_time_to_tm(ts.tv_sec, tm); } EXPORT_SYMBOL_GPL(rtc_ktime_to_tm); diff --git a/include/linux/rtc.h b/include/linux/rtc.h index 58c0cde..43639c9 100644 --- a/include/linux/rtc.h +++ b/include/linux/rtc.h @@ -107,8 +107,8 @@ extern int rtc_year_days(unsigned int day, unsigned int month, unsigned int year extern int rtc_valid_tm(const struct rtc_time *tm); extern int rtc_tm_to_time(const struct rtc_time *tm, unsigned long *time); extern void rtc_time_to_tm(unsigned long time, struct rtc_time *tm); -extern ktime_t rtc_tm_to_ktime(struct rtc_time tm); -extern struct rtc_time rtc_ktime_to_tm(ktime_t kt); +extern ktime_t rtc_tm_to_ktime(const struct rtc_time *tm); +extern void rtc_ktime_to_tm(ktime_t kt, struct rtc_time *tm); #include