patch-2.4.7 linux/drivers/char/esp.c

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

diff -u --recursive --new-file v2.4.6/linux/drivers/char/esp.c linux/drivers/char/esp.c
@@ -32,6 +32,9 @@
  *   Support for PIO mode.  This allows the driver to work properly with
  *     multiport cards.
  *
+ * Arnaldo Carvalho de Melo <acme@conectiva.com.br> -
+ * several cleanups, use module_init/module_exit, etc
+ *
  * This module exports the following rs232 io functions:
  *
  *	int espserial_init(void);
@@ -100,8 +103,8 @@
 
 #define WAKEUP_CHARS 1024
 
-static char *serial_name = "ESP serial driver";
-static char *serial_version = "2.2";
+static char serial_name[] __initdata = "ESP serial driver";
+static char serial_version[] __initdata = "2.2";
 
 static DECLARE_TASK_QUEUE(tq_esp);
 
@@ -174,9 +177,9 @@
 					kdev_t device, const char *routine)
 {
 #ifdef SERIAL_PARANOIA_CHECK
-	static const char *badmagic =
+	static const char badmagic[] = KERN_WARNING
 		"Warning: bad magic number for serial struct (%s) in %s\n";
-	static const char *badinfo =
+	static const char badinfo[] = KERN_WARNING
 		"Warning: null esp_struct for (%s) in %s\n";
 
 	if (!info) {
@@ -285,8 +288,7 @@
 		buf = free_pio_buf;
 		free_pio_buf = buf->next;
 	} else {
-		buf = (struct esp_pio_buffer *)
-			kmalloc(sizeof(struct esp_pio_buffer), GFP_ATOMIC);
+		buf = kmalloc(sizeof(struct esp_pio_buffer), GFP_ATOMIC);
 	}
 
 	return buf;
@@ -887,17 +889,14 @@
 
 	save_flags(flags); cli();
 
-	if (info->flags & ASYNC_INITIALIZED) {
-		restore_flags(flags);
-		return retval;
-	}
+	if (info->flags & ASYNC_INITIALIZED)
+		goto out;
 
 	if (!info->xmit_buf) {
 		info->xmit_buf = (unsigned char *)get_free_page(GFP_KERNEL);
-		if (!info->xmit_buf) {
-			restore_flags(flags);
-			return -ENOMEM;
-		}
+		retval = -ENOMEM;
+		if (!info->xmit_buf)
+			goto out;
 	}
 
 #ifdef SERIAL_DEBUG_OPEN
@@ -944,9 +943,7 @@
 					&info->tty->flags);
 			retval = 0;
 		}
-		
-		restore_flags(flags);
-		return retval;
+		goto out;
 	}
 
 	if (!(info->stat_flags & ESP_STAT_USE_PIO) && !dma_buffer) {
@@ -1003,8 +1000,9 @@
 	change_speed(info);
 
 	info->flags |= ASYNC_INITIALIZED;
-	restore_flags(flags);
-	return 0;
+	retval = 0;
+out:	restore_flags(flags);
+	return retval;
 }
 
 /*
@@ -1500,10 +1498,7 @@
 	tmp.pio_threshold = info->config.pio_threshold;
 	tmp.dma_channel = (info->stat_flags & ESP_STAT_NEVER_DMA ? 0 : dma);
 
-	if (copy_to_user(retinfo,&tmp,sizeof(*retinfo)))
-		return -EFAULT;
-
-	return 0;
+	return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
 }
 
 static int set_serial_info(struct esp_struct * info,
@@ -1803,12 +1798,10 @@
 static int set_modem_info(struct esp_struct * info, unsigned int cmd,
 			  unsigned int *value)
 {
-	int error;
 	unsigned int arg;
 
-	error = get_user(arg, value);
-	if (error)
-		return error;
+	if (get_user(arg, value))
+		return -EFAULT;
 
 	switch (cmd) {
 	case TIOCMBIS: 
@@ -1866,7 +1859,6 @@
 static int rs_ioctl(struct tty_struct *tty, struct file * file,
 		    unsigned int cmd, unsigned long arg)
 {
-	int error;
 	struct esp_struct * info = (struct esp_struct *)tty->driver_data;
 	struct async_icount cprev, cnow;	/* kernel counter temps */
 	struct serial_icounter_struct *p_cuser;	/* user space */
@@ -1929,13 +1921,19 @@
 				cli();
 				cnow = info->icount;	/* atomic copy */
 				sti();
-				if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && 
-				    cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
+				if (cnow.rng == cprev.rng &&
+				    cnow.dsr == cprev.dsr && 
+				    cnow.dcd == cprev.dcd &&
+				    cnow.cts == cprev.cts)
 					return -EIO; /* no change => error */
-				if ( ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
-				     ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
-				     ((arg & TIOCM_CD)  && (cnow.dcd != cprev.dcd)) ||
-				     ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
+				if (((arg & TIOCM_RNG) &&
+				     (cnow.rng != cprev.rng)) ||
+				     ((arg & TIOCM_DSR) &&
+				      (cnow.dsr != cprev.dsr)) ||
+				     ((arg & TIOCM_CD) &&
+				      (cnow.dcd != cprev.dcd)) ||
+				     ((arg & TIOCM_CTS) &&
+				      (cnow.cts != cprev.cts)) ) {
 					return 0;
 				}
 				cprev = cnow;
@@ -1953,22 +1951,17 @@
 			cnow = info->icount;
 			sti();
 			p_cuser = (struct serial_icounter_struct *) arg;
-			if ((error = put_user(cnow.cts, &p_cuser->cts)))
-				return error;
-			if ((error = put_user(cnow.dsr, &p_cuser->dsr)))
-				return error;
-			if ((error = put_user(cnow.rng, &p_cuser->rng)))
-				return error;
-			if ((error = put_user(cnow.dcd, &p_cuser->dcd)))
-				return error;
+			if (put_user(cnow.cts, &p_cuser->cts) ||
+			    put_user(cnow.dsr, &p_cuser->dsr) ||
+			    put_user(cnow.rng, &p_cuser->rng) ||
+			    put_user(cnow.dcd, &p_cuser->dcd))
+				return -EFAULT;
 
 			return 0;
 	case TIOCGHAYESESP:
-		return (get_esp_config(info,
-				       (struct hayes_esp_config *)arg));
+		return (get_esp_config(info, (struct hayes_esp_config *)arg));
 	case TIOCSHAYESESP:
-		return (set_esp_config(info,
-				       (struct hayes_esp_config *)arg));
+		return (set_esp_config(info, (struct hayes_esp_config *)arg));
 
 		default:
 			return -ENOIOCTLCMD;
@@ -2050,9 +2043,7 @@
 	
 	if (tty_hung_up_p(filp)) {
 		DBG_CNT("before DEC-hung");
-		MOD_DEC_USE_COUNT;
-		restore_flags(flags);
-		return;
+		goto out;
 	}
 	
 #ifdef SERIAL_DEBUG_OPEN
@@ -2077,9 +2068,7 @@
 	}
 	if (info->count) {
 		DBG_CNT("before DEC-2");
-		MOD_DEC_USE_COUNT;
-		restore_flags(flags);
-		return;
+		goto out;
 	}
 	info->flags |= ASYNC_CLOSING;
 	/*
@@ -2140,7 +2129,7 @@
 	info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|
 			 ASYNC_CLOSING);
 	wake_up_interruptible(&info->close_wait);
-	MOD_DEC_USE_COUNT;
+out:	MOD_DEC_USE_COUNT;
 	restore_flags(flags);
 }
 
@@ -2360,7 +2349,6 @@
 {
 	struct esp_struct	*info;
 	int 			retval, line;
-	unsigned long		page;
 
 	line = MINOR(tty->device) - tty->driver.minor_start;
 	if ((line < 0) || (line >= NR_PORTS))
@@ -2388,13 +2376,9 @@
 	info->tty = tty;
 
 	if (!tmp_buf) {
-		page = get_free_page(GFP_KERNEL);
-		if (!page)
+		tmp_buf = (unsigned char *) get_free_page(GFP_KERNEL);
+		if (!tmp_buf)
 			return -ENOMEM;
-		if (tmp_buf)
-			free_page(page);
-		else
-			tmp_buf = (unsigned char *) page;
 	}
 	
 	/*
@@ -2613,8 +2597,7 @@
 		return 1;
 	}
 	
-	info = (struct esp_struct *)kmalloc(sizeof(struct esp_struct),
-		GFP_KERNEL);
+	info = kmalloc(sizeof(struct esp_struct), GFP_KERNEL);
 
 	if (!info)
 	{
@@ -2685,8 +2668,7 @@
 		if (!dma)
 			info->stat_flags |= ESP_STAT_NEVER_DMA;
 
-		info = (struct esp_struct *)kmalloc(sizeof(struct esp_struct),
-			GFP_KERNEL);
+		info = kmalloc(sizeof(struct esp_struct), GFP_KERNEL);
 		if (!info)
 		{
 			printk(KERN_ERR "Couldn't allocate memory for esp serial device information\n"); 
@@ -2714,14 +2696,7 @@
 	return 0;
 }
 
-#ifdef MODULE
-
-int init_module(void)
-{
-	return espserial_init();
-}
-
-void cleanup_module(void) 
+static void __exit espserial_exit(void) 
 {
 	unsigned long flags;
 	int e1, e2;
@@ -2782,4 +2757,6 @@
 		free_pio_buf = pio_buf;
 	}
 }
-#endif /* MODULE */
+
+module_init(espserial_init);
+module_exit(espserial_exit);

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