patch-2.4.21 linux-2.4.21/Documentation/DocBook/mousedrivers.tmpl
Next file: linux-2.4.21/Documentation/DocBook/procfs-guide.tmpl
Previous file: linux-2.4.21/Documentation/DocBook/kernel-locking.tmpl
Back to the patch index
Back to the overall index
- Lines: 47
- Date:
2003-06-13 07:51:29.000000000 -0700
- Orig file:
linux-2.4.20/Documentation/DocBook/mousedrivers.tmpl
- Orig date:
2001-09-30 12:26:05.000000000 -0700
diff -urN linux-2.4.20/Documentation/DocBook/mousedrivers.tmpl linux-2.4.21/Documentation/DocBook/mousedrivers.tmpl
@@ -153,11 +153,17 @@
__init ourmouse_init(void)
{
- if(check_region(OURMOUSE_BASE, 3))
+ if (request_region(OURMOUSE_BASE, 3, "ourmouse") < 0) {
+ printk(KERN_ERR "ourmouse: request_region failed.\n");
return -ENODEV;
- request_region(OURMOUSE_BASE, 3, "ourmouse");
+ }
+
+ if (misc_register(&our_mouse) < 0) {
+ printk(KERN_ERR "ourmouse: cannot register misc device.\n");
+ release_region(OURMOUSE_BASE, 3);
+ return -EBUSY;
+ }
- misc_register(&our_mouse);
return 0;
}
</programlisting>
@@ -177,18 +183,20 @@
so it is a good idea to obtain a current copy of this file first.
</para>
<para>
- Our code then is fairly simple. We check nobody else has taken our
- address space. Having done so we reserve it to ensure nobody stamps
- on our device while probing for other ISA bus devices. Such a probe
- might confuse our device.
+ Our code then is fairly simple. We reserve our I/O address space with
+ request_region, checking to make sure that it succeeded (i.e. the
+ space wasn't reserved by anyone else).
</para>
<para>
- Then we tell the misc driver that we wish to own a minor number. We also
+ Then we ask the misc driver to allocate our minor device number. We also
hand it our name (which is used in
<filename class="directory">/proc/misc</filename>) and a set of file
operations that are to be used. The file operations work exactly like the
file operations you would register for a normal character device. The misc
device itself is simply acting as a redirector for requests.
+ Since misc_register can fail, it is important to check for failure
+ and act accordingly (which in the case of a mouse driver is to abort,
+ since you can't use the mouse without a working device node).
</para>
<para>
Next, in order to be able to use and test our code we need to add some
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)