Skip to content

Commit 441f0dd

Browse files
andy-shevgregkh
authored andcommitted
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: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 24de09c commit 441f0dd

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

kernel/resource.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,33 @@ static struct resource *next_resource_skip_children(struct resource *p)
7777
(_p) = (_skip_children) ? next_resource_skip_children(_p) : \
7878
next_resource(_p))
7979

80-
static void *r_next(struct seq_file *m, void *v, loff_t *pos)
81-
{
82-
struct resource *p = v;
83-
(*pos)++;
84-
return (void *)next_resource(p);
85-
}
86-
8780
#ifdef CONFIG_PROC_FS
8881

8982
enum { MAX_IORES_LEVEL = 5 };
9083

9184
static void *r_start(struct seq_file *m, loff_t *pos)
9285
__acquires(resource_lock)
9386
{
94-
struct resource *p = pde_data(file_inode(m->file));
95-
loff_t l = 0;
87+
struct resource *root = pde_data(file_inode(m->file));
88+
struct resource *p;
89+
loff_t l = *pos;
90+
9691
read_lock(&resource_lock);
97-
for (p = p->child; p && l < *pos; p = r_next(m, p, &l))
98-
;
92+
for_each_resource(root, p, false) {
93+
if (l-- == 0)
94+
break;
95+
}
96+
9997
return p;
10098
}
10199

100+
static void *r_next(struct seq_file *m, void *v, loff_t *pos)
101+
{
102+
struct resource *p = v;
103+
(*pos)++;
104+
return (void *)next_resource(p);
105+
}
106+
102107
static void r_stop(struct seq_file *m, void *v)
103108
__releases(resource_lock)
104109
{
@@ -336,7 +341,7 @@ static int find_next_iomem_res(resource_size_t start, resource_size_t end,
336341

337342
read_lock(&resource_lock);
338343

339-
for (p = iomem_resource.child; p; p = next_resource(p)) {
344+
for_each_resource(&iomem_resource, p, false) {
340345
/* If we passed the resource we are looking for, stop */
341346
if (p->start > end) {
342347
p = NULL;
@@ -1641,13 +1646,12 @@ __setup("reserve=", reserve_setup);
16411646
*/
16421647
int iomem_map_sanity_check(resource_size_t addr, unsigned long size)
16431648
{
1644-
struct resource *p = &iomem_resource;
16451649
resource_size_t end = addr + size - 1;
1650+
struct resource *p;
16461651
int err = 0;
1647-
loff_t l;
16481652

16491653
read_lock(&resource_lock);
1650-
for (p = p->child; p ; p = r_next(NULL, p, &l)) {
1654+
for_each_resource(&iomem_resource, p, false) {
16511655
/*
16521656
* We can probably skip the resources without
16531657
* IORESOURCE_IO attribute?

0 commit comments

Comments
 (0)