misc: mic: fix passing the current time
authorArnd Bergmann <arnd@arndb.de>
Mon, 18 Jun 2018 14:25:51 +0000 (16:25 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 7 Jul 2018 15:44:52 +0000 (17:44 +0200)
I noticed that the mic driver passes a 'struct timespec64' as part of
a message into an attached device, where it is used to set the current
system time.

This won't actually work if one of the two sides runs a 32-bit kernel and
the other runs a 64-bit kernel, since the structure layout is different
between the two.

I found this while replacing calls to the deprecated do_settimeofday64()
interface with the modern ktime_get_real_ts() variant, but it seems
appropriate to address both at the same time here.

To make sure we have a sane structure, let's define our own structure
using the layout of the 64-bit kernel.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/mic/cosm/cosm_main.h
drivers/misc/mic/cosm/cosm_scif_server.c
drivers/misc/mic/cosm_client/cosm_scif_client.c

index f01156f..aa78cdf 100644 (file)
@@ -45,7 +45,10 @@ struct cosm_msg {
        u64 id;
        union {
                u64 shutdown_status;
-               struct timespec64 timespec;
+               struct {
+                       u64 tv_sec;
+                       u64 tv_nsec;
+               } timespec;
        };
 };
 
index 05a6328..e94b7ea 100644 (file)
@@ -179,9 +179,13 @@ static void cosm_set_crashed(struct cosm_device *cdev)
 static void cosm_send_time(struct cosm_device *cdev)
 {
        struct cosm_msg msg = { .id = COSM_MSG_SYNC_TIME };
+       struct timespec64 ts;
        int rc;
 
-       getnstimeofday64(&msg.timespec);
+       ktime_get_real_ts64(&ts);
+       msg.timespec.tv_sec = ts.tv_sec;
+       msg.timespec.tv_nsec = ts.tv_nsec;
+
        rc = scif_send(cdev->epd, &msg, sizeof(msg), SCIF_SEND_BLOCK);
        if (rc < 0)
                dev_err(&cdev->dev, "%s %d scif_send failed rc %d\n",
index beafc0d..225078c 100644 (file)
@@ -63,7 +63,11 @@ static struct notifier_block cosm_reboot = {
 /* Set system time from timespec value received from the host */
 static void cosm_set_time(struct cosm_msg *msg)
 {
-       int rc = do_settimeofday64(&msg->timespec);
+       struct timespec64 ts = {
+               .tv_sec = msg->timespec.tv_sec,
+               .tv_nsec = msg->timespec.tv_nsec,
+       };
+       int rc = do_settimeofday64(&ts);
 
        if (rc)
                dev_err(&client_spdev->dev, "%s: %d settimeofday rc %d\n",