From patchwork Fri Jan 11 21:48:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 14009 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 96F6823E1F for ; Fri, 11 Jan 2013 21:49:20 +0000 (UTC) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by fiordland.canonical.com (Postfix) with ESMTP id 4117CA19753 for ; Fri, 11 Jan 2013 21:49:20 +0000 (UTC) Received: by mail-vc0-f179.google.com with SMTP id p1so1864731vcq.24 for ; Fri, 11 Jan 2013 13:49:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:mime-version:content-type :content-transfer-encoding:x-gm-message-state; bh=sP3E1e4bLzlKi3G7cqCuIQ4ev13Nab7iImhvPlJrSqc=; b=hj53pK6O0LyXlB92SgVgl/OyhbO57Svj0yikmIV60BXSJXbSXIgjaEioYA1OAv+jyf P7UMOoMiiUNPK342kaiuPQI5qccO14D3njOHWIYtqLGotfbJZdwUfJY5RzuywLdR4K1z Bp/Nykr+4Jm8PkzrgaVAMTvZUbuCVs71/LUUeqyswMHP6q14SIBWxioycFLUg7/5/Ein PsU4d6g/jeaVNHLwwi+xpRHFwTxz9cWk021g0/ajiWHIvvOyizSYN2Vh7GxFW6BwfygE MJ2t3fAdtgEByRP3zRnfMt4hdBnd+Q3BCOuInjFxm4uGhmXgiFazPU5jBcYxL/EbdeyY 9taQ== X-Received: by 10.58.196.196 with SMTP id io4mr98279707vec.22.1357940959747; Fri, 11 Jan 2013 13:49:19 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.145.101 with SMTP id st5csp133431veb; Fri, 11 Jan 2013 13:49:19 -0800 (PST) X-Received: by 10.68.197.197 with SMTP id iw5mr230016948pbc.22.1357940958765; Fri, 11 Jan 2013 13:49:18 -0800 (PST) Received: from mail-pa0-f49.google.com (mail-pa0-f49.google.com [209.85.220.49]) by mx.google.com with ESMTPS id ac7si6197631pbd.223.2013.01.11.13.49.18 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 11 Jan 2013 13:49:18 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.49 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.220.49; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.49 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) smtp.mail=john.stultz@linaro.org Received: by mail-pa0-f49.google.com with SMTP id bi1so1233897pad.8 for ; Fri, 11 Jan 2013 13:49:18 -0800 (PST) X-Received: by 10.68.130.170 with SMTP id of10mr231855612pbb.131.1357940958245; Fri, 11 Jan 2013 13:49:18 -0800 (PST) Received: from localhost.localdomain (c-24-21-54-107.hsd1.or.comcast.net. [24.21.54.107]) by mx.google.com with ESMTPS id j9sm3771525paw.2.2013.01.11.13.49.17 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 11 Jan 2013 13:49:17 -0800 (PST) From: John Stultz To: linux-kernel@vger.kernel.org Cc: John Stultz , Greg KH , Serban Constantinescu , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Android Kernel Team Subject: [RFC][PATCH 2/2] staging: alarm-dev: Implement compat_ioctl support Date: Fri, 11 Jan 2013 13:48:38 -0800 Message-Id: <1357940918-14941-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1357940918-14941-1-git-send-email-john.stultz@linaro.org> References: <1357940918-14941-1-git-send-email-john.stultz@linaro.org> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQkzOc5GmSnXNaTCSnD9mGSwTJf1kCUnyr3caCao7/2mWNzOoORsFdOFdSM9mXbDq6JqF1Ls Implement compat_ioctl support for the alarm-dev ioctl. The only really iffy bit here is that the ANDROID_ALARM_SET_OLD and ANDROID_ALARM_SET_AND_WAIT_OLD support, which is there for older Android compatability uses a time_t. On 64bit, this size matches the compat_timespec size, causing ioctl number aliasing. However, since the _OLD ioctls are only there to support existing Android applications (all of which I'm assuming are 32bit), I've made the _OLD ioctls 32bit only (so on 64bit we only support the compat implementation). Cc: Greg KH Cc: Serban Constantinescu Cc: Arve Hjønnevåg Cc: Android Kernel Team Signed-off-by: John Stultz --- drivers/staging/android/alarm-dev.c | 48 +++++++++++++++++++++++++++++++ drivers/staging/android/android_alarm.h | 19 ++++++++++++ 2 files changed, 67 insertions(+) diff --git a/drivers/staging/android/alarm-dev.c b/drivers/staging/android/alarm-dev.c index 12c570d..c8589bf 100644 --- a/drivers/staging/android/alarm-dev.c +++ b/drivers/staging/android/alarm-dev.c @@ -42,9 +42,15 @@ do { \ ANDROID_ALARM_RTC_WAKEUP_MASK | \ ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP_MASK) +#ifdef CONFIG_COMPAT +/* Compat only on 64bit! */ +#define ANDROID_ALARM_SET_OLD _IOW('a', 2, compat_time_t) +#define ANDROID_ALARM_SET_AND_WAIT_OLD _IOW('a', 3, compat_time_t) +#else /* support old userspace code */ #define ANDROID_ALARM_SET_OLD _IOW('a', 2, time_t) /* set alarm */ #define ANDROID_ALARM_SET_AND_WAIT_OLD _IOW('a', 3, time_t) +#endif static int alarm_opened; static DEFINE_SPINLOCK(alarm_slock); @@ -288,6 +294,45 @@ static long alarm_ioctl(struct file *file, unsigned int cmd, unsigned long arg) return rv; } +#ifdef CONFIG_COMPAT +static long alarm_compat_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) +{ + + struct timespec ts; + int rv; + + switch (ANDROID_ALARM_BASE_CMD(cmd)) { + case ANDROID_ALARM_SET_OLD: + case ANDROID_ALARM_SET_AND_WAIT_OLD: + if (get_user(ts.tv_sec, (int __user *)arg)) + return -EFAULT; + + ts.tv_nsec = 0; + break; + case ANDROID_ALARM_SET_AND_WAIT_COMPAT(0): + case ANDROID_ALARM_SET_COMPAT(0): + case ANDROID_ALARM_SET_RTC_COMPAT: + if (compat_get_timespec(&ts, (void __user *)arg)) + return -EFAULT; + /* fall through */ + case ANDROID_ALARM_GET_TIME_COMPAT(0): + cmd = ANDROID_ALARM_COMPAT_TO_NORM(cmd); + break; + } + + rv = alarm_do_ioctl(file, cmd, &ts); + + switch (ANDROID_ALARM_BASE_CMD(cmd)) { + case ANDROID_ALARM_GET_TIME(0): /* NOTE: we modified cmd above */ + if (compat_put_timespec(&ts, (void __user *)arg)) + return -EFAULT; + break; + } + + return rv; +} +#endif static int alarm_open(struct inode *inode, struct file *file) { @@ -369,6 +414,9 @@ static const struct file_operations alarm_fops = { .unlocked_ioctl = alarm_ioctl, .open = alarm_open, .release = alarm_release, +#ifdef CONFIG_COMPAT + .compat_ioctl = alarm_compat_ioctl, +#endif }; static struct miscdevice alarm_device = { diff --git a/drivers/staging/android/android_alarm.h b/drivers/staging/android/android_alarm.h index d0cafd6..4fd32f3 100644 --- a/drivers/staging/android/android_alarm.h +++ b/drivers/staging/android/android_alarm.h @@ -18,6 +18,7 @@ #include #include +#include enum android_alarm_type { /* return code bit numbers or set alarm arg */ @@ -59,4 +60,22 @@ enum android_alarm_return_flags { #define ANDROID_ALARM_BASE_CMD(cmd) (cmd & ~(_IOC(0, 0, 0xf0, 0))) #define ANDROID_ALARM_IOCTL_TO_TYPE(cmd) (_IOC_NR(cmd) >> 4) + +#ifdef CONFIG_COMPAT +#define ANDROID_ALARM_SET_COMPAT(type) ALARM_IOW(2, type, \ + struct compat_timespec) +#define ANDROID_ALARM_SET_AND_WAIT_COMPAT(type) ALARM_IOW(3, type, \ + struct compat_timespec) +#define ANDROID_ALARM_GET_TIME_COMPAT(type) ALARM_IOW(4, type, \ + struct compat_timespec) +#define ANDROID_ALARM_SET_RTC_COMPAT _IOW('a', 5, \ + struct compat_timespec) +#define ANDROID_ALARM_IOCTL_NR(cmd) (_IOC_NR(cmd) & ((1<<4)-1)) +#define ANDROID_ALARM_COMPAT_TO_NORM(cmd) \ + ALARM_IOW(ANDROID_ALARM_IOCTL_NR(cmd), \ + ANDROID_ALARM_IOCTL_TO_TYPE(cmd), \ + struct timespec) + +#endif + #endif