From patchwork Thu Nov 2 11:06:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 117778 Delivered-To: patch@linaro.org Received: by 10.80.245.45 with SMTP id t42csp1918002edm; Thu, 2 Nov 2017 04:08:28 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SWLCiWhLzN0fU7hRZLbWnnI8htQha3vb0MUBzl0Nq4oStaNlOIfabPej2DXOgxYdEGiuJz X-Received: by 10.84.184.12 with SMTP id l12mr2848469plc.404.1509620908148; Thu, 02 Nov 2017 04:08:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509620908; cv=none; d=google.com; s=arc-20160816; b=bg8meL7YCbD+7tmpfiOcmcMnma6SAGs08M0d0xEqNBfWIXkUk0i7sjPiVkaatPZrUK 1oho1U6DIJFoGZMQMPqnE407vrRrOtz+P8D8KOgEoFZAQYmexW5zD7+/9gfznQF/tWMQ MLn1d++3gzZk4Zao0CwgPGMtXeI5YADI3khszH95yrPTxl2nVTpedzVf8DbkDw+C+wKa 5wlwjEb/moLnNb2EoZr7iz4t/zbjori0ypFMYFoCHPdDdQd1Go2BBEdCXBKCqvVMTsPR z/IEarwnnb+o0cb2l6WxjPkwF2+jDTVU2FUsk/DNmYVCHEB0PySI+ym8NGv6/OnZrdok sTfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=waYCnyobHwTlyPNeA0sgTYEiCEo7RecuFTDE940VUgw=; b=LJs32wpuJg/C0eOk56Mfa/bUF6QkN3VKWJsR9lsJHvRvvMe5oSi7TMd7WpF17ZXa7T qsNvH9H49kbum/dQydbjqNwutReZUr3AW+qq6sTP05/BOiQO02ILKJjYV6vRscpzZQiI w5nBeiaive/RRI78YmF4xvpFk3ABiuCy/RV6fBKcHkvbQlR6u5HiRA5KJNnylLI//cYq 3I/y588M07gfKSJHzmxeZcm37/boIeoYCLcL+/tpTl4RqfxFFvF3rwn9STtBuLeF78yQ xfrE/BPre7yBBjyrWvwVGoQIsoBOHlqOhh2EzDGzLpHeaXjTZQnrilXISiEmJJdweRDl ZR7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B5UT9FLM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 62si3503031pfh.332.2017.11.02.04.08.27; Thu, 02 Nov 2017 04:08:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B5UT9FLM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755718AbdKBLI0 (ORCPT + 26 others); Thu, 2 Nov 2017 07:08:26 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:50164 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755564AbdKBLIX (ORCPT ); Thu, 2 Nov 2017 07:08:23 -0400 Received: by mail-pg0-f65.google.com with SMTP id g6so4773877pgn.6 for ; Thu, 02 Nov 2017 04:08:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=waYCnyobHwTlyPNeA0sgTYEiCEo7RecuFTDE940VUgw=; b=B5UT9FLM14PbEHnyJCpoY2tLj6isYuPA2zGpu5DE8ZNdEijdCnVAQ6h4HatDBxfot0 sFYHGWJ7JC0Hh3S3VzT1sMmkKgpM/8u+8JONBMJpqxd1aXbZ0P29AtlX3wK2bi1VkVSE YLBAHCfnlB9gtw4eOQAbz4P3AVS0CQ0s1adPY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=waYCnyobHwTlyPNeA0sgTYEiCEo7RecuFTDE940VUgw=; b=Xl2dLTAWeSqT0WwEal6mmaYiwYR+R6eWnHq2g72VFq4M0damj/hOQdr/d8DFsozjkk sgqpjFySSB9v6rtge4/dUhOZ/FisjcM/mRvnWLWRmpLxe8ZE/R+hn3KKRfVPXNZ7sQfD N9VdXyJnjtHWiUY7lJy/Bm4u/3QcdOzcSVDm3qE8DndFxvtlNdEqSqgcgfUYoejn3zxp 0+PlfH4REPI+qOdexgmKC1smSpR9tH5GBkepOcfw7oe20ZU81e2CwYwYrY0TQEwjqFtB pLHC/tbVoazi5S/4RgsGOmOLfY8CjqjAOigR/AVvTEn8csOkxrbqB5Kb/OIEjDz2ZywG 5kzg== X-Gm-Message-State: AMCzsaWiX8+ze3t1KJh9v8o+TdJaDRzBf0MWuOXn7FNGDXkpIgktk3Pj Yn6Hfp3fTUg67tWaa9AKDo8Nzg== X-Received: by 10.99.120.7 with SMTP id t7mr3088755pgc.360.1509620902680; Thu, 02 Nov 2017 04:08:22 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id g13sm5473772pfm.130.2017.11.02.04.08.16 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Nov 2017 04:08:22 -0700 (PDT) From: Baolin Wang To: perex@perex.cz, tiwai@suse.com, arnd@arndb.de Cc: lgirdwood@gmail.com, broonie@kernel.org, o-takashi@sakamocchi.jp, mingo@kernel.org, elfring@users.sourceforge.net, dan.carpenter@oracle.com, jeeja.kp@intel.com, vinod.koul@intel.com, guneshwor.o.singh@intel.com, subhransu.s.prusty@intel.com, bhumirks@gmail.com, gudishax.kranthikumar@intel.com, naveen.m@intel.com, hardik.t.shah@intel.com, arvind.yadav.cs@gmail.com, fabf@skynet.be, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org Subject: [RFC PATCH v2 4/7] sound: core: Avoid using timespec for struct snd_timer_status Date: Thu, 2 Nov 2017 19:06:54 +0800 Message-Id: <9902c3c02cccba879bc9b8359b4af4aadfdcc5c1.1509612176.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The struct snd_timer_status will use 'timespec' type variables to record timestamp, which is not year 2038 safe on 32bits system. Thus thia patch introduces 'struct snd_timer_status32' and 'struct snd_timer_status64' to handle 32bit time_t and 64bit time_t in native mode, which replace timespec with s64 type. In compat mode, this patch renamed the structure as 'struct compat_snd_timer_status32' to handle 32bit time_t. Moreover we should use 'struct snd_timer_status64' to handle 64bit time_t no matter 32bit or 64bit alignment, since they have the same size. 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 --- sound/core/timer.c | 62 ++++++++++++++++++++++++++++++++++++++++----- sound/core/timer_compat.c | 57 +++++------------------------------------ 2 files changed, 62 insertions(+), 57 deletions(-) -- 1.7.9.5 diff --git a/sound/core/timer.c b/sound/core/timer.c index f44d702..9168365 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -79,6 +79,30 @@ struct snd_timer_user { struct mutex ioctl_lock; }; +struct snd_timer_status32 { + s32 tstamp_sec; /* Timestamp - last update */ + s32 tstamp_nsec; + unsigned int resolution; /* current period resolution in ns */ + unsigned int lost; /* counter of master tick lost */ + unsigned int overrun; /* count of read queue overruns */ + unsigned int queue; /* used queue size */ + unsigned char reserved[64]; /* reserved */ +}; + +#define SNDRV_TIMER_IOCTL_STATUS32 _IOR('T', 0x14, struct snd_timer_status32) + +struct snd_timer_status64 { + s64 tstamp_sec; /* Timestamp - last update */ + s64 tstamp_nsec; + unsigned int resolution; /* current period resolution in ns */ + unsigned int lost; /* counter of master tick lost */ + unsigned int overrun; /* count of read queue overruns */ + unsigned int queue; /* used queue size */ + unsigned char reserved[64]; /* reserved */ +}; + +#define SNDRV_TIMER_IOCTL_STATUS64 _IOR('T', 0x14, struct snd_timer_status64) + /* list of timers */ static LIST_HEAD(snd_timer_list); @@ -1798,17 +1822,41 @@ static int snd_timer_user_params(struct file *file, return err; } -static int snd_timer_user_status(struct file *file, - struct snd_timer_status __user *_status) +static int snd_timer_user_status32(struct file *file, + struct snd_timer_status32 __user *_status) + { + struct snd_timer_user *tu; + struct snd_timer_status32 status; + + tu = file->private_data; + if (!tu->timeri) + return -EBADFD; + memset(&status, 0, sizeof(status)); + status.tstamp_sec = tu->tstamp.tv_sec; + status.tstamp_nsec = tu->tstamp.tv_nsec; + status.resolution = snd_timer_resolution(tu->timeri); + status.lost = tu->timeri->lost; + status.overrun = tu->overrun; + spin_lock_irq(&tu->qlock); + status.queue = tu->qused; + spin_unlock_irq(&tu->qlock); + if (copy_to_user(_status, &status, sizeof(status))) + return -EFAULT; + return 0; +} + +static int snd_timer_user_status64(struct file *file, + struct snd_timer_status64 __user *_status) { struct snd_timer_user *tu; - struct snd_timer_status status; + struct snd_timer_status64 status; tu = file->private_data; if (!tu->timeri) return -EBADFD; memset(&status, 0, sizeof(status)); - status.tstamp = timespec64_to_timespec(tu->tstamp); + status.tstamp_sec = tu->tstamp.tv_sec; + status.tstamp_nsec = tu->tstamp.tv_nsec; status.resolution = snd_timer_resolution(tu->timeri); status.lost = tu->timeri->lost; status.overrun = tu->overrun; @@ -1920,8 +1968,10 @@ static long __snd_timer_user_ioctl(struct file *file, unsigned int cmd, return snd_timer_user_info(file, argp); case SNDRV_TIMER_IOCTL_PARAMS: return snd_timer_user_params(file, argp); - case SNDRV_TIMER_IOCTL_STATUS: - return snd_timer_user_status(file, argp); + case SNDRV_TIMER_IOCTL_STATUS32: + return snd_timer_user_status32(file, argp); + case SNDRV_TIMER_IOCTL_STATUS64: + return snd_timer_user_status64(file, argp); case SNDRV_TIMER_IOCTL_START: case SNDRV_TIMER_IOCTL_START_OLD: return snd_timer_user_start(file); diff --git a/sound/core/timer_compat.c b/sound/core/timer_compat.c index 6a437eb..3e09548 100644 --- a/sound/core/timer_compat.c +++ b/sound/core/timer_compat.c @@ -83,54 +83,11 @@ static int snd_timer_user_info_compat(struct file *file, return 0; } -struct snd_timer_status32 { - struct compat_timespec tstamp; - u32 resolution; - u32 lost; - u32 overrun; - u32 queue; - unsigned char reserved[64]; -}; - -static int snd_timer_user_status_compat(struct file *file, - struct snd_timer_status32 __user *_status) -{ - struct snd_timer_user *tu; - struct snd_timer_status32 status; - - tu = file->private_data; - if (snd_BUG_ON(!tu->timeri)) - return -ENXIO; - memset(&status, 0, sizeof(status)); - status.tstamp.tv_sec = tu->tstamp.tv_sec; - status.tstamp.tv_nsec = tu->tstamp.tv_nsec; - status.resolution = snd_timer_resolution(tu->timeri); - status.lost = tu->timeri->lost; - status.overrun = tu->overrun; - spin_lock_irq(&tu->qlock); - status.queue = tu->qused; - spin_unlock_irq(&tu->qlock); - if (copy_to_user(_status, &status, sizeof(status))) - return -EFAULT; - return 0; -} - -#ifdef CONFIG_X86_X32 -/* X32 ABI has the same struct as x86-64 */ -#define snd_timer_user_status_x32(file, s) \ - snd_timer_user_status(file, s) -#endif /* CONFIG_X86_X32 */ - -/* - */ - enum { SNDRV_TIMER_IOCTL_GPARAMS32 = _IOW('T', 0x04, struct snd_timer_gparams32), SNDRV_TIMER_IOCTL_INFO32 = _IOR('T', 0x11, struct snd_timer_info32), - SNDRV_TIMER_IOCTL_STATUS32 = _IOW('T', 0x14, struct snd_timer_status32), -#ifdef CONFIG_X86_X32 - SNDRV_TIMER_IOCTL_STATUS_X32 = _IOW('T', 0x14, struct snd_timer_status), -#endif /* CONFIG_X86_X32 */ + SNDRV_TIMER_IOCTL_STATUS_COMPAT32 = _IOW('T', 0x14, struct snd_timer_status32), + SNDRV_TIMER_IOCTL_STATUS_COMPAT64 = _IOW('T', 0x14, struct snd_timer_status64), }; static long snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg) @@ -158,12 +115,10 @@ static long snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd, uns return snd_timer_user_gparams_compat(file, argp); case SNDRV_TIMER_IOCTL_INFO32: return snd_timer_user_info_compat(file, argp); - case SNDRV_TIMER_IOCTL_STATUS32: - return snd_timer_user_status_compat(file, argp); -#ifdef CONFIG_X86_X32 - case SNDRV_TIMER_IOCTL_STATUS_X32: - return snd_timer_user_status_x32(file, argp); -#endif /* CONFIG_X86_X32 */ + case SNDRV_TIMER_IOCTL_STATUS_COMPAT32: + return snd_timer_user_status32(file, argp); + case SNDRV_TIMER_IOCTL_STATUS_COMPAT64: + return snd_timer_user_status64(file, argp); } return -ENOIOCTLCMD; }