Skip to content

Commit

Permalink
misc: mic: fix passing the current time
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Arnd Bergmann authored and Greg Kroah-Hartman committed Jul 7, 2018
1 parent e890591 commit 6051e79
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion drivers/misc/mic/cosm/cosm_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ struct cosm_msg {
u64 id;
union {
u64 shutdown_status;
struct timespec64 timespec;
struct {
u64 tv_sec;
u64 tv_nsec;
} timespec;
};
};

Expand Down
6 changes: 5 additions & 1 deletion drivers/misc/mic/cosm/cosm_scif_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion drivers/misc/mic/cosm_client/cosm_scif_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 6051e79

Please sign in to comment.