From ee105769c36b78ca603ac3b0548b818b90a2482c Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 15 Aug 2003 18:08:31 -0700 Subject: [PATCH] [IRDA]: Fix irtty line disc and module semantics. The irda tty line discipline does not handle the new module paradigm well. This patch fixes that: - initialize line discipline as data, not with code - set module owner - make prototype for irtty_ioctl match expected arguments from tty discipline - get rid of explicit MOD_INC/MOD_DEC --- drivers/net/irda/irtty.c | 50 ++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/drivers/net/irda/irtty.c b/drivers/net/irda/irtty.c index ac61f9730711d..6bfcc312f31f4 100644 --- a/drivers/net/irda/irtty.c +++ b/drivers/net/irda/irtty.c @@ -39,8 +39,6 @@ #include #include -static struct tty_ldisc irda_ldisc; - static int qos_mtt_bits = 0x03; /* 5 ms or more */ /* Network device fuction prototypes */ @@ -54,7 +52,8 @@ static struct net_device_stats *irtty_net_get_stats(struct net_device *dev); /* Line discipline function prototypes */ static int irtty_open(struct tty_struct *tty); static void irtty_close(struct tty_struct *tty); -static int irtty_ioctl(struct tty_struct *, void *, int, void *); +static int irtty_ioctl(struct tty_struct *, struct file *, + unsigned int, unsigned long); static int irtty_receive_room(struct tty_struct *tty); static void irtty_write_wakeup(struct tty_struct *tty); static void irtty_receive_buf(struct tty_struct *, const unsigned char *, @@ -68,29 +67,22 @@ static int irtty_raw_read(struct net_device *dev, __u8 *buf, int len); static int irtty_set_mode(struct net_device *dev, int mode); static int irtty_change_speed(struct irda_task *task); -char *driver_name = "irtty"; +static struct tty_ldisc irda_ldisc = { + .owner = THIS_MODULE, + .magic = TTY_LDISC_MAGIC, + .name = "irda", + .open = irtty_open, + .close = irtty_close, + .ioctl = irtty_ioctl, + .receive_buf = irtty_receive_buf, + .receive_room = irtty_receive_room, + .write_wakeup = irtty_write_wakeup, +}; int __init irtty_init(void) { int status; - /* Fill in our line protocol discipline, and register it */ - memset(&irda_ldisc, 0, sizeof( irda_ldisc)); - - irda_ldisc.magic = TTY_LDISC_MAGIC; - irda_ldisc.name = "irda"; - irda_ldisc.flags = 0; - irda_ldisc.open = irtty_open; - irda_ldisc.close = irtty_close; - irda_ldisc.read = NULL; - irda_ldisc.write = NULL; - irda_ldisc.ioctl = (int (*)(struct tty_struct *, struct file *, - unsigned int, unsigned long)) irtty_ioctl; - irda_ldisc.poll = NULL; - irda_ldisc.receive_buf = irtty_receive_buf; - irda_ldisc.receive_room = irtty_receive_room; - irda_ldisc.write_wakeup = irtty_write_wakeup; - if ((status = tty_register_ldisc(N_IRDA, &irda_ldisc)) != 0) { ERROR("IrDA: can't register line discipline (err = %d)\n", status); @@ -234,8 +226,6 @@ static int irtty_open(struct tty_struct *tty) MESSAGE("IrDA: Registered device %s\n", dev->name); - MOD_INC_USE_COUNT; - return 0; } @@ -286,8 +276,6 @@ static void irtty_close(struct tty_struct *tty) spin_unlock_irqrestore(&self->lock, flags); kfree(self); - - MOD_DEC_USE_COUNT; } /* @@ -468,7 +456,8 @@ static int irtty_change_speed(struct irda_task *task) * The Swiss army knife of system calls :-) * */ -static int irtty_ioctl(struct tty_struct *tty, void *file, int cmd, void *arg) +static int irtty_ioctl(struct tty_struct *tty, struct file *file, + unsigned int cmd, unsigned long arg) { dongle_t *dongle; struct irtty_info info; @@ -492,8 +481,7 @@ static int irtty_ioctl(struct tty_struct *tty, void *file, int cmd, void *arg) case TCGETS: case TCGETA: /* Unsure about locking here, to check - Jean II */ - return n_tty_ioctl(tty, (struct file *) file, cmd, - (unsigned long) arg); + return n_tty_ioctl(tty, (struct file *) file, cmd, arg); break; case IRTTY_IOCTDONGLE: /* Initialize dongle */ @@ -524,7 +512,7 @@ static int irtty_ioctl(struct tty_struct *tty, void *file, int cmd, void *arg) memset(&info, 0, sizeof(struct irtty_info)); strncpy(info.name, self->netdev->name, 5); - if (copy_to_user(arg, &info, sizeof(struct irtty_info))) + if (copy_to_user((void *) arg, &info, sizeof(struct irtty_info))) return -EFAULT; break; default: @@ -941,8 +929,6 @@ static int irtty_net_open(struct net_device *dev) */ self->irlap = irlap_open(dev, &self->qos, hwname); - MOD_INC_USE_COUNT; - return 0; } @@ -964,8 +950,6 @@ static int irtty_net_close(struct net_device *dev) irlap_close(self->irlap); self->irlap = NULL; - MOD_DEC_USE_COUNT; - return 0; } -- 2.53.0