From patchwork Tue Apr 24 12:06:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 134066 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2150684lji; Tue, 24 Apr 2018 05:07:37 -0700 (PDT) X-Google-Smtp-Source: AIpwx49WpJP3AHYt/qU+3zWRGZjwaxvlLrR4HooVjCu12Or+28qdcUf4Q7u+R7Yhh7uvgM9kVVMe X-Received: by 2002:adf:b8eb:: with SMTP id c40-v6mr18357868wrg.170.1524571657580; Tue, 24 Apr 2018 05:07:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524571657; cv=none; d=google.com; s=arc-20160816; b=vtBYUYJQITzY37a+B/fcUAN/hFd40W5CooDF15eYoO+djD0So5tIK0oKUMTjfzay7p yd3r1W380sZF1IIpWn8qsoK/yt9cjbemFcpb+LtFv5oU/V09JQbO7k8W3Hm74Md6CS22 NalwxFxWd7Dmp/6vsRbryb87KO6sxvyhu/BhxUXO0w0f+1p6y4Uy3MIFUA2EOUHH7D7t XZItDQckMqvSOrJEhStbjXokZBpnhJYbu6cXNQEuaqbyPYKQIKmm7QVI0KMa+L6WrOYV jLfPFSWGYUP8IzYQ5bFilmbu7DkzGDQYvV2iuBEQ0ANxklBCQIo8/4aVJwjKvYFKpniu 0amg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:references :in-reply-to:message-id:date:to:from:dkim-signature:delivered-to :arc-authentication-results; bh=spH38ZhWUZTn4POu3l1F7roVplKj7qQ4eb0ZHYmzZxM=; b=ne33k3AOZC4afTXCpdOdJMZoFq9JbFrU22fdhKq6jcQpok2OYde/cDsLK4emYrfSNE 9EH7tyxpkIn27fy+pHt9Ze3wZSfGAhW3HLmjz5Hzyl60v3M8SjQ7hIP8ptVtv7ocaAnl 5JQ3RRU8cjbmdz4CdO9m3KWmgCChCkWZGY5XoZfIaGcQsiV4+uGnZhrXAGKMb+Rip8/O uCOWZaV1gz7ibHE6C87AzcZlRxK3/gPWZdJAOQoeV8yh7YuZTwFpHZalhuGlM+FZ9Pfg bRYszFXZpGuxB8IqtfDC2iwgaPcU2s/PRYL5+1w8gU4aoup8VKwqCHwU/Lwbj1y5/yuJ 8/EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=D4mVtVe0; spf=pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) smtp.mailfrom=alsa-devel-bounces@alsa-project.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from alsa0.perex.cz (alsa0.perex.cz. [77.48.224.243]) by mx.google.com with ESMTP id 63-v6si11194580wre.270.2018.04.24.05.07.37; Tue, 24 Apr 2018 05:07:37 -0700 (PDT) Received-SPF: pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) client-ip=77.48.224.243; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=D4mVtVe0; spf=pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) smtp.mailfrom=alsa-devel-bounces@alsa-project.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 1E2012676BA; Tue, 24 Apr 2018 14:07:32 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id A83A62676BA; Tue, 24 Apr 2018 14:07:29 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_PASS autolearn=disabled version=3.4.0 Received: from mail-pf0-f194.google.com (mail-pf0-f194.google.com [209.85.192.194]) by alsa0.perex.cz (Postfix) with ESMTP id C7508267230 for ; Tue, 24 Apr 2018 14:07:24 +0200 (CEST) Received: by mail-pf0-f194.google.com with SMTP id v63so2500717pfk.8 for ; Tue, 24 Apr 2018 05:07:24 -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=WKVt13V27oCvRafXSAYWQULVWixLxgRr7JG5X1xGeLU=; b=D4mVtVe0XzxgwUdk9BF/8XyHGjBmHizJSqkmXGSSn2qGvNEfZzG0ciCiQxVAHEwJW6 GccBe2ix0RUQBjvLu8E+fXBt0oB1u4tc5OwpzP512ROs6v87Run07G7Ram+JcDHjkIeL vTn3wafrUO1u77lB7OjjNwZOM5dzsKgv8UK+4= 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=WKVt13V27oCvRafXSAYWQULVWixLxgRr7JG5X1xGeLU=; b=poYP6gaKQ5PkrKiOFGiRZxJ3MC1dPDb0ZLbH5iLH+EDHfqcvREZOi4gn4c41gC8boq S68+aTLzTFTa0E2b5/8KapPMSeWZUjt4D/OhVt9qTokwhrJHEKPUX4xCP9ZaLMEUDYyf wfXDBrVF61FvuiSXSUPefSixWJrDMsmjsTfWn2ckxDTx++j7Z676R+uca4i41Px9okM/ Kc1wAVZZXQZ+hP119MDnIzdYrxn40IuJleBg2/25aBNm6zulIx0AL4yxU7pdDKhLNWjW JZAZdoggjMMrmKPsuztHrBozXW/ni79dsqhqbM5Ll/LaiCg4pviwS2fdnuQjcgn2NKhl +YFg== X-Gm-Message-State: ALQs6tAVmhM2d1rxGwGA+V0h7hgI8NXWSIXPAkN89igjCgQVtownn+wN j/jcMQtn9Cvdaghyq3i2dWUakQ== X-Received: by 10.99.115.78 with SMTP id d14mr8386345pgn.1.1524571643497; Tue, 24 Apr 2018 05:07:23 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id c7sm46350567pfg.81.2018.04.24.05.07.18 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Apr 2018 05:07:23 -0700 (PDT) From: Baolin Wang To: perex@perex.cz, tiwai@suse.com, arnd@arndb.de Date: Tue, 24 Apr 2018 20:06:09 +0800 Message-Id: <9d2927f93fca520407bb0eddcea08d51b3060494.1524570852.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Cc: fabf@skynet.be, arvind.yadav.cs@gmail.com, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, baolin.wang@linaro.org, vinod.koul@intel.com, hardik.t.shah@intel.com, guneshwor.o.singh@intel.com, lgirdwood@gmail.com, elfring@users.sourceforge.net, gudishax.kranthikumar@intel.com, broonie@kernel.org, bhumirks@gmail.com, naveen.m@intel.com, jeeja.kp@intel.com, o-takashi@sakamocchi.jp, subhransu.s.prusty@intel.com, mingo@kernel.org, dan.carpenter@oracle.com Subject: [alsa-devel] [PATCH 2/8] ALSA: Avoid using timespec for struct snd_timer_status X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org struct snd_timer_status uses 'timespec' type variables to record timestamp, which will be changed to an incompatible layout with updated user space using 64-bit time_t. To handle both the old and the new layout on 32-bit architectures, this patch introduces 'struct snd_timer_status32' and 'struct snd_timer_status64' to handle 32bit time_t and 64bit time_t in native mode and compat mode, which replaces timespec with s64 type. 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 _______________________________________________ Alsa-devel mailing list Alsa-devel@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/alsa-devel diff --git a/sound/core/timer.c b/sound/core/timer.c index a77b461..c9d7ddb 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); @@ -1842,17 +1866,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; @@ -1964,8 +2012,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 e00f7e3..0495ede 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 (!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; -} - -#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, @@ -159,12 +116,10 @@ static long __snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd, 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; }