[PATCH 2/4] ptp/clcok:Introduce the setktime/getktime interfaces with "ktime_t" type

Baolin Wang
2015-03-19T05:46:38Z

This patch introduces another two options to get/set time with "ktime_t"
type in ptp clock operation.

Original code will set/get time through the settime/gettime interfaces
with "timespec" type, that will cause break issue in year 2038. And now
introducing the new setktime/getktime interfaces with "ktime_t" type to
use firstly.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
drivers/ptp/ptp_clock.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index 296b0ec..46425ad 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -106,14 +106,30 @@ static int ptp_clock_getres(struct posix_clock *pc, struct timespec *tp)

static int ptp_clock_settime(struct posix_clock *pc, const struct timespec *tp)
{
+ ktime_t kt;
struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock);
- return ptp->info->settime(ptp->info, tp);
+
+ if (ptp->info->setktime) {
+ kt = timespec_to_ktime(*tp);
+ return ptp->info->setktime(ptp->info, kt);
+ } else {
+ return ptp->info->settime(ptp->info, tp);
+ }
}

static int ptp_clock_gettime(struct posix_clock *pc, struct timespec *tp)
{
+ ktime_t kt;
+ int ret;
struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock);
- return ptp->info->gettime(ptp->info, tp);
+
+ if (ptp->info->getktime) {
+ ret = ptp->info->getktime(ptp->info, &kt);
+ *tp = ktime_to_timespec(kt);
+ return ret;
+ } else {
+ return ptp->info->gettime(ptp->info, tp);
+ }
}

static int ptp_clock_adjtime(struct posix_clock *pc, struct timex *tx)
--
1.7.9.5