[patch] request_region return val

Jeff Garzik (jgarzik@pobox.com)
Thu, 27 May 1999 00:06:16 -0400 (EDT)


This patch, against 2.3.3, adds a return value to request_region.
Drivers often have logic like

if check_region() == 0
request_region()
else
error...

The iotable is searched twice for this common case. My patch makes
request_region return -EBUSY just like check_region, if the region is
unavailable. It also makes driver code a tiny bit cleaner. The above
code becomes

if request_region()
error...

Index: include/linux/ioport.h
===================================================================
RCS file: /usr/local/cvsroot/linux_2_3/include/linux/ioport.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 ioport.h
--- include/linux/ioport.h 1999/05/16 06:21:11 1.1.1.1
+++ include/linux/ioport.h 1999/05/27 03:55:19
@@ -18,7 +18,7 @@
*/
extern void reserve_setup(char *str, int *ints);
extern int check_region(unsigned long from, unsigned long extent);
-extern void request_region(unsigned long from, unsigned long extent,const char *name);
+extern int request_region(unsigned long from, unsigned long extent,const char *name);
extern void release_region(unsigned long from, unsigned long extent);
extern int get_ioport_list(char *);

Index: kernel/resource.c
===================================================================
RCS file: /usr/local/cvsroot/linux_2_3/kernel/resource.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 resource.c
--- kernel/resource.c 1999/05/16 06:21:04 1.1.1.1
+++ kernel/resource.c 1999/05/27 03:55:20
@@ -68,7 +68,7 @@
/*
* Call this from the device driver to register the ioport region.
*/
-void request_region(unsigned long from, unsigned long num, const char *name)
+int request_region(unsigned long from, unsigned long num, const char *name)
{
resource_entry_t *p;
int i;
@@ -81,14 +81,17 @@
else {
p = find_gap(&iolist, from, num);
if (p == NULL)
- return;
+ return -EBUSY;
iotable[i].name = name;
iotable[i].from = from;
iotable[i].num = num;
iotable[i].next = p->next;
p->next = &iotable[i];
- return;
+ return 0;
}
+
+ /* Driver prints a warning hopefully */
+ return 0;
}

/*

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/