Skip to contentSkip to conversation

bus mouse drivers cleanup

PATCH New [email protected] 1 participant 1 message Jun 13, 2001

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bus mouse drivers cleanup

Hi all,

attached are patches to add (missing) error checking and proper error code returning in case of request_region(), request_irq and misc_register() fauilures.

Drivers affected: atixlmouse.c, logibusmouse.c, msbusmouse.c, pc110pad.c.

Best regards.

P.S. Also check_region() calls removed from logibusmouse.c and msbusmouse.c

Signature · 2 lines
Andrey Panin            | Embedded systems software engineer
[email protected]        | PGP key: http://www.orbita1.ru/~pazke/AndreyPanin.asc
linux/drivers/char/atixlmouse.c renamed from linux.vanilla/drivers/char/atixlmouse.c +4 -3
diff -u -X /usr/dontdiff /linux.vanilla/drivers/char/atixlmouse.c /linux/drivers/char/atixlmouse.c
@@ -91,8 +91,9 @@
 
 static int open_mouse(struct inode * inode, struct file * file)
 {
-	if (request_irq(ATIXL_MOUSE_IRQ, mouse_interrupt, 0, "ATIXL mouse", NULL))
-		return -EBUSY;
+	int retval;
+	if ((retval = request_irq(ATIXL_MOUSE_IRQ, mouse_interrupt, SA_INTERRUPT | SA_SAMPLE_RANDOM, "ATIXL mouse", NULL)))
+		return retval;
 	ATIXL_MSE_INT_ON(); /* Interrupts are really enabled here */
 	return 0;
 }
@@ -112,7 +113,7 @@
 	 */
 
 	if (!request_region(ATIXL_MSE_DATA_PORT, 3, "atixlmouse"))
-		return -EIO;
+		return -EBUSY;
 
 	a = inb( ATIXL_MSE_SIGNATURE_PORT );	/* Get signature */
 	b = inb( ATIXL_MSE_SIGNATURE_PORT );
linux/drivers/char/logibusmouse.c renamed from linux.vanilla/drivers/char/logibusmouse.c +11 -9
diff -u -X /usr/dontdiff /linux.vanilla/drivers/char/logibusmouse.c /linux/drivers/char/logibusmouse.c
@@ -116,8 +116,9 @@
 
 static int open_mouse(struct inode * inode, struct file * file)
 {
-	if (request_irq(mouse_irq, mouse_interrupt, 0, "busmouse", NULL))
-		return -EBUSY;
+	int retval;
+	if ((retval = request_irq(mouse_irq, mouse_interrupt, SA_INTERRUPT | SA_SAMPLE_RANDOM, "busmouse", NULL)))
+		return retval;
 	MSE_INT_ON();
 	return 0;
 }
@@ -128,24 +129,25 @@
 
 static int __init logi_busmouse_init(void)
 {
-	if (check_region(LOGIBM_BASE, LOGIBM_EXTENT))
-		return -EIO;
+	if (!request_region(LOGIBM_BASE, LOGIBM_EXTENT, "busmouse"))
+		return -EBUSY;
 
 	outb(MSE_CONFIG_BYTE, MSE_CONFIG_PORT);
 	outb(MSE_SIGNATURE_BYTE, MSE_SIGNATURE_PORT);
 	udelay(100L);	/* wait for reply from mouse */
-	if (inb(MSE_SIGNATURE_PORT) != MSE_SIGNATURE_BYTE)
+	if (inb(MSE_SIGNATURE_PORT) != MSE_SIGNATURE_BYTE) {
+		release_region(LOGIBM_BASE, LOGIBM_EXTENT);
 		return -EIO;
+	}
 
 	outb(MSE_DEFAULT_MODE, MSE_CONFIG_PORT);
 	MSE_INT_OFF();
-	
-	request_region(LOGIBM_BASE, LOGIBM_EXTENT, "busmouse");
 
 	msedev = register_busmouse(&busmouse);
-	if (msedev < 0)
+	if (msedev < 0) {
 		printk(KERN_WARNING "Unable to register busmouse driver.\n");
-	else
+		release_region(LOGIBM_BASE, LOGIBM_EXTENT);
+	} else
 		printk(KERN_INFO "Logitech busmouse installed.\n");
 	return msedev < 0 ? msedev : 0;
 }
linux/drivers/char/msbusmouse.c renamed from linux.vanilla/drivers/char/msbusmouse.c +12 -8
diff -u -X /usr/dontdiff /linux.vanilla/drivers/char/msbusmouse.c /linux/drivers/char/msbusmouse.c
@@ -113,8 +113,9 @@
 
 static int open_mouse(struct inode * inode, struct file * file)
 {
-	if (request_irq(mouse_irq, ms_mouse_interrupt, 0, "MS Busmouse", NULL))
-		return -EBUSY;
+	int retval;
+	if ((retval = request_irq(mouse_irq, ms_mouse_interrupt, SA_INTERRUPT | SA_SAMPLE_RANDOM, "MS Busmouse", NULL)))
+		return retval;
 
 	outb(MS_MSE_START, MS_MSE_CONTROL_PORT);
 	MS_MSE_INT_ON();	
@@ -130,8 +131,8 @@
 	int present = 0;
 	int mse_byte, i;
 
-	if (check_region(MS_MSE_CONTROL_PORT, 0x04))
-		return -ENODEV;
+	if (!request_region(MS_MSE_CONTROL_PORT, 0x04, "MS Busmouse"));
+		return -EBUSY;
 
 	if (inb_p(MS_MSE_SIGNATURE_PORT) == 0xde) {
 
@@ -147,14 +148,17 @@
 				present = 0;
 		}
 	}
-	if (present == 0)
+	if (present == 0) {
+		release_region(MS_MSE_CONTROL_PORT, 0x04);
 		return -EIO;
+	}
 	MS_MSE_INT_OFF();
-	request_region(MS_MSE_CONTROL_PORT, 0x04, "MS Busmouse");
+
 	msedev = register_busmouse(&msbusmouse);
-	if (msedev < 0)
+	if (msedev < 0) {
 		printk(KERN_WARNING "Unable to register msbusmouse driver.\n");
-	else
+		release_region(MS_MSE_CONTROL_PORT, 0x04);
+	} else
 		printk(KERN_INFO "Microsoft BusMouse detected and installed.\n");
 	return msedev < 0 ? msedev : 0;
 }
linux/drivers/char/pc110pad.c renamed from linux.vanilla/drivers/char/pc110pad.c +20 -7
diff -u -X /usr/dontdiff /linux.vanilla/drivers/char/pc110pad.c /linux/drivers/char/pc110pad.c
@@ -802,23 +802,36 @@
 
 static int __init pc110pad_init_driver(void)
 {
+	int retval = -EBUSY;
+
 	init_MUTEX(&reader_lock);
 	current_params = default_params;
 
-	if (request_irq(current_params.irq, pad_irq, 0, "pc110pad", 0)) {
-		printk(KERN_ERR "pc110pad: Unable to get IRQ.\n");
-		return -EBUSY;
-	}
 	if (!request_region(current_params.io, 4, "pc110pad"))	{
 		printk(KERN_ERR "pc110pad: I/O area in use.\n");
-		free_irq(current_params.irq,0);
-		return -EBUSY;
+		goto err_out;
+	}
+	if ((retval = request_irq(current_params.irq, pad_irq, SA_INTERRUPT | SA_SAMPLE_RANDOM, "pc110pad", 0))) {
+		printk(KERN_ERR "pc110pad: Unable to get IRQ.\n");
+		goto err_out_release_region;
 	}
 	init_waitqueue_head(&queue);
+
+	if ((retval = misc_register(&pc110_pad))) {
+		printk(KERN_ERR "pc110pad: Unable to register driver.\n");
+		goto err_out_free_irq;
+	}
+
 	printk(banner, current_params.io, current_params.irq);
-	misc_register(&pc110_pad);
 	outb(0x30, current_params.io+2);	/* switch off digitiser */
 	return 0;
+
+err_out_free_irq:
+	free_irq(current_params.irq, 0);
+err_out_release_region:
+	release_region(current_params.io, 4);
+err_out:
+	return retval;
 }
 
 /*