Skip to content

Commit 094c0ce

Browse files
ij-intelbjorn-helgaas
authored andcommitted
resource: Handle simple alignment inside __find_resource_space()
allocate_resource() accepts ->alignf() callback to perform custom alignment beyond constraint->align. If alignf is NULL, simple_align_resource() is used which only returns avail->start (no change). Using avail->start directly is natural and can be done with a conditional in __find_resource_space() instead which avoids unnecessarily using callback. It makes the code inside __find_resource_space() more obvious and removes the need for the caller to provide constraint->alignf unnecessarily. This is preparation for exporting find_resource_space(). Link: https://lore.kernel.org/r/[email protected] Tested-by: Lidong Wang <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Reviewed-by: Mika Westerberg <[email protected]>
1 parent 4eed3dd commit 094c0ce

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

kernel/resource.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -621,14 +621,6 @@ void __weak arch_remove_reservations(struct resource *avail)
621621
{
622622
}
623623

624-
static resource_size_t simple_align_resource(void *data,
625-
const struct resource *avail,
626-
resource_size_t size,
627-
resource_size_t align)
628-
{
629-
return avail->start;
630-
}
631-
632624
static void resource_clip(struct resource *res, resource_size_t min,
633625
resource_size_t max)
634626
{
@@ -648,6 +640,7 @@ static int __find_resource_space(struct resource *root, struct resource *old,
648640
{
649641
struct resource *this = root->child;
650642
struct resource tmp = *new, avail, alloc;
643+
resource_alignf alignf = constraint->alignf;
651644

652645
tmp.start = root->start;
653646
/*
@@ -676,8 +669,12 @@ static int __find_resource_space(struct resource *root, struct resource *old,
676669
avail.flags = new->flags & ~IORESOURCE_UNSET;
677670
if (avail.start >= tmp.start) {
678671
alloc.flags = avail.flags;
679-
alloc.start = constraint->alignf(constraint->alignf_data, &avail,
680-
size, constraint->align);
672+
if (alignf) {
673+
alloc.start = alignf(constraint->alignf_data,
674+
&avail, size, constraint->align);
675+
} else {
676+
alloc.start = avail.start;
677+
}
681678
alloc.end = alloc.start + size - 1;
682679
if (alloc.start <= alloc.end &&
683680
resource_contains(&avail, &alloc)) {
@@ -788,9 +785,6 @@ int allocate_resource(struct resource *root, struct resource *new,
788785
int err;
789786
struct resource_constraint constraint;
790787

791-
if (!alignf)
792-
alignf = simple_align_resource;
793-
794788
constraint.min = min;
795789
constraint.max = max;
796790
constraint.align = align;

0 commit comments

Comments
 (0)