acpi-wmi: Unmark as 'experimental'
[safe/jmp/linux-2.6] / drivers / char / amiserial.c
index 7b02bf1..a58869e 100644 (file)
@@ -170,7 +170,7 @@ static __inline__ void rtsdtr_ctrl(int bits)
  */
 static void rs_stop(struct tty_struct *tty)
 {
-       struct async_struct *info = (struct async_struct *)tty->driver_data;
+       struct async_struct *info = tty->driver_data;
        unsigned long flags;
 
        if (serial_paranoia_check(info, tty->name, "rs_stop"))
@@ -190,7 +190,7 @@ static void rs_stop(struct tty_struct *tty)
 
 static void rs_start(struct tty_struct *tty)
 {
-       struct async_struct *info = (struct async_struct *)tty->driver_data;
+       struct async_struct *info = tty->driver_data;
        unsigned long flags;
 
        if (serial_paranoia_check(info, tty->name, "rs_start"))
@@ -832,38 +832,36 @@ static void change_speed(struct async_struct *info,
        local_irq_restore(flags);
 }
 
-static void rs_put_char(struct tty_struct *tty, unsigned char ch)
+static int rs_put_char(struct tty_struct *tty, unsigned char ch)
 {
        struct async_struct *info;
        unsigned long flags;
 
-       if (!tty)
-               return;
-
        info = tty->driver_data;
 
        if (serial_paranoia_check(info, tty->name, "rs_put_char"))
-               return;
+               return 0;
 
        if (!info->xmit.buf)
-               return;
+               return 0;
 
        local_irq_save(flags);
        if (CIRC_SPACE(info->xmit.head,
                       info->xmit.tail,
                       SERIAL_XMIT_SIZE) == 0) {
                local_irq_restore(flags);
-               return;
+               return 0;
        }
 
        info->xmit.buf[info->xmit.head++] = ch;
        info->xmit.head &= SERIAL_XMIT_SIZE-1;
        local_irq_restore(flags);
+       return 1;
 }
 
 static void rs_flush_chars(struct tty_struct *tty)
 {
-       struct async_struct *info = (struct async_struct *)tty->driver_data;
+       struct async_struct *info = tty->driver_data;
        unsigned long flags;
 
        if (serial_paranoia_check(info, tty->name, "rs_flush_chars"))
@@ -891,9 +889,6 @@ static int rs_write(struct tty_struct * tty, const unsigned char *buf, int count
        struct async_struct *info;
        unsigned long flags;
 
-       if (!tty)
-               return 0;
-
        info = tty->driver_data;
 
        if (serial_paranoia_check(info, tty->name, "rs_write"))
@@ -939,7 +934,7 @@ static int rs_write(struct tty_struct * tty, const unsigned char *buf, int count
 
 static int rs_write_room(struct tty_struct *tty)
 {
-       struct async_struct *info = (struct async_struct *)tty->driver_data;
+       struct async_struct *info = tty->driver_data;
 
        if (serial_paranoia_check(info, tty->name, "rs_write_room"))
                return 0;
@@ -948,7 +943,7 @@ static int rs_write_room(struct tty_struct *tty)
 
 static int rs_chars_in_buffer(struct tty_struct *tty)
 {
-       struct async_struct *info = (struct async_struct *)tty->driver_data;
+       struct async_struct *info = tty->driver_data;
 
        if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer"))
                return 0;
@@ -957,7 +952,7 @@ static int rs_chars_in_buffer(struct tty_struct *tty)
 
 static void rs_flush_buffer(struct tty_struct *tty)
 {
-       struct async_struct *info = (struct async_struct *)tty->driver_data;
+       struct async_struct *info = tty->driver_data;
        unsigned long flags;
 
        if (serial_paranoia_check(info, tty->name, "rs_flush_buffer"))
@@ -974,7 +969,7 @@ static void rs_flush_buffer(struct tty_struct *tty)
  */
 static void rs_send_xchar(struct tty_struct *tty, char ch)
 {
-       struct async_struct *info = (struct async_struct *)tty->driver_data;
+       struct async_struct *info = tty->driver_data;
         unsigned long flags;
 
        if (serial_paranoia_check(info, tty->name, "rs_send_char"))
@@ -1009,7 +1004,7 @@ static void rs_send_xchar(struct tty_struct *tty, char ch)
  */
 static void rs_throttle(struct tty_struct * tty)
 {
-       struct async_struct *info = (struct async_struct *)tty->driver_data;
+       struct async_struct *info = tty->driver_data;
        unsigned long flags;
 #ifdef SERIAL_DEBUG_THROTTLE
        char    buf[64];
@@ -1034,7 +1029,7 @@ static void rs_throttle(struct tty_struct * tty)
 
 static void rs_unthrottle(struct tty_struct * tty)
 {
-       struct async_struct *info = (struct async_struct *)tty->driver_data;
+       struct async_struct *info = tty->driver_data;
        unsigned long flags;
 #ifdef SERIAL_DEBUG_THROTTLE
        char    buf[64];
@@ -1074,6 +1069,7 @@ static int get_serial_info(struct async_struct * info,
        if (!retinfo)
                return -EFAULT;
        memset(&tmp, 0, sizeof(tmp));
+       lock_kernel();
        tmp.type = state->type;
        tmp.line = state->line;
        tmp.port = state->port;
@@ -1084,6 +1080,7 @@ static int get_serial_info(struct async_struct * info,
        tmp.close_delay = state->close_delay;
        tmp.closing_wait = state->closing_wait;
        tmp.custom_divisor = state->custom_divisor;
+       unlock_kernel();
        if (copy_to_user(retinfo,&tmp,sizeof(*retinfo)))
                return -EFAULT;
        return 0;
@@ -1099,13 +1096,17 @@ static int set_serial_info(struct async_struct * info,
 
        if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
                return -EFAULT;
+
+       lock_kernel();
        state = info->state;
        old_state = *state;
   
        change_irq = new_serial.irq != state->irq;
        change_port = (new_serial.port != state->port);
-       if(change_irq || change_port || (new_serial.xmit_fifo_size != state->xmit_fifo_size))
+       if(change_irq || change_port || (new_serial.xmit_fifo_size != state->xmit_fifo_size)) {
+         unlock_kernel();
          return -EINVAL;
+       }
   
        if (!serial_isroot()) {
                if ((new_serial.baud_base != state->baud_base) ||
@@ -1122,8 +1123,10 @@ static int set_serial_info(struct async_struct * info,
                goto check_and_exit;
        }
 
-       if (new_serial.baud_base < 9600)
+       if (new_serial.baud_base < 9600) {
+               unlock_kernel();
                return -EINVAL;
+       }
 
        /*
         * OK, past this point, all the error checking has been done.
@@ -1157,6 +1160,7 @@ check_and_exit:
                }
        } else
                retval = startup(info);
+       unlock_kernel();
        return retval;
 }
 
@@ -1190,7 +1194,7 @@ static int get_lsr_info(struct async_struct * info, unsigned int __user *value)
 
 static int rs_tiocmget(struct tty_struct *tty, struct file *file)
 {
-       struct async_struct * info = (struct async_struct *)tty->driver_data;
+       struct async_struct * info = tty->driver_data;
        unsigned char control, status;
        unsigned long flags;
 
@@ -1213,7 +1217,7 @@ static int rs_tiocmget(struct tty_struct *tty, struct file *file)
 static int rs_tiocmset(struct tty_struct *tty, struct file *file,
                       unsigned int set, unsigned int clear)
 {
-       struct async_struct * info = (struct async_struct *)tty->driver_data;
+       struct async_struct * info = tty->driver_data;
        unsigned long flags;
 
        if (serial_paranoia_check(info, tty->name, "rs_ioctl"))
@@ -1238,13 +1242,13 @@ static int rs_tiocmset(struct tty_struct *tty, struct file *file,
 /*
  * rs_break() --- routine which turns the break handling on or off
  */
-static void rs_break(struct tty_struct *tty, int break_state)
+static int rs_break(struct tty_struct *tty, int break_state)
 {
-       struct async_struct * info = (struct async_struct *)tty->driver_data;
+       struct async_struct * info = tty->driver_data;
        unsigned long flags;
 
        if (serial_paranoia_check(info, tty->name, "rs_break"))
-               return;
+               return -EINVAL;
 
        local_irq_save(flags);
        if (break_state == -1)
@@ -1253,13 +1257,14 @@ static void rs_break(struct tty_struct *tty, int break_state)
          custom.adkcon = AC_UARTBRK;
        mb();
        local_irq_restore(flags);
+       return 0;
 }
 
 
 static int rs_ioctl(struct tty_struct *tty, struct file * file,
                    unsigned int cmd, unsigned long arg)
 {
-       struct async_struct * info = (struct async_struct *)tty->driver_data;
+       struct async_struct * info = tty->driver_data;
        struct async_icount cprev, cnow;        /* kernel counter temps */
        struct serial_icounter_struct icount;
        void __user *argp = (void __user *)arg;
@@ -1363,7 +1368,7 @@ static int rs_ioctl(struct tty_struct *tty, struct file * file,
 
 static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
 {
-       struct async_struct *info = (struct async_struct *)tty->driver_data;
+       struct async_struct *info = tty->driver_data;
        unsigned long flags;
        unsigned int cflag = tty->termios->c_cflag;
 
@@ -1423,7 +1428,7 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
  */
 static void rs_close(struct tty_struct *tty, struct file * filp)
 {
-       struct async_struct * info = (struct async_struct *)tty->driver_data;
+       struct async_struct * info = tty->driver_data;
        struct serial_state *state;
        unsigned long flags;
 
@@ -1496,8 +1501,7 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
                rs_wait_until_sent(tty, info->timeout);
        }
        shutdown(info);
-       if (tty->driver->flush_buffer)
-               tty->driver->flush_buffer(tty);
+       rs_flush_buffer(tty);
                
        tty_ldisc_flush(tty);
        tty->closing = 0;
@@ -1519,7 +1523,7 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
  */
 static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
 {
-       struct async_struct * info = (struct async_struct *)tty->driver_data;
+       struct async_struct * info = tty->driver_data;
        unsigned long orig_jiffies, char_time;
        int lsr;
 
@@ -1530,6 +1534,8 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
                return; /* Just in case.... */
 
        orig_jiffies = jiffies;
+
+       lock_kernel();
        /*
         * Set the check interval to be 1/5 of the estimated time to
         * send a single character, and make it at least 1.  The check
@@ -1570,6 +1576,7 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
                        break;
        }
        __set_current_state(TASK_RUNNING);
+       unlock_kernel();
 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
        printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
 #endif
@@ -1580,7 +1587,7 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
  */
 static void rs_hangup(struct tty_struct *tty)
 {
-       struct async_struct * info = (struct async_struct *)tty->driver_data;
+       struct async_struct * info = tty->driver_data;
        struct serial_state *state = info->state;
 
        if (serial_paranoia_check(info, tty->name, "rs_hangup"))
@@ -1721,12 +1728,11 @@ static int get_async_struct(int line, struct async_struct **ret_info)
                *ret_info = sstate->info;
                return 0;
        }
-       info = kmalloc(sizeof(struct async_struct), GFP_KERNEL);
+       info = kzalloc(sizeof(struct async_struct), GFP_KERNEL);
        if (!info) {
                sstate->count--;
                return -ENOMEM;
        }
-       memset(info, 0, sizeof(struct async_struct));
 #ifdef DECLARE_WAITQUEUE
        init_waitqueue_head(&info->open_wait);
        init_waitqueue_head(&info->close_wait);
@@ -1957,6 +1963,7 @@ static int __init rs_init(void)
 {
        unsigned long flags;
        struct serial_state * state;
+       int error;
 
        if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(AMI_SERIAL))
                return -ENODEV;
@@ -1969,8 +1976,11 @@ static int __init rs_init(void)
         *  We request SERDAT and SERPER only, because the serial registers are
         *  too spreaded over the custom register space
         */
-       if (!request_mem_region(CUSTOM_PHYSADDR+0x30, 4, "amiserial [Paula]"))
-               return -EBUSY;
+       if (!request_mem_region(CUSTOM_PHYSADDR+0x30, 4,
+                               "amiserial [Paula]")) {
+               error = -EBUSY;
+               goto fail_put_tty_driver;
+       }
 
        IRQ_ports = NULL;
 
@@ -1991,8 +2001,9 @@ static int __init rs_init(void)
        serial_driver->flags = TTY_DRIVER_REAL_RAW;
        tty_set_operations(serial_driver, &serial_ops);
 
-       if (tty_register_driver(serial_driver))
-               panic("Couldn't register serial driver\n");
+       error = tty_register_driver(serial_driver);
+       if (error)
+               goto fail_release_mem_region;
 
        state = rs_table;
        state->magic = SSTATE_MAGIC;
@@ -2018,8 +2029,14 @@ static int __init rs_init(void)
        local_irq_save(flags);
 
        /* set ISRs, and then disable the rx interrupts */
-       request_irq(IRQ_AMIGA_TBE, ser_tx_int, 0, "serial TX", state);
-       request_irq(IRQ_AMIGA_RBF, ser_rx_int, IRQF_DISABLED, "serial RX", state);
+       error = request_irq(IRQ_AMIGA_TBE, ser_tx_int, 0, "serial TX", state);
+       if (error)
+               goto fail_unregister;
+
+       error = request_irq(IRQ_AMIGA_RBF, ser_rx_int, IRQF_DISABLED,
+                           "serial RX", state);
+       if (error)
+               goto fail_free_irq;
 
        /* turn off Rx and Tx interrupts */
        custom.intena = IF_RBF | IF_TBE;
@@ -2039,6 +2056,16 @@ static int __init rs_init(void)
        ciab.ddra &= ~(SER_DCD | SER_CTS | SER_DSR);  /* inputs */
 
        return 0;
+
+fail_free_irq:
+       free_irq(IRQ_AMIGA_TBE, state);
+fail_unregister:
+       tty_unregister_driver(serial_driver);
+fail_release_mem_region:
+       release_mem_region(CUSTOM_PHYSADDR+0x30, 4);
+fail_put_tty_driver:
+       put_tty_driver(serial_driver);
+       return error;
 }
 
 static __exit void rs_exit(void) 
@@ -2058,6 +2085,9 @@ static __exit void rs_exit(void)
          kfree(info);
        }
 
+       free_irq(IRQ_AMIGA_TBE, rs_table);
+       free_irq(IRQ_AMIGA_RBF, rs_table);
+
        release_mem_region(CUSTOM_PHYSADDR+0x30, 4);
 }
 
@@ -2065,12 +2095,13 @@ module_init(rs_init)
 module_exit(rs_exit)
 
 
+#if defined(CONFIG_SERIAL_CONSOLE) && !defined(MODULE)
+
 /*
  * ------------------------------------------------------------
  * Serial console driver
  * ------------------------------------------------------------
  */
-#ifdef CONFIG_SERIAL_CONSOLE
 
 static void amiga_serial_putc(char c)
 {
@@ -2124,6 +2155,7 @@ static int __init amiserial_console_init(void)
        return 0;
 }
 console_initcall(amiserial_console_init);
-#endif
+
+#endif /* CONFIG_SERIAL_CONSOLE && !MODULE */
 
 MODULE_LICENSE("GPL");