From patchwork Thu Sep 21 06:18:07 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: 113194 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp1641455qgf; Wed, 20 Sep 2017 23:19:03 -0700 (PDT) X-Received: by 10.84.238.142 with SMTP id v14mr4490733plk.388.1505974743494; Wed, 20 Sep 2017 23:19:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505974743; cv=none; d=google.com; s=arc-20160816; b=e7A0wWjPfMPCi/Asl1FTncgFuUtv13JGA+ZMOlItlmSyxhK/++ePJgFVKnq/NJgmon O6sryvqLU3OSqgBjf9SKUTtsLHQBeh96pvRmYRrXj5ZvudVyUqHDRvDo5WJBH9q5yQpp CIK8/HGczTASYal56zu8z4bllmAj4n9EAYnXXw379XM3zBWN1WPMQGYsMs4kD/gF1r08 thTN2INC4GoQbmh7PEDJWcAmM95Uo6RZsjE2cZcQTW8q3AXWAZXaTmyMnzA4Z1mFKcDF lOBB5SvS75bpfiy/j4lmZ1bVhbRJY/8LZGZ6FhNCTjyToCzUkIs3NMtCaR0UmG9hTPAY ITEQ== 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=9UKJs7bSYshiNCpbGIPWwCRi4TXlyyRz3ngV2Dn2lOE=; b=YeTlRr/EWEjmfZGh031V12wnAIFovW9245pgdTTznRSC0XM/WoNp+v+4tBo/5RyJxa lrZlJlLE3xZm2+hFSqb+C3VZRcb61eEiahZjDSHIiLCOInYu72LbcxiE/5/yDkxHlc6g zTUxgU9q2/r9pcewB+TdEaeR9+4ldldbne/sQmtUAXHi7/m+SpBq6CZuHOFaS6Rajtwo 7PKt/nbVoAebeSJbKw754ZpAfHXkYf4N/Z74gfdHfdurS/MHYd1XXXZinJErStUEqgr9 jGOv5k8lEnqKwyGUTNS4LJayT9N3dXlYLvI2m6FK9NfjMe666hT0GT0QDqaNoy4rXWDv b6Vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q8oXGhjR; 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 i3si562739pli.293.2017.09.20.23.19.03; Wed, 20 Sep 2017 23:19:03 -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=Q8oXGhjR; 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 S1751825AbdIUGTB (ORCPT + 26 others); Thu, 21 Sep 2017 02:19:01 -0400 Received: from mail-pg0-f42.google.com ([74.125.83.42]:53862 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751743AbdIUGS4 (ORCPT ); Thu, 21 Sep 2017 02:18:56 -0400 Received: by mail-pg0-f42.google.com with SMTP id j70so3009154pgc.10 for ; Wed, 20 Sep 2017 23:18:56 -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=9UKJs7bSYshiNCpbGIPWwCRi4TXlyyRz3ngV2Dn2lOE=; b=Q8oXGhjRMjQAipu81SRyxqO2u7YI1xau+51QL9yIkOyV1uJqzIzGEQxdNRbBA54HMR 8glGl0RV2V1L7LEpQ59SgrML58lRIc73cRGZUsdmQWvJr2bGP3nU314ZiEb4j+eOEZIN mr+K3kLa6TSGAnrmNTU5QRF8L6V+ULcwxLqbA= 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=9UKJs7bSYshiNCpbGIPWwCRi4TXlyyRz3ngV2Dn2lOE=; b=NANkc4o2tBA95b68Rp0UfthPjG+sZtzaZfg9nqHwjywDevGmrf3cUZlENBwrd9fr6Z sCc4f8NYu/cv6/v9Yp/6/z+CBW3Wf44PRqWFerxDTwTyp6sRqjn9ht9gz+gWTAGXHjym gjsFkKfv7qQfFo8jmgw7tb37A/0YyE9EcDvGEOAXkHh1F/zBTRe686DlAl9yhAOdmPOi GGBf4Ss2xEeHzDzxIBFsJa8uyRY+oqWK08lhEdQ5dDSQb0Qc+uwiYJX0634vS21LQSkw RlqsbkqBnuFVCEEsjfizQvLczZdMGK2q7nMhXjK7hKDxwiDevtSxrjempqUdl/3EeoDq L4EQ== X-Gm-Message-State: AHPjjUg0Vw/Z99a64K0cjYbGoRzxsCvCjEGFsudG58yhnz2c+t2DVjHm 4YMXZc/rX4rZqIlG4dVsWYrzIg== X-Google-Smtp-Source: AOwi7QCRVHj5+KX+DJbuq+7kG1odsk+CRbk8U5SaJBDV6LDqpv2j2z7FcFQuwUJ9zr117yNyfusjSw== X-Received: by 10.84.238.143 with SMTP id v15mr4576173plk.303.1505974735836; Wed, 20 Sep 2017 23:18:55 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id q23sm1037773pfk.182.2017.09.20.23.18.50 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 20 Sep 2017 23:18:55 -0700 (PDT) From: Baolin Wang To: perex@perex.cz, tiwai@suse.com Cc: lgirdwood@gmail.com, mingo@kernel.org, o-takashi@sakamocchi.jp, elfring@users.sourceforge.net, dan.carpenter@oracle.com, jeeja.kp@intel.com, vinod.koul@intel.com, dharageswari.r@intel.com, guneshwor.o.singh@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, arnd@arndb.de, broonie@kernel.org, deepa.kernel@gmail.com, baolin.wang@linaro.org, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 5/7] sound: core: Avoid using timespec for struct snd_timer_status Date: Thu, 21 Sep 2017 14:18:07 +0800 Message-Id: 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 | 66 ++++++++++++++++++++++++++++++++++++++++----- sound/core/timer_compat.c | 25 ++++++----------- 2 files changed, 68 insertions(+), 23 deletions(-) -- 1.7.9.5 diff --git a/sound/core/timer.c b/sound/core/timer.c index f44d702..376b7e6 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -79,6 +79,30 @@ struct snd_timer_user { struct mutex ioctl_lock; }; +#if __BITS_PER_LONG == 32 +struct snd_timer_status32 { + struct { s32 tv_sec; s32 tv_nsec; } tstamp; /* Timestamp - last update */ + 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) +#endif + +struct snd_timer_status64 { + struct { s64 tv_sec; s64 tv_nsec; } tstamp; /* Timestamp - last update */ + 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,43 @@ 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) +#if __BITS_PER_LONG == 32 +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.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; +} +#endif + +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.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; @@ -1920,8 +1970,12 @@ 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); +#if __BITS_PER_LONG == 32 + case SNDRV_TIMER_IOCTL_STATUS32: + return snd_timer_user_status32(file, argp); +#endif + 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..c592603 100644 --- a/sound/core/timer_compat.c +++ b/sound/core/timer_compat.c @@ -83,7 +83,7 @@ static int snd_timer_user_info_compat(struct file *file, return 0; } -struct snd_timer_status32 { +struct compat_snd_timer_status32 { struct compat_timespec tstamp; u32 resolution; u32 lost; @@ -93,10 +93,10 @@ struct snd_timer_status32 { }; static int snd_timer_user_status_compat(struct file *file, - struct snd_timer_status32 __user *_status) + struct compat_snd_timer_status32 __user *_status) { struct snd_timer_user *tu; - struct snd_timer_status32 status; + struct compat_snd_timer_status32 status; tu = file->private_data; if (snd_BUG_ON(!tu->timeri)) @@ -115,12 +115,6 @@ static int snd_timer_user_status_compat(struct file *file, 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 */ - /* */ @@ -128,9 +122,8 @@ 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 compat_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 +151,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: + case SNDRV_TIMER_IOCTL_STATUS_COMPAT32: 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_COMPAT64: + return snd_timer_user_status64(file, argp); } return -ENOIOCTLCMD; }