patch-2.4.8 linux/drivers/char/riscom8.c

Next file: linux/drivers/char/sbc60xxwdt.c
Previous file: linux/drivers/char/nvram.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.7/linux/drivers/char/riscom8.c linux/drivers/char/riscom8.c
@@ -24,7 +24,11 @@
  *      along with this program; if not, write to the Free Software
  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- *	Revision 1.0 
+ *	Revision 1.1
+ *
+ *	ChangeLog:
+ *	Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 27-Jun-2001
+ *	- get rid of check_region and several cleanups
  */
 
 #include <linux/module.h>
@@ -97,10 +101,18 @@
 };
 
 static struct riscom_board rc_board[RC_NBOARD] =  {
-	{ 0, RC_IOBASE1, 0, },
-	{ 0, RC_IOBASE2, 0, },
-	{ 0, RC_IOBASE3, 0, },
-	{ 0, RC_IOBASE4, 0, },
+	{
+		base:	RC_IOBASE1,
+	},
+	{
+		base:	RC_IOBASE2,
+	},
+	{
+		base:	RC_IOBASE3,
+	},
+	{
+		base:	RC_IOBASE4,
+	},
 };
 
 static struct riscom_port rc_port[RC_NBOARD * RC_NPORT];
@@ -122,9 +134,9 @@
 				    kdev_t device, const char *routine)
 {
 #ifdef RISCOM_PARANOIA_CHECK
-	static const char *badmagic =
+	static const char badmagic[] = KERN_INFO
 		"rc: Warning: bad riscom port magic number for device %s in %s\n";
-	static const char *badinfo =
+	static const char badinfo[] = KERN_INFO
 		"rc: Warning: null riscom port for device %s in %s\n";
 
 	if (!port) {
@@ -186,32 +198,29 @@
 		if (!rc_in(bp, CD180_CCR))
 			return;
 	
-	printk("rc%d: Timeout waiting for CCR.\n", board_No(bp));
+	printk(KERN_INFO "rc%d: Timeout waiting for CCR.\n", board_No(bp));
 }
 
 /*
  *  RISCom/8 probe functions.
  */
 
-static inline int rc_check_io_range(struct riscom_board * const bp)
+static inline int rc_request_io_range(struct riscom_board * const bp)
 {
 	int i;
 	
 	for (i = 0; i < RC_NIOPORT; i++)  
-		if (check_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1))  {
-			printk("rc%d: Skipping probe at 0x%03x. I/O address in use.\n",
-			       board_No(bp), bp->base);
-			return 1;
+		if (!request_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1,
+				   "RISCom/8"))  {
+			goto out_release;
 		}
 	return 0;
-}
-
-static inline void rc_request_io_range(struct riscom_board * const bp)
-{
-	int i;
-	
-	for (i = 0; i < RC_NIOPORT; i++) 
-		request_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1, "RISCom/8" );
+out_release:
+	printk(KERN_INFO "rc%d: Skipping probe at 0x%03x. IO address in use.\n",
+			 board_No(bp), bp->base);
+	while(--i >= 0)
+		release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1);
+	return 1;
 }
 
 static inline void rc_release_io_range(struct riscom_board * const bp)
@@ -221,7 +230,6 @@
 	for (i = 0; i < RC_NIOPORT; i++)  
 		release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1);
 }
-
 	
 /* Must be called with enabled interrupts */
 static inline void rc_long_delay(unsigned long delay)
@@ -265,7 +273,7 @@
 	
 	bp->irq = 0;
 
-	if (rc_check_io_range(bp))
+	if (rc_request_io_range(bp))
 		return 1;
 	
 	/* Are the I/O ports here ? */
@@ -277,9 +285,9 @@
 	val2 = rc_in(bp, CD180_PPRL);
 	
 	if ((val1 != 0x5a) || (val2 != 0xa5))  {
-		printk("rc%d: RISCom/8 Board at 0x%03x not found.\n",
+		printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not found.\n",
 		       board_No(bp), bp->base);
-		return 1;
+		goto out_release;
 	}
 	
 	/* It's time to find IRQ for this board */
@@ -297,27 +305,30 @@
 		rc_init_CD180(bp);	       		/* Reset CD180 again      */
 	
 		if ((val1 & RC_BSR_TINT) || (val2 != (RC_ID | GIVR_IT_TX)))  {
-			printk("rc%d: RISCom/8 Board at 0x%03x not found.\n",
-			       board_No(bp), bp->base);
-			return 1;
+			printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not "
+					"found.\n", board_No(bp), bp->base);
+			goto out_release;
 		}
 	}
 	
 	if (irqs <= 0)  {
-		printk("rc%d: Can't find IRQ for RISCom/8 board at 0x%03x.\n",
-		       board_No(bp), bp->base);
-		return 1;
+		printk(KERN_ERR "rc%d: Can't find IRQ for RISCom/8 board "
+				"at 0x%03x.\n", board_No(bp), bp->base);
+		goto out_release;
 	}
-	rc_request_io_range(bp);
 	bp->irq = irqs;
 	bp->flags |= RC_BOARD_PRESENT;
 	
-	printk("rc%d: RISCom/8 Rev. %c board detected at 0x%03x, IRQ %d.\n",
+	printk(KERN_INFO "rc%d: RISCom/8 Rev. %c board detected at "
+			 "0x%03x, IRQ %d.\n",
 	       board_No(bp),
 	       (rc_in(bp, CD180_GFRCR) & 0x0f) + 'A',   /* Board revision */
 	       bp->base, bp->irq);
 	
 	return 0;
+out_release:
+	rc_release_io_range(bp);
+	return 1;
 }
 
 /* 
@@ -354,7 +365,7 @@
 			return port;
 		}
 	}
-	printk("rc%d: %s interrupt from invalid port %d\n", 
+	printk(KERN_ERR "rc%d: %s interrupt from invalid port %d\n", 
 	       board_No(bp), what, channel);
 	return NULL;
 }
@@ -371,7 +382,8 @@
 
 	tty = port->tty;
 	if (tty->flip.count >= TTY_FLIPBUF_SIZE)  {
-		printk("rc%d: port %d: Working around flip buffer overflow.\n",
+		printk(KERN_WARNING "rc%d: port %d: Working around flip "
+				    "buffer overflow.\n",
 		       board_No(bp), port_No(port));
 		return;
 	}
@@ -381,7 +393,7 @@
 	if (status & RCSR_OE)  {
 		port->overrun++;
 #if 0		
-		printk("rc%d: port %d: Overrun. Total %ld overruns.\n", 
+		printk(KERN_ERR "rc%d: port %d: Overrun. Total %ld overruns\n", 
 		       board_No(bp), port_No(port), port->overrun);
 #endif		
 	}
@@ -394,12 +406,13 @@
 		return;
 	}
 	if (status & RCSR_TOUT)  {
-		printk("rc%d: port %d: Receiver timeout. Hardware problems ?\n", 
+		printk(KERN_WARNING "rc%d: port %d: Receiver timeout. "
+				    "Hardware problems ?\n", 
 		       board_No(bp), port_No(port));
 		return;
 		
 	} else if (status & RCSR_BREAK)  {
-		printk("rc%d: port %d: Handling break...\n",
+		printk(KERN_INFO "rc%d: port %d: Handling break...\n",
 		       board_No(bp), port_No(port));
 		*tty->flip.flag_buf_ptr++ = TTY_BREAK;
 		if (port->flags & ASYNC_SAK)
@@ -441,7 +454,8 @@
 	
 	while (count--)  {
 		if (tty->flip.count >= TTY_FLIPBUF_SIZE)  {
-			printk("rc%d: port %d: Working around flip buffer overflow.\n",
+			printk(KERN_WARNING "rc%d: port %d: Working around "
+					    "flip buffer overflow.\n",
 			       board_No(bp), port_No(port));
 			break;
 		}
@@ -594,7 +608,8 @@
 				  RC_BSR_MINT | RC_BSR_RINT))) {
 	
 		if (status & RC_BSR_TOUT) 
-			printk("rc%d: Got timeout. Hardware error ?\n", board_No(bp));
+			printk(KERN_WARNING "rc%d: Got timeout. Hardware "
+					    "error?\n", board_No(bp));
 		
 		else if (status & RC_BSR_RINT) {
 			ack = rc_in(bp, RC_ACK_RINT);
@@ -604,7 +619,8 @@
 			else if (ack == (RC_ID | GIVR_IT_REXC))
 				rc_receive_exc(bp);
 			else
-				printk("rc%d: Bad receive ack 0x%02x.\n",
+				printk(KERN_WARNING "rc%d: Bad receive ack "
+						    "0x%02x.\n",
 				       board_No(bp), ack);
 		
 		} else if (status & RC_BSR_TINT) {
@@ -613,7 +629,8 @@
 			if (ack == (RC_ID | GIVR_IT_TX))
 				rc_transmit(bp);
 			else
-				printk("rc%d: Bad transmit ack 0x%02x.\n",
+				printk(KERN_WARNING "rc%d: Bad transmit ack "
+						    "0x%02x.\n",
 				       board_No(bp), ack);
 		
 		} else /* if (status & RC_BSR_MINT) */ {
@@ -622,7 +639,8 @@
 			if (ack == (RC_ID | GIVR_IT_MODEM)) 
 				rc_check_modem(bp);
 			else
-				printk("rc%d: Bad modem ack 0x%02x.\n",
+				printk(KERN_WARNING "rc%d: Bad modem ack "
+						    "0x%02x.\n",
 				       board_No(bp), ack);
 		
 		} 
@@ -644,7 +662,8 @@
 	if (bp->flags & RC_BOARD_ACTIVE) 
 		return 0;
 	
-	error = request_irq(bp->irq, rc_interrupt, SA_INTERRUPT, "RISCom/8", NULL);
+	error = request_irq(bp->irq, rc_interrupt, SA_INTERRUPT,
+			    "RISCom/8", NULL);
 	if (error) 
 		return error;
 	
@@ -892,14 +911,14 @@
 		return;
 	
 #ifdef RC_REPORT_OVERRUN
-	printk("rc%d: port %d: Total %ld overruns were detected.\n",
+	printk(KERN_INFO "rc%d: port %d: Total %ld overruns were detected.\n",
 	       board_No(bp), port_No(port), port->overrun);
 #endif	
 #ifdef RC_REPORT_FIFO
 	{
 		int i;
 		
-		printk("rc%d: port %d: FIFO hits [ ",
+		printk(KERN_INFO "rc%d: port %d: FIFO hits [ ",
 		       board_No(bp), port_No(port));
 		for (i = 0; i < 10; i++)  {
 			printk("%ld ", port->hits[i]);
@@ -932,7 +951,8 @@
 	port->flags &= ~ASYNC_INITIALIZED;
 	
 	if (--bp->count < 0)  {
-		printk("rc%d: rc_shutdown_port: bad board count: %d\n",
+		printk(KERN_INFO "rc%d: rc_shutdown_port: "
+				 "bad board count: %d\n",
 		       board_No(bp), bp->count);
 		bp->count = 0;
 	}
@@ -1118,27 +1138,24 @@
 		return;
 	
 	save_flags(flags); cli();
-	if (tty_hung_up_p(filp))  {
-		restore_flags(flags);
-		return;
-	}
+	if (tty_hung_up_p(filp))
+		goto out;
 	
 	bp = port_Board(port);
 	if ((tty->count == 1) && (port->count != 1))  {
-		printk("rc%d: rc_close: bad port count;"
+		printk(KERN_INFO "rc%d: rc_close: bad port count;"
 		       " tty->count is 1, port count is %d\n",
 		       board_No(bp), port->count);
 		port->count = 1;
 	}
 	if (--port->count < 0)  {
-		printk("rc%d: rc_close: bad port count for tty%d: %d\n",
+		printk(KERN_INFO "rc%d: rc_close: bad port count "
+				 "for tty%d: %d\n",
 		       board_No(bp), port_No(port), port->count);
 		port->count = 0;
 	}
-	if (port->count)  {
-		restore_flags(flags);
-		return;
-	}
+	if (port->count)
+		goto out;
 	port->flags |= ASYNC_CLOSING;
 	/*
 	 * Save the termios structure, since this port may have
@@ -1198,7 +1215,7 @@
 	port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|
 			 ASYNC_CLOSING);
 	wake_up_interruptible(&port->close_wait);
-	restore_flags(flags);
+out:	restore_flags(flags);
 }
 
 static int rc_write(struct tty_struct * tty, int from_user, 
@@ -1293,15 +1310,13 @@
 
 	save_flags(flags); cli();
 	
-	if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {
-		restore_flags(flags);
-		return;
-	}
+	if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
+		goto out;
 
 	port->xmit_buf[port->xmit_head++] = ch;
 	port->xmit_head &= SERIAL_XMIT_SIZE - 1;
 	port->xmit_cnt++;
-	restore_flags(flags);
+out:	restore_flags(flags);
 }
 
 static void rc_flush_chars(struct tty_struct * tty)
@@ -1383,21 +1398,18 @@
 		| ((status & MSVR_CD)  ? TIOCM_CAR : 0)
 		| ((status & MSVR_DSR) ? TIOCM_DSR : 0)
 		| ((status & MSVR_CTS) ? TIOCM_CTS : 0);
-	put_user(result, value);
-	return 0;
+	return put_user(result, value);
 }
 
 static int rc_set_modem_info(struct riscom_port * port, unsigned int cmd,
 			     unsigned int *value)
 {
-	int error;
 	unsigned int arg;
 	unsigned long flags;
 	struct riscom_board *bp = port_Board(port);
 
-	error = get_user(arg, value);
-	if (error) 
-		return error;
+	if (get_user(arg, value))
+		return -EFAULT;
 	switch (cmd) {
 	 case TIOCMBIS: 
 		if (arg & TIOCM_RTS) 
@@ -1453,12 +1465,9 @@
 	struct riscom_board *bp = port_Board(port);
 	int change_speed;
 	unsigned long flags;
-	int error;
 	
-	error = verify_area(VERIFY_READ, (void *) newinfo, sizeof(tmp));
-	if (error)
-		return error;
-	copy_from_user(&tmp, newinfo, sizeof(tmp));
+	if (copy_from_user(&tmp, newinfo, sizeof(tmp)))
+		return -EFAULT;
 	
 #if 0	
 	if ((tmp.irq != bp->irq) ||
@@ -1501,11 +1510,6 @@
 {
 	struct serial_struct tmp;
 	struct riscom_board *bp = port_Board(port);
-	int error;
-	
-	error = verify_area(VERIFY_WRITE, (void *) retinfo, sizeof(tmp));
-	if (error)
-		return error;
 	
 	memset(&tmp, 0, sizeof(tmp));
 	tmp.type = PORT_CIRRUS;
@@ -1517,8 +1521,7 @@
 	tmp.close_delay = port->close_delay * HZ/100;
 	tmp.closing_wait = port->closing_wait * HZ/100;
 	tmp.xmit_fifo_size = CD180_NFIFO;
-	copy_to_user(retinfo, &tmp, sizeof(tmp));
-	return 0;
+	return copy_to_user(retinfo, &tmp, sizeof(tmp)) ? -EFAULT : 0;
 }
 
 static int rc_ioctl(struct tty_struct * tty, struct file * filp, 
@@ -1526,7 +1529,6 @@
 		    
 {
 	struct riscom_port *port = (struct riscom_port *)tty->driver_data;
-	int error;
 	int retval;
 				
 	if (rc_paranoia_check(port, tty->device, "rc_ioctl"))
@@ -1540,29 +1542,24 @@
 		tty_wait_until_sent(tty, 0);
 		if (!arg)
 			rc_send_break(port, HZ/4);	/* 1/4 second */
-		return 0;
+		break;
 	 case TCSBRKP:	/* support for POSIX tcsendbreak() */
 		retval = tty_check_change(tty);
 		if (retval)
 			return retval;
 		tty_wait_until_sent(tty, 0);
 		rc_send_break(port, arg ? arg*(HZ/10) : HZ/4);
-		return 0;
+		break;
 	 case TIOCGSOFTCAR:
 		return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned int *) arg);
 	 case TIOCSSOFTCAR:
-		retval = get_user(arg,(unsigned int *) arg);
-		if (retval)
-			return retval;
+		if (get_user(arg,(unsigned int *) arg))
+			return -EFAULT;
 		tty->termios->c_cflag =
 			((tty->termios->c_cflag & ~CLOCAL) |
 			(arg ? CLOCAL : 0));
-		return 0;
+		break;
 	 case TIOCMGET:
-		error = verify_area(VERIFY_WRITE, (void *) arg,
-				    sizeof(unsigned int));
-		if (error)
-			return error;
 		return rc_get_modem_info(port, (unsigned int *) arg);
 	 case TIOCMBIS:
 	 case TIOCMBIC:
@@ -1751,7 +1748,7 @@
 
 	
 	if (!(tmp_buf = (unsigned char *) get_free_page(GFP_KERNEL))) {
-		printk("rc: Couldn't get free page.\n");
+		printk(KERN_ERR "rc: Couldn't get free page.\n");
 		return 1;
 	}
 	init_bh(RISCOM8_BH, do_riscom_bh);
@@ -1795,14 +1792,16 @@
 	
 	if ((error = tty_register_driver(&riscom_driver)))  {
 		free_page((unsigned long)tmp_buf);
-		printk("rc: Couldn't register RISCom/8 driver, error = %d\n",
+		printk(KERN_ERR "rc: Couldn't register RISCom/8 driver, "
+				"error = %d\n",
 		       error);
 		return 1;
 	}
 	if ((error = tty_register_driver(&riscom_callout_driver)))  {
 		free_page((unsigned long)tmp_buf);
 		tty_unregister_driver(&riscom_driver);
-		printk("rc: Couldn't register RISCom/8 callout driver, error = %d\n",
+		printk(KERN_ERR "rc: Couldn't register RISCom/8 callout "
+				"driver, error = %d\n",
 		       error);
 		return 1;
 	}
@@ -1867,6 +1866,12 @@
 __setup("riscom8=", riscom8_setup);
 #endif
 
+static char banner[] __initdata =
+	KERN_INFO "rc: SDL RISCom/8 card driver v1.1, (c) D.Gorodchanin "
+		  "1994-1996.\n";
+static char no_boards_msg[] __initdata =
+	KERN_INFO "rc: No RISCom/8 boards detected.\n";
+
 /* 
  * This routine must be called by kernel at boot time 
  */
@@ -1875,7 +1880,7 @@
 	int i;
 	int found = 0;
 
-	printk("rc: SDL RISCom/8 card driver v1.0, (c) D.Gorodchanin 1994-1996.\n");
+	printk(banner);
 
 	if (rc_init_drivers()) 
 		return -EIO;
@@ -1886,7 +1891,7 @@
 	
 	if (!found)  {
 		rc_release_drivers();
-		printk("rc: No RISCom/8 boards detected.\n");
+		printk(no_boards_msg);
 		return -EIO;
 	}
 	return 0;

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)