* [PATCH] Input: serport: Add compat_ioctl routine to support 32bit inputtattach in 64bit systems
@ 2014-09-05 13:04 John Sung
2014-09-08 21:28 ` Dmitry Torokhov
0 siblings, 1 reply; 2+ messages in thread
From: John Sung @ 2014-09-05 13:04 UTC (permalink / raw)
To: Dmitry Torokhov, linux-input, linux-kernel; +Cc: penmount.touch
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.
Signed-off-by: John Sung <penmount.touch@gmail.com>
---
drivers/input/serio/serport.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c
index 0cb7ef5..4b68c29 100644
--- a/drivers/input/serio/serport.c
+++ b/drivers/input/serio/serport.c
@@ -22,6 +22,8 @@
#include <linux/serio.h>
#include <linux/tty.h>
+#include <asm/compat.h>
+
MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
MODULE_DESCRIPTION("Input device TTY line discipline");
MODULE_LICENSE("GPL");
@@ -31,6 +33,8 @@ MODULE_ALIAS_LDISC(N_MOUSE);
#define SERPORT_ACTIVE 2
#define SERPORT_DEAD 3
+#define SPIOCSTYPE32 (_IOW('q', 0x01, compat_ulong_t))
+
struct serport {
struct tty_struct *tty;
wait_queue_head_t wait;
@@ -221,6 +225,25 @@ static int serport_ldisc_ioctl(struct tty_struct * tty, struct file * file, unsi
return -EINVAL;
}
+static long serport_ldisc_compat_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 == SPIOCSTYPE32) {
+ 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 -EINVAL;
+}
+
static void serport_ldisc_write_wakeup(struct tty_struct * tty)
{
struct serport *serport = (struct serport *) tty->disc_data;
@@ -243,6 +266,7 @@ static struct tty_ldisc_ops serport_ldisc = {
.close = serport_ldisc_close,
.read = serport_ldisc_read,
.ioctl = serport_ldisc_ioctl,
+ .compat_ioctl = serport_ldisc_compat_ioctl,
.receive_buf = serport_ldisc_receive,
.write_wakeup = serport_ldisc_write_wakeup
};
--
1.7.9.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Input: serport: Add compat_ioctl routine to support 32bit inputtattach in 64bit systems
2014-09-05 13:04 [PATCH] Input: serport: Add compat_ioctl routine to support 32bit inputtattach in 64bit systems John Sung
@ 2014-09-08 21:28 ` Dmitry Torokhov
0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Torokhov @ 2014-09-08 21:28 UTC (permalink / raw)
To: John Sung; +Cc: linux-input, linux-kernel
Hi John,
On Fri, Sep 05, 2014 at 09:04:37PM +0800, John Sung wrote:
> 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.
>
> Signed-off-by: John Sung <penmount.touch@gmail.com>
> ---
> drivers/input/serio/serport.c | 24 ++++++++++++++++++++++++
> 1 file changed, 24 insertions(+)
>
> diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c
> index 0cb7ef5..4b68c29 100644
> --- a/drivers/input/serio/serport.c
> +++ b/drivers/input/serio/serport.c
> @@ -22,6 +22,8 @@
> #include <linux/serio.h>
> #include <linux/tty.h>
>
> +#include <asm/compat.h>
> +
> MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
> MODULE_DESCRIPTION("Input device TTY line discipline");
> MODULE_LICENSE("GPL");
> @@ -31,6 +33,8 @@ MODULE_ALIAS_LDISC(N_MOUSE);
> #define SERPORT_ACTIVE 2
> #define SERPORT_DEAD 3
>
> +#define SPIOCSTYPE32 (_IOW('q', 0x01, compat_ulong_t))
> +
> struct serport {
> struct tty_struct *tty;
> wait_queue_head_t wait;
> @@ -221,6 +225,25 @@ static int serport_ldisc_ioctl(struct tty_struct * tty, struct file * file, unsi
> return -EINVAL;
> }
>
> +static long serport_ldisc_compat_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 == SPIOCSTYPE32) {
> + 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 -EINVAL;
> +}
> +
> static void serport_ldisc_write_wakeup(struct tty_struct * tty)
> {
> struct serport *serport = (struct serport *) tty->disc_data;
> @@ -243,6 +266,7 @@ static struct tty_ldisc_ops serport_ldisc = {
> .close = serport_ldisc_close,
> .read = serport_ldisc_read,
> .ioctl = serport_ldisc_ioctl,
> + .compat_ioctl = serport_ldisc_compat_ioctl,
I think this, and serport_ldisc_compat_ioctl definition, should be
protected by #ifdef OCNFIG_COMPAT. Also, instea dof replicating the
ioctl definition and parsing, could we combine the code a bit?
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-09-08 21:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-05 13:04 [PATCH] Input: serport: Add compat_ioctl routine to support 32bit inputtattach in 64bit systems John Sung
2014-09-08 21:28 ` Dmitry Torokhov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).