Commit 6051e79b authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Greg Kroah-Hartman

misc: mic: fix passing the current time

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: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e8905914
...@@ -45,7 +45,10 @@ struct cosm_msg { ...@@ -45,7 +45,10 @@ struct cosm_msg {
u64 id; u64 id;
union { union {
u64 shutdown_status; u64 shutdown_status;
struct timespec64 timespec; struct {
u64 tv_sec;
u64 tv_nsec;
} timespec;
}; };
}; };
......
...@@ -179,9 +179,13 @@ static void cosm_set_crashed(struct cosm_device *cdev) ...@@ -179,9 +179,13 @@ static void cosm_set_crashed(struct cosm_device *cdev)
static void cosm_send_time(struct cosm_device *cdev) static void cosm_send_time(struct cosm_device *cdev)
{ {
struct cosm_msg msg = { .id = COSM_MSG_SYNC_TIME }; struct cosm_msg msg = { .id = COSM_MSG_SYNC_TIME };
struct timespec64 ts;
int rc; 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); rc = scif_send(cdev->epd, &msg, sizeof(msg), SCIF_SEND_BLOCK);
if (rc < 0) if (rc < 0)
dev_err(&cdev->dev, "%s %d scif_send failed rc %d\n", dev_err(&cdev->dev, "%s %d scif_send failed rc %d\n",
......
...@@ -63,7 +63,11 @@ static struct notifier_block cosm_reboot = { ...@@ -63,7 +63,11 @@ static struct notifier_block cosm_reboot = {
/* Set system time from timespec value received from the host */ /* Set system time from timespec value received from the host */
static void cosm_set_time(struct cosm_msg *msg) 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) if (rc)
dev_err(&client_spdev->dev, "%s: %d settimeofday rc %d\n", dev_err(&client_spdev->dev, "%s: %d settimeofday rc %d\n",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment