From patchwork Mon Jun 29 14:23:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bamvor Zhang Jian X-Patchwork-Id: 50415 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CB17E218E4 for ; Mon, 29 Jun 2015 14:27:12 +0000 (UTC) Received: by wibdu3 with SMTP id du3sf8876610wib.2 for ; Mon, 29 Jun 2015 07:27:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=8VTI3SPelIeKtECSuigoewEuw37yLucZ3N+Rg5bzYf0=; b=WhPsHhFaG5q9HCsRPcVRlXlG28ZayboQFuJrMZtaupx14nQTCuk9imjssMW3gemcWq NNxCeEXzk9svz+rnq89hKCEkEHAy19Ac8SJnToMGrs09aIg+SoSz6yAFz+DBNpeKxQBR 49SpgpKpdOxXFTfb13XOimIXQL9vyKuPKgSR9H6q580JqcC35DuJYWYJwKFhePmhFwrD 21x++TEEWmyMn9e65tPn+R4UVX9L2N1xhT1wSaVrpVNH+dObwT0lddZcr0rgTJ2o9ByB 3G6TLXbO4KROWPf1TcjUXA9vDXR8bglBccS+sntVnt+23LGAUhfB6JMjNpTGRdzE33ZR RUmQ== X-Gm-Message-State: ALoCoQlJF51Cim3Yd+zQ+WTOcmMFhwKg0WqaQ7G1jh9GFLLvoj8qQjjjwCvV+a7P6pDyYlL7Q1Vq X-Received: by 10.180.216.12 with SMTP id om12mr8778378wic.1.1435588032103; Mon, 29 Jun 2015 07:27:12 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.120.71 with SMTP id la7ls725016lab.25.gmail; Mon, 29 Jun 2015 07:27:11 -0700 (PDT) X-Received: by 10.152.1.40 with SMTP id 8mr14703740laj.56.1435588031781; Mon, 29 Jun 2015 07:27:11 -0700 (PDT) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id bx11si35182829lbb.141.2015.06.29.07.27.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Jun 2015 07:27:11 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by lagc2 with SMTP id c2so12059989lag.3 for ; Mon, 29 Jun 2015 07:27:11 -0700 (PDT) X-Received: by 10.152.26.163 with SMTP id m3mr14427263lag.86.1435588031622; Mon, 29 Jun 2015 07:27:11 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp1743941lbb; Mon, 29 Jun 2015 07:27:10 -0700 (PDT) X-Received: by 10.70.42.13 with SMTP id j13mr32636862pdl.90.1435588029760; Mon, 29 Jun 2015 07:27:09 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g2si64722584pdp.243.2015.06.29.07.27.08; Mon, 29 Jun 2015 07:27:09 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753618AbbF2O1H (ORCPT + 30 others); Mon, 29 Jun 2015 10:27:07 -0400 Received: from mail-pd0-f174.google.com ([209.85.192.174]:36149 "EHLO mail-pd0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752960AbbF2O0j (ORCPT ); Mon, 29 Jun 2015 10:26:39 -0400 Received: by pdcu2 with SMTP id u2so117813666pdc.3 for ; Mon, 29 Jun 2015 07:26:38 -0700 (PDT) X-Received: by 10.68.219.1 with SMTP id pk1mr32367366pbc.18.1435587998723; Mon, 29 Jun 2015 07:26:38 -0700 (PDT) Received: from linux-j170.site.site ([69.85.92.49]) by mx.google.com with ESMTPSA id i10sm42520177pdr.78.2015.06.29.07.26.34 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 29 Jun 2015 07:26:38 -0700 (PDT) From: Bamvor Zhang Jian To: arnd@arndb.de, john.stultz@linaro.org, tglx@linutronix.de Cc: y2039@lists.linaro.org, linux-kernel@vger.kernel.org, bamvor.zhangjian@linaro.org Subject: [RFC PATCH v2 4/4] y2038: convert ppdev to 2038 safe Date: Mon, 29 Jun 2015 22:23:27 +0800 Message-Id: <1435587807-10008-5-git-send-email-bamvor.zhangjian@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1435587807-10008-1-git-send-email-bamvor.zhangjian@linaro.org> References: <1435587807-10008-1-git-send-email-bamvor.zhangjian@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: bamvor.zhangjian@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Convert ppdev use 64bit time_t internally by replacing timeval to timeval64. In order to migrate to y2038 safe, split ioctl command PP[SG]ETTIME to PP[SG]ETTIME64(y2038 safe) and PP[SG]ETTIME32 (the legacy behavior in 32bit application). The 32bit application should make use of PP[SG]ETTIME64 and __kernel_timeval to migrate to time64_t. Signed-off-by: Bamvor Zhang Jian --- drivers/char/ppdev.c | 32 +++++++++++++++++++++++++------- include/uapi/linux/ppdev.h | 14 ++++++++++++-- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c index 9207658..a103d3d 100644 --- a/drivers/char/ppdev.c +++ b/drivers/char/ppdev.c @@ -497,8 +497,9 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg) unsigned char mask; int mode; int ret; - struct timeval par_timeout; + struct timeval64 par_timeout; long to_jiffies; + int is_not_compat_timeval = 0; case PPRSTATUS: reg = parport_read_status (port); @@ -593,9 +594,17 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg) atomic_sub (ret, &pp->irqc); return 0; - case PPSETTIME: - if (copy_from_user (&par_timeout, argp, sizeof(struct timeval))) { - return -EFAULT; + case PPSETTIME64: + is_not_compat_timeval = 1; + case PPSETTIME32: + if (is_not_compat_timeval) { + if (get_timeval64(&par_timeout, argp)) { + return -EFAULT; + } + } else { + if (compat_get_timeval64(&par_timeout, argp)) { + return -EFAULT; + } } /* Convert to jiffies, place in pp->pdev->timeout */ if ((par_timeout.tv_sec < 0) || (par_timeout.tv_usec < 0)) { @@ -609,13 +618,22 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg) pp->pdev->timeout = to_jiffies; return 0; - case PPGETTIME: + case PPGETTIME64: + is_not_compat_timeval = 1; + case PPGETTIME32: to_jiffies = pp->pdev->timeout; memset(&par_timeout, 0, sizeof(par_timeout)); par_timeout.tv_sec = to_jiffies / HZ; par_timeout.tv_usec = (to_jiffies % (long)HZ) * (1000000/HZ); - if (copy_to_user (argp, &par_timeout, sizeof(struct timeval))) - return -EFAULT; + if (is_not_compat_timeval) { + if (put_timeval64(&par_timeout, argp)) { + return -EFAULT; + } + } else { + if (compat_put_timeval64(&par_timeout, argp)) { + return -EFAULT; + } + } return 0; default: diff --git a/include/uapi/linux/ppdev.h b/include/uapi/linux/ppdev.h index dc18c5d..d62a47d 100644 --- a/include/uapi/linux/ppdev.h +++ b/include/uapi/linux/ppdev.h @@ -74,8 +74,18 @@ struct ppdev_frob_struct { #define PPSETPHASE _IOW(PP_IOCTL, 0x94, int) /* Set and get port timeout (struct timeval's) */ -#define PPGETTIME _IOR(PP_IOCTL, 0x95, struct timeval) -#define PPSETTIME _IOW(PP_IOCTL, 0x96, struct timeval) +/* Force application use 64 time_t ioctl */ +/* TODO: It is an open question about we should use a __xxx_timeval or an + * implicit array. + * replace struct __kernel_timeval with __s32[4] + * replace struct compat_timeval with __s32[2] + */ +#define PPGETTIME PPGETTIME64 +#define PPSETTIME PPSETTIME64 +#define PPGETTIME64 _IOR(PP_IOCTL, 0x95, struct __kernel_timeval) +#define PPSETTIME64 _IOW(PP_IOCTL, 0x96, struct __kernel_timeval) +#define PPGETTIME32 _IOR(PP_IOCTL, 0x9c, struct __kernel_compat_timeval) +#define PPSETTIME32 _IOW(PP_IOCTL, 0x9d, struct __kernel_compat_timeval) /* Get available modes (what the hardware can do) */ #define PPGETMODES _IOR(PP_IOCTL, 0x97, unsigned int)