Commit 441f0dd8 authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Greg Kroah-Hartman

resource: Reuse for_each_resource() macro

We have a few places where for_each_resource() is open coded.
Replace that by the macro. This makes code easier to read and
understand.

With this, compile r_next() only for CONFIG_PROC_FS=y.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20230912165312.402422-1-andriy.shevchenko@linux.intel.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 24de09c1
...@@ -77,13 +77,6 @@ static struct resource *next_resource_skip_children(struct resource *p) ...@@ -77,13 +77,6 @@ static struct resource *next_resource_skip_children(struct resource *p)
(_p) = (_skip_children) ? next_resource_skip_children(_p) : \ (_p) = (_skip_children) ? next_resource_skip_children(_p) : \
next_resource(_p)) next_resource(_p))
static void *r_next(struct seq_file *m, void *v, loff_t *pos)
{
struct resource *p = v;
(*pos)++;
return (void *)next_resource(p);
}
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
enum { MAX_IORES_LEVEL = 5 }; enum { MAX_IORES_LEVEL = 5 };
...@@ -91,14 +84,26 @@ enum { MAX_IORES_LEVEL = 5 }; ...@@ -91,14 +84,26 @@ enum { MAX_IORES_LEVEL = 5 };
static void *r_start(struct seq_file *m, loff_t *pos) static void *r_start(struct seq_file *m, loff_t *pos)
__acquires(resource_lock) __acquires(resource_lock)
{ {
struct resource *p = pde_data(file_inode(m->file)); struct resource *root = pde_data(file_inode(m->file));
loff_t l = 0; struct resource *p;
loff_t l = *pos;
read_lock(&resource_lock); read_lock(&resource_lock);
for (p = p->child; p && l < *pos; p = r_next(m, p, &l)) for_each_resource(root, p, false) {
; if (l-- == 0)
break;
}
return p; return p;
} }
static void *r_next(struct seq_file *m, void *v, loff_t *pos)
{
struct resource *p = v;
(*pos)++;
return (void *)next_resource(p);
}
static void r_stop(struct seq_file *m, void *v) static void r_stop(struct seq_file *m, void *v)
__releases(resource_lock) __releases(resource_lock)
{ {
...@@ -336,7 +341,7 @@ static int find_next_iomem_res(resource_size_t start, resource_size_t end, ...@@ -336,7 +341,7 @@ static int find_next_iomem_res(resource_size_t start, resource_size_t end,
read_lock(&resource_lock); read_lock(&resource_lock);
for (p = iomem_resource.child; p; p = next_resource(p)) { for_each_resource(&iomem_resource, p, false) {
/* If we passed the resource we are looking for, stop */ /* If we passed the resource we are looking for, stop */
if (p->start > end) { if (p->start > end) {
p = NULL; p = NULL;
...@@ -1641,13 +1646,12 @@ __setup("reserve=", reserve_setup); ...@@ -1641,13 +1646,12 @@ __setup("reserve=", reserve_setup);
*/ */
int iomem_map_sanity_check(resource_size_t addr, unsigned long size) int iomem_map_sanity_check(resource_size_t addr, unsigned long size)
{ {
struct resource *p = &iomem_resource;
resource_size_t end = addr + size - 1; resource_size_t end = addr + size - 1;
struct resource *p;
int err = 0; int err = 0;
loff_t l;
read_lock(&resource_lock); read_lock(&resource_lock);
for (p = p->child; p ; p = r_next(NULL, p, &l)) { for_each_resource(&iomem_resource, p, false) {
/* /*
* We can probably skip the resources without * We can probably skip the resources without
* IORESOURCE_IO attribute? * IORESOURCE_IO attribute?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment