Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

resource: introduce is_type_match() helper and use it

There are already a couple of places where we may replace a few lines of
code by calling a helper, which increases readability while deduplicating
the code.

Introduce is_type_match() helper and use it.

Link: https://lkml.kernel.org/r/20240925154355.1170859-3-andriy.shevchenko@linux.intel.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Andy Shevchenko and committed by
Andrew Morton
ba1eccc1 5c1edea7

+10 -13
+10 -13
kernel/resource.c
··· 297 297 298 298 EXPORT_SYMBOL(release_resource); 299 299 300 + static bool is_type_match(struct resource *p, unsigned long flags, unsigned long desc) 301 + { 302 + return (p->flags & flags) == flags && (desc == IORES_DESC_NONE || desc == p->desc); 303 + } 304 + 300 305 /** 301 306 * find_next_iomem_res - Finds the lowest iomem resource that covers part of 302 307 * [@start..@end]. ··· 344 339 if (p->end < start) 345 340 continue; 346 341 347 - if ((p->flags & flags) != flags) 348 - continue; 349 - if ((desc != IORES_DESC_NONE) && (desc != p->desc)) 350 - continue; 351 - 352 342 /* Found a match, break */ 353 - break; 343 + if (is_type_match(p, flags, desc)) 344 + break; 354 345 } 355 346 356 347 if (p) { ··· 541 540 int type = 0; int other = 0; 542 541 struct resource *p, *dp; 543 542 struct resource res, o; 544 - bool is_type, covered; 543 + bool covered; 545 544 546 545 res.start = start; 547 546 res.end = start + size - 1; ··· 549 548 for (p = parent->child; p ; p = p->sibling) { 550 549 if (!resource_intersection(p, &res, &o)) 551 550 continue; 552 - is_type = (p->flags & flags) == flags && 553 - (desc == IORES_DESC_NONE || desc == p->desc); 554 - if (is_type) { 551 + if (is_type_match(p, flags, desc)) { 555 552 type++; 556 553 continue; 557 554 } ··· 569 570 for_each_resource(p, dp, false) { 570 571 if (!resource_overlaps(dp, &res)) 571 572 continue; 572 - is_type = (dp->flags & flags) == flags && 573 - (desc == IORES_DESC_NONE || desc == dp->desc); 574 - if (is_type) { 573 + if (is_type_match(dp, flags, desc)) { 575 574 type++; 576 575 /* 577 576 * Range from 'o.start' to 'dp->start'