From patchwork Thu Dec 31 14:06:33 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: 59095 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp3448194lbb; Thu, 31 Dec 2015 06:07:11 -0800 (PST) X-Received: by 10.98.13.151 with SMTP id 23mr101603585pfn.48.1451570831076; Thu, 31 Dec 2015 06:07:11 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id rf10si29130492pab.94.2015.12.31.06.07.09; Thu, 31 Dec 2015 06:07:11 -0800 (PST) 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; 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; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753221AbbLaOG7 (ORCPT + 29 others); Thu, 31 Dec 2015 09:06:59 -0500 Received: from mail-pf0-f175.google.com ([209.85.192.175]:34982 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751210AbbLaOGv (ORCPT ); Thu, 31 Dec 2015 09:06:51 -0500 Received: by mail-pf0-f175.google.com with SMTP id 78so156965253pfw.2 for ; Thu, 31 Dec 2015 06:06:50 -0800 (PST) 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; bh=ufR9cDUMdCffRwLtXthr+aiVwRg2LZ7tP5A/2tdK5iY=; b=N9cRS1nRDpkM/WIlsLolqRtgqgP3IZvk3c/ZVlJyDhbAb+iyWZyeryxglvorBABR11 5q2DILYm+eWiuK7Mx9EV60fxiU0MJw5LOdVmLL4Oud2jbYcqRQ7ha6NtEf65t+VMmiwA XqjL8il987GMI37kwV+FORNwuBLZHMLeQw3Oc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ufR9cDUMdCffRwLtXthr+aiVwRg2LZ7tP5A/2tdK5iY=; b=G4WB+2UV1NXeC9TBgFAL1JrqbpbH6K5bHH8nmn7xLv/+ZgmR5TMrLqx483xfu+cIa5 6nQGDJ/uE4BI+rrcQKZEXEgfDSPc3fYzOVisMlc4V91oj+kTUoHeEULkA8yLwreTcoXv bnk7xzYNY82MrULR+rwUiKFqdfLHyAdeVEDqYzDqgLJ5BkoxrdAm+rusYr7QuiA/jRGv j+/BAyLN26ocPl5NMKEcNepA/ltOSSb/szgSPYCUhJGcKuPdGf1jqLsP6VoFmFf117CV l+tR68HZH1CpJXtg2d5jw63FZkjkKPeR5GtGidAT5CzqBRVOtQUhOcriWYGgPhySwbUM xluA== X-Gm-Message-State: ALoCoQnnzbU5U6L6fuyHKtc4h6Q8WDn1sultZSUpPrBYTQJJUGzB0KLZiOKb2nPRnPgt8v6WKR4W9/q9wgRtWhK+YKhrdQdYQA== X-Received: by 10.98.13.155 with SMTP id 27mr43687416pfn.40.1451570810668; Thu, 31 Dec 2015 06:06:50 -0800 (PST) Received: from linux-j170.lan ([211.22.145.200]) by smtp.gmail.com with ESMTPSA id k77sm15355770pfb.37.2015.12.31.06.06.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 31 Dec 2015 06:06:50 -0800 (PST) From: Bamvor Jian Zhang To: linux-kernel@vger.kernel.org Cc: y2038@lists.linaro.org, gregkh@linuxfoundation.org, arnd@arndb.de, sudipm.mukherjee@gmail.com, broonie@kernel.org, Bamvor Jian Zhang Subject: [PATCH v3 1/2] ppdev: convert to y2038 safe Date: Thu, 31 Dec 2015 22:06:33 +0800 Message-Id: <1451570794-14263-2-git-send-email-bamvor.zhangjian@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1451570794-14263-1-git-send-email-bamvor.zhangjian@linaro.org> References: <1451570794-14263-1-git-send-email-bamvor.zhangjian@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The y2038 issue for ppdev is changes of timeval in the ioctl (PPSETTIME and PPGETTIME). The size of struct timeval changes from 8bytes to 16bytes due to the changes of time_t. It lead to the changes of the command of ioctl, e.g. for PPGETTIME, We have: on 32-bit (old): 0x80087095 on 32-bit (new): 0x80107095 on 64-bit : 0x80107095 This patch define these two ioctl commands to support the 32bit and 64bit time_t application at the same time. And, introduce pp_set_timeout to remove some duplicated code. Signed-off-by: Bamvor Jian Zhang Reviewed-by: Arnd Bergmann Tested-by: Sudip Mukherjee --- drivers/char/ppdev.c | 75 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 20 deletions(-) -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c index ae0b42b..c03d998 100644 --- a/drivers/char/ppdev.c +++ b/drivers/char/ppdev.c @@ -98,6 +98,13 @@ struct pp_struct { #define ROUND_UP(x,y) (((x)+(y)-1)/(y)) static DEFINE_MUTEX(pp_do_mutex); + +/* define fixed sized ioctl cmd for y2038 migration */ +#define PPGETTIME32 _IOR(PP_IOCTL, 0x95, s32[2]) +#define PPSETTIME32 _IOW(PP_IOCTL, 0x96, s32[2]) +#define PPGETTIME64 _IOR(PP_IOCTL, 0x95, s64[2]) +#define PPSETTIME64 _IOW(PP_IOCTL, 0x96, s64[2]) + static inline void pp_enable_irq (struct pp_struct *pp) { struct parport *port = pp->pdev->port; @@ -322,6 +329,22 @@ static enum ieee1284_phase init_phase (int mode) return IEEE1284_PH_FWD_IDLE; } +static int pp_set_timeout(struct pardevice *pdev, long tv_sec, int tv_usec) +{ + long to_jiffies; + + if ((tv_sec < 0) || (tv_usec < 0)) + return -EINVAL; + + to_jiffies = usecs_to_jiffies(tv_usec); + to_jiffies += tv_sec * HZ; + if (to_jiffies <= 0) + return -EINVAL; + + pdev->timeout = to_jiffies; + return 0; +} + static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { unsigned int minor = iminor(file_inode(file)); @@ -495,9 +518,10 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg) unsigned char reg; unsigned char mask; int mode; + s32 time32[2]; + s64 time64[2]; + struct timespec64 ts; int ret; - struct timeval par_timeout; - long to_jiffies; case PPRSTATUS: reg = parport_read_status (port); @@ -592,29 +616,40 @@ 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))) { + case PPSETTIME32: + if (copy_from_user(time32, argp, sizeof(time32))) return -EFAULT; - } - /* Convert to jiffies, place in pp->pdev->timeout */ - if ((par_timeout.tv_sec < 0) || (par_timeout.tv_usec < 0)) { - return -EINVAL; - } - to_jiffies = ROUND_UP(par_timeout.tv_usec, 1000000/HZ); - to_jiffies += par_timeout.tv_sec * (long)HZ; - if (to_jiffies <= 0) { + + return pp_set_timeout(pp->pdev, time32[0], time32[1]); + + case PPSETTIME64: + if (copy_from_user(time64, argp, sizeof(time64))) + return -EFAULT; + + return pp_set_timeout(pp->pdev, time64[0], time64[1]); + + case PPGETTIME32: + jiffies_to_timespec64(pp->pdev->timeout, &ts); + time32[0] = ts.tv_sec; + time32[1] = ts.tv_nsec / NSEC_PER_USEC; + if ((time32[0] < 0) || (time32[1] < 0)) return -EINVAL; - } - pp->pdev->timeout = to_jiffies; + + if (copy_to_user(argp, time32, sizeof(time32))) + return -EFAULT; + return 0; - case PPGETTIME: - 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))) + case PPGETTIME64: + jiffies_to_timespec64(pp->pdev->timeout, &ts); + time64[0] = ts.tv_sec; + time64[1] = ts.tv_nsec / NSEC_PER_USEC; + if ((time64[0] < 0) || (time64[1] < 0)) + return -EINVAL; + + if (copy_to_user(argp, time64, sizeof(time64))) return -EFAULT; + return 0; default: