Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

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

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
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -45,7 +45,10 @@ struct cosm_msg {
	u64 id;
	union {
		u64 shutdown_status;
		struct timespec64 timespec;
		struct {
			u64 tv_sec;
			u64 tv_nsec;
		} timespec;
	};
};

+5 −1
Original line number Diff line number Diff line
@@ -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",
+5 −1
Original line number Diff line number Diff line
@@ -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",