[alsa-devel] [PATCH v6 5/8] ALSA: Avoid using timespec for struct snd_rawmidi_status

Takashi Iwai tiwai at suse.de
Tue Nov 12 17:38:57 CET 2019


On Tue, 12 Nov 2019 16:16:39 +0100,
Arnd Bergmann wrote:
> 
> From: Baolin Wang <baolin.wang at linaro.org>
> 
> The struct snd_rawmidi_status will use 'timespec' type variables to record
> timestamp, which is not year 2038 safe on 32bits system.
> 
> Thus we introduced 'struct snd_rawmidi_status32' and 'struct snd_rawmidi_status64'
> to handle 32bit time_t and 64bit time_t in native mode, which replace
> timespec with s64 type.
> 
> In compat mode, we renamed or introduced new structures to handle 32bit/64bit
> time_t in compatible mode. The 'struct snd_rawmidi_status32' and
> snd_rawmidi_ioctl_status32() are used to handle 32bit time_t in compat mode.
> 'struct compat_snd_rawmidi_status64' is used to handle 64bit time_t.
> 
> When glibc changes time_t to 64-bit, any recompiled program will issue ioctl
> commands that the kernel does not understand without this patch.
> 
> Signed-off-by: Baolin Wang <baolin.wang at linaro.org>
> Signed-off-by: Arnd Bergmann <arnd at arndb.de>
> ---
>  include/uapi/sound/asound.h |   3 +
>  sound/core/rawmidi.c        | 132 ++++++++++++++++++++++++++++--------
>  sound/core/rawmidi_compat.c |  87 ++++++------------------
>  3 files changed, 128 insertions(+), 94 deletions(-)
> 
> diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h
> index 7b74524f9406..cb830813da5d 100644
> --- a/include/uapi/sound/asound.h
> +++ b/include/uapi/sound/asound.h
> @@ -651,13 +651,16 @@ struct snd_rawmidi_params {
>  	unsigned char reserved[16];	/* reserved for future use */
>  };
>  
> +#ifndef __KERNEL__
>  struct snd_rawmidi_status {
>  	int stream;
> +	unsigned char pad1[sizeof(time_t) - sizeof(int)];
>  	struct timespec tstamp;		/* Timestamp */
>  	size_t avail;			/* available bytes */
>  	size_t xruns;			/* count of overruns since last status (in bytes) */
>  	unsigned char reserved[16];	/* reserved for future use */
>  };

Can we use union instead of padding?  Something like:

struct snd_rawmidi_status {
	union {
		int stream;
		time_t stream_alignment;
	};
  	struct timespec tstamp;		/* Timestamp */
	....


thanks,

Takashi


More information about the Alsa-devel mailing list