From patchwork Fri Jan 11 21:15:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 14007 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 F3B0823FC8 for ; Fri, 11 Jan 2013 21:15:59 +0000 (UTC) Received: from mail-vb0-f54.google.com (mail-vb0-f54.google.com [209.85.212.54]) by fiordland.canonical.com (Postfix) with ESMTP id 97FACA1851C for ; Fri, 11 Jan 2013 21:15:59 +0000 (UTC) Received: by mail-vb0-f54.google.com with SMTP id l1so1887575vba.27 for ; Fri, 11 Jan 2013 13:15:59 -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=qL1z8pN/iJPExrEnYlaGKpa1QLQhEI1ggboNLh7raLk=; b=gGPiPQgG11DJuhE66vPbjZDTRM0uJS74sRcmiGJn3X+gGzI7Qwocm3mcwfmcZ7/yms 38H7ReBCebMYhRGcQwyaURpHhcl/sqzvmwnjmeBYFgWAR4P4ybGqR+XQKjmwqVGYdDqO UFXufflgGHaDP1WpuHCbaGjjunUzh0NbqcNs2Ea+VzO76dtJDniNjPjKMXSqpR8U9R2C IHSxUYIZbM40q9LPMYDv29gb0Uun9ueXelipmnvslh9s8GO8jV+plM0PekOmIrzwy1Pz /9shiLMaOJbCp4Iwb5wnUviuitEoOJppA0dtCRuuC76O43P9BKEgfu1Uw6xP5wt265an dmww== X-Received: by 10.58.247.132 with SMTP id ye4mr98858412vec.9.1357938959108; Fri, 11 Jan 2013 13:15:59 -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 st5csp132319veb; Fri, 11 Jan 2013 13:15:58 -0800 (PST) X-Received: by 10.66.90.72 with SMTP id bu8mr210290110pab.69.1357938958001; Fri, 11 Jan 2013 13:15:58 -0800 (PST) Received: from mail-pb0-f46.google.com (mail-pb0-f46.google.com [209.85.160.46]) by mx.google.com with ESMTPS id rz7si6143635pbc.102.2013.01.11.13.15.57 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 11 Jan 2013 13:15:57 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.46 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.160.46; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.46 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-pb0-f46.google.com with SMTP id wy7so1160240pbc.33 for ; Fri, 11 Jan 2013 13:15:57 -0800 (PST) X-Received: by 10.66.79.134 with SMTP id j6mr188345100pax.11.1357938957546; Fri, 11 Jan 2013 13:15:57 -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 o5sm3728276pay.5.2013.01.11.13.15.56 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 11 Jan 2013 13:15:56 -0800 (PST) From: John Stultz To: Dave Hansen Cc: John Stultz Subject: [PATCH 2/2] staging: alarm-dev: Implement compat_ioctl support Date: Fri, 11 Jan 2013 13:15:45 -0800 Message-Id: <1357938945-14611-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1357938945-14611-1-git-send-email-john.stultz@linaro.org> References: <1357938945-14611-1-git-send-email-john.stultz@linaro.org> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQnywjoCoD6Bn8mTm9D23ZGVwc+FYN9I5bKM4SqyGQCwG+Ru4ycbLKFvl5S0JCBwNgGOnVl6 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). 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