Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

HSI: cmt_speech: fix timestamp interface

The user interface for timestamps in the new cmt_speech
driver is broken in multiple ways:

- The layout is incompatible between 32-bit and 64-bit user
space, because of the size differences in 'struct timespec'.
This means that the driver can not work when used with 32-bit
user space on a 64-bit kernel.

- As there are plans to change 32-bit user space to use
a 64-bit time_t type in the future, it will also be
incompatible with new 32-bit user space.

- It is using ktime_get_ts under it's deprecated alias
(do_posix_clock_monotonic_gettime).

To keep support for the user space tools written for this driver (which
have lived many years out-of-tree), the interface has been hardened to
unsigned 32-bit values.

Reported-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Sebastian Reichel <sre@kernel.org>

+18 -7
+7 -2
drivers/hsi/clients/cmt_speech.c
··· 451 451 dev_dbg(&hi->cl->device, "Read on control: %08X\n", cmd); 452 452 cs_release_cmd(msg); 453 453 if (hi->flags & CS_FEAT_TSTAMP_RX_CTRL) { 454 - struct timespec *tstamp = 454 + struct timespec tspec; 455 + struct cs_timestamp *tstamp = 455 456 &hi->mmap_cfg->tstamp_rx_ctrl; 456 - do_posix_clock_monotonic_gettime(tstamp); 457 + 458 + ktime_get_ts(&tspec); 459 + 460 + tstamp->tv_sec = (__u32) tspec.tv_sec; 461 + tstamp->tv_nsec = (__u32) tspec.tv_nsec; 457 462 } 458 463 spin_unlock(&hi->lock); 459 464
+11 -5
include/uapi/linux/hsi/cs-protocol.h
··· 76 76 }; 77 77 78 78 /* 79 + * struct for monotonic timestamp taken when the 80 + * last control command was received 81 + */ 82 + struct cs_timestamp { 83 + __u32 tv_sec; /* seconds */ 84 + __u32 tv_nsec; /* nanoseconds */ 85 + }; 86 + 87 + /* 79 88 * Struct describing the layout and contents of the driver mmap area. 80 89 * This information is meant as read-only information for the application. 81 90 */ ··· 100 91 __u32 rx_ptr; 101 92 __u32 rx_ptr_boundary; 102 93 __u32 reserved3[2]; 103 - /* 104 - * if enabled with CS_FEAT_TSTAMP_RX_CTRL, monotonic 105 - * timestamp taken when the last control command was received 106 - */ 107 - struct timespec tstamp_rx_ctrl; 94 + /* enabled with CS_FEAT_TSTAMP_RX_CTRL */ 95 + struct cs_timestamp tstamp_rx_ctrl; 108 96 }; 109 97 110 98 #define CS_IO_MAGIC 'C'