Get rid of check_resource() before it becomes a problem
PATCH 1/1 Get rid of check_resource() before it becomes a problem
AFAICT, it has the same race issues as the old check_region() which is being slowly and painfully eliminated.
Remove the temptation, and open-code the one user (PCMCIA).
Rusty.
drivers/pcmcia/rsrc_mgr.c +22 -2
@@ -124,16 +124,36 @@ static struct resource *resource_parent(return &ioport_resource; } +/* FIXME: Fundamentally racy. */ static inline int check_io_resource (unsigned long b,unsigned long n,struct pci_dev *dev) { -return check_resource (resource_parent (b, n,IORESOURCE_IO , dev), b, n); +struct resource *region; + + region =__request_region (resource_parent (b, n,IORESOURCE_IO , dev), + b, n,"check_io_resource" ); +if (!region) +return -EBUSY ; + +release_resource (region); +kfree (region); +return 0 ; } +/* FIXME: Fundamentally racy. */ static inline int check_mem_resource (unsigned long b,unsigned long n,struct pci_dev *dev) { -return check_resource (resource_parent (b, n,IORESOURCE_MEM , dev), b, n); +struct resource *region; + + region =__request_region (resource_parent (b, n,IORESOURCE_MEM , dev), + b, n,"check_mem_resource" ); +if (!region) +return -EBUSY ; + +release_resource (region); +kfree (region); +return 0 ; } static struct resource *make_resource(unsigned long b, unsigned long n,
include/linux/ioport.h +0 -1
@@ -85,7 +85,6 @@ extern struct resource iomem_resource;extern int get_resource_list (struct resource *,char *buf,int size); -extern int check_resource (struct resource *root,unsigned long ,unsigned long );extern int request_resource (struct resource *root,struct resource *new);extern int release_resource (struct resource *new); extern int allocate_resource(struct resource *root, struct resource *new,
kernel/resource.c +0 -14
@@ -131,20 +131,6 @@ int release_resource(struct resource *olreturn retval; } -int check_resource (struct resource *root,unsigned long start,unsigned long len) -{ -struct resource *conflict, tmp; - - tmp.start = start; - tmp.end = start + len -1 ; -write_lock (&resource_lock); - conflict =__request_resource (root, &tmp); -if (!conflict) -__release_resource (&tmp); -write_unlock (&resource_lock); -return conflict ? -EBUSY :0 ; -} -/* * Find empty slot in the resource tree given range and alignment. */
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Need to zap the export from kernel/ksyms.c too
In message <[email protected]> you write:
Quoted 1 line
Need to zap the export from
kernel/ksyms.ctoo
Ack.
Here it is, fresh against 2.5.44.
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Name: Remove inherently racy check_resource
Author: Rusty Russell
Status: Trivial
D: The new resource interface foolishly replicated the (obsolete,
D: racy) spirit of the check_region call as check_resource. You
D: should use request_resource/release_resource instead.
drivers/pcmcia/rsrc_mgr.c +22 -2
@@ -124,16 +124,36 @@ static struct resource *resource_parent(return &ioport_resource; } +/* FIXME: Fundamentally racy. */ static inline int check_io_resource (unsigned long b,unsigned long n,struct pci_dev *dev) { -return check_resource (resource_parent (b, n,IORESOURCE_IO , dev), b, n); +struct resource *region; + + region =__request_region (resource_parent (b, n,IORESOURCE_IO , dev), + b, n,"check_io_resource" ); +if (!region) +return -EBUSY ; + +release_resource (region); +kfree (region); +return 0 ; } +/* FIXME: Fundamentally racy. */ static inline int check_mem_resource (unsigned long b,unsigned long n,struct pci_dev *dev) { -return check_resource (resource_parent (b, n,IORESOURCE_MEM , dev), b, n); +struct resource *region; + + region =__request_region (resource_parent (b, n,IORESOURCE_MEM , dev), + b, n,"check_mem_resource" ); +if (!region) +return -EBUSY ; + +release_resource (region); +kfree (region); +return 0 ; } static struct resource *make_resource(unsigned long b, unsigned long n,
include/linux/ioport.h +0 -1
@@ -85,7 +85,6 @@ extern struct resource iomem_resource;extern int get_resource_list (struct resource *,char *buf,int size); -extern int check_resource (struct resource *root,unsigned long ,unsigned long );extern int request_resource (struct resource *root,struct resource *new);extern int release_resource (struct resource *new); extern int allocate_resource(struct resource *root, struct resource *new,
kernel/ksyms.c +0 -1
@@ -445,7 +445,6 @@ EXPORT_SYMBOL(enable_hlt);EXPORT_SYMBOL (request_resource);EXPORT_SYMBOL (release_resource);EXPORT_SYMBOL (allocate_resource); -EXPORT_SYMBOL (check_resource);EXPORT_SYMBOL (__request_region);EXPORT_SYMBOL (__check_region);EXPORT_SYMBOL (__release_region);
kernel/resource.c +0 -14
@@ -131,20 +131,6 @@ int release_resource(struct resource *olreturn retval; } -int check_resource (struct resource *root,unsigned long start,unsigned long len) -{ -struct resource *conflict, tmp; - - tmp.start = start; - tmp.end = start + len -1 ; -write_lock (&resource_lock); - conflict =__request_resource (root, &tmp); -if (!conflict) -__release_resource (&tmp); -write_unlock (&resource_lock); -return conflict ? -EBUSY :0 ; -} -/* * Find empty slot in the resource tree given range and alignment. */