From patchwork Tue Sep 9 05:20:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Sung X-Patchwork-Id: 4865911 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 434F9C0338 for ; Tue, 9 Sep 2014 05:26:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5A9032015D for ; Tue, 9 Sep 2014 05:26:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1D4062014A for ; Tue, 9 Sep 2014 05:26:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751625AbaIIF0j (ORCPT ); Tue, 9 Sep 2014 01:26:39 -0400 Received: from mail-pd0-f174.google.com ([209.85.192.174]:35705 "EHLO mail-pd0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751451AbaIIF0i (ORCPT ); Tue, 9 Sep 2014 01:26:38 -0400 Received: by mail-pd0-f174.google.com with SMTP id v10so8224187pde.33 for ; Mon, 08 Sep 2014 22:26:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=wkHJIuKKCBVHQ2wUAiKd2sUBCxWUfetaRKODii3hj9M=; b=Cct+9GQK0IHsA/E3fLYncxkLr0vPezbM/aSVUYQdoV4e7cVRnRMa3Q2V7Jo3Hpx6z6 B3Deo6pd/3jlgUTMmRBidg+o7ZfkoOX2OJCbkCZjmDAu68lGu2qzHATCs5sXTGE+XcQs dqwTKz1ZvhlRl9shfnaoZmSPTYCIo6wUDz269OXJ5rRfgBf3ZAxSpLFjnJTBbCopoaUb oIaTN5h1IMK+T6neyMOxnXkdUwBUAy6hLdetek6KWD5POqiXgwJI9KjP1lPvr02YFDCK NJghexrEE8DcgkKGh+a2v4W7X9Oaq0Ov8epjaCxBAkJFvYoksu+A16KktQ69ez4fHFAy VPMA== X-Received: by 10.66.65.162 with SMTP id y2mr52627634pas.55.1410240397758; Mon, 08 Sep 2014 22:26:37 -0700 (PDT) Received: from localhost.localdomain ([210.68.37.194]) by mx.google.com with ESMTPSA id zm5sm10320331pbb.76.2014.09.08.22.26.36 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 08 Sep 2014 22:26:36 -0700 (PDT) From: John Sung To: Dmitry Torokhov , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Cc: penmount.touch@gmail.com Subject: [PATCH v2] Input: serport: Add compat_ioctl routine to support 32bit inputattach in 64bit systems Date: Tue, 9 Sep 2014 13:20:28 +0800 Message-Id: <1410240028-9377-1-git-send-email-penmount.touch@gmail.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When running a 32-bit inputattach utility in a 64-bit system, there will be error code "inputattach: can't set device type". This is caused by the serport device driver not supporting compat_ioctl, so that SPIOCSTYPE ioctl fails. Changes in v2: (1) Codes of the compat_ioctl are protected by #ifdef CONFIG_COMPAT. (2) Add a new function serport_set_type() for common codes used by serport_ldisc_ioctl() and serport_ldisc_compat_ioctl(). Signed-off-by: John Sung --- drivers/input/serio/serport.c | 57 +++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c index 0cb7ef5..1decaa2 100644 --- a/drivers/input/serio/serport.c +++ b/drivers/input/serio/serport.c @@ -22,6 +22,10 @@ #include #include +#ifdef CONFIG_COMPAT +#include +#endif + MODULE_AUTHOR("Vojtech Pavlik "); MODULE_DESCRIPTION("Input device TTY line discipline"); MODULE_LICENSE("GPL"); @@ -40,6 +44,30 @@ struct serport { unsigned long flags; }; +#ifdef CONFIG_COMPAT +#define SPIOCSTYPE32 (_IOW('q', 0x01, compat_ulong_t)) +#endif + +/* + * serport_set_type() is called by serport_ldisc_ioctl() and + * serport_ldisc_compat_ioctl() to set up the serio_device_id values + */ + +static int serport_set_type(struct tty_struct *tty, unsigned long arg) +{ + struct serport *serport = (struct serport *) tty->disc_data; + unsigned long type; + + if (get_user(type, (unsigned long __user *) arg)) + return -EFAULT; + + serport->id.proto = type & 0x000000ff; + serport->id.id = (type & 0x0000ff00) >> 8; + serport->id.extra = (type & 0x00ff0000) >> 16; + + return 0; +} + /* * Callback functions from the serio code. */ @@ -204,18 +232,8 @@ static ssize_t serport_ldisc_read(struct tty_struct * tty, struct file * file, u static int serport_ldisc_ioctl(struct tty_struct * tty, struct file * file, unsigned int cmd, unsigned long arg) { - struct serport *serport = (struct serport*) tty->disc_data; - unsigned long type; - if (cmd == SPIOCSTYPE) { - if (get_user(type, (unsigned long __user *) arg)) - return -EFAULT; - - serport->id.proto = type & 0x000000ff; - serport->id.id = (type & 0x0000ff00) >> 8; - serport->id.extra = (type & 0x00ff0000) >> 16; - - return 0; + return serport_set_type(tty, arg); } return -EINVAL; @@ -232,6 +250,20 @@ static void serport_ldisc_write_wakeup(struct tty_struct * tty) spin_unlock_irqrestore(&serport->lock, flags); } +#ifdef CONFIG_COMPAT +/* + * serport_ldisc_compat_ioctl() allows to set the port protocol, and device ID + */ + +static long serport_ldisc_compat_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) +{ + if (cmd == SPIOCSTYPE32) + return serport_set_type(tty, arg); + + return -EINVAL; +} +#endif + /* * The line discipline structure. */ @@ -243,6 +275,9 @@ static struct tty_ldisc_ops serport_ldisc = { .close = serport_ldisc_close, .read = serport_ldisc_read, .ioctl = serport_ldisc_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = serport_ldisc_compat_ioctl, +#endif .receive_buf = serport_ldisc_receive, .write_wakeup = serport_ldisc_write_wakeup };