lkml.org 
[lkml]   [2001]   [Jun]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patches in this message
/
Date
Subject[PATCH] bus mouse drivers cleanup
From
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

--
Andrey Panin | Embedded systems software engineer
pazke@orbita1.ru | PGP key: http://www.orbita1.ru/~pazke/AndreyPanin.ascdiff -u -X /usr/dontdiff /linux.vanilla/drivers/char/atixlmouse.c /linux/drivers/char/atixlmouse.c
--- /linux.vanilla/drivers/char/atixlmouse.c Tue Jun 12 10:51:22 2001
+++ /linux/drivers/char/atixlmouse.c Tue Jun 12 11:32:59 2001
@@ -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 );diff -u -X /usr/dontdiff /linux.vanilla/drivers/char/logibusmouse.c /linux/drivers/char/logibusmouse.c
--- /linux.vanilla/drivers/char/logibusmouse.c Tue Jun 12 10:51:30 2001
+++ /linux/drivers/char/logibusmouse.c Tue Jun 12 11:35:28 2001
@@ -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;
}diff -u -X /usr/dontdiff /linux.vanilla/drivers/char/msbusmouse.c /linux/drivers/char/msbusmouse.c
--- /linux.vanilla/drivers/char/msbusmouse.c Tue Jun 12 10:51:22 2001
+++ /linux/drivers/char/msbusmouse.c Tue Jun 12 11:38:18 2001
@@ -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;
}diff -u -X /usr/dontdiff /linux.vanilla/drivers/char/pc110pad.c /linux/drivers/char/pc110pad.c
--- /linux.vanilla/drivers/char/pc110pad.c Tue Jun 12 10:51:26 2001
+++ /linux/drivers/char/pc110pad.c Tue Jun 12 12:01:44 2001
@@ -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;
}

/*[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2005-03-22 12:55    [W:0.024 / U:0.312 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site