]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
s390/boot: Add physmem_alloc()
authorVasily Gorbik <gor@linux.ibm.com>
Fri, 29 Nov 2024 01:26:19 +0000 (02:26 +0100)
committerAlexander Gordeev <agordeev@linux.ibm.com>
Sun, 26 Jan 2025 16:23:58 +0000 (17:23 +0100)
Add physmem_alloc() as a variant of physmem_alloc_or_die() that can return
an error instead of triggering a panic on OOM. This allows callers to
implement alternative fallback paths.

Reviewed-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
arch/s390/boot/boot.h
arch/s390/boot/physmem_info.c

index f269026246501bcfe9a2372d5a49f0c45b19303b..ce8422d8f9a8937763cc896374cabb468c73eeb1 100644 (file)
@@ -49,6 +49,8 @@ void physmem_free(enum reserved_range_type type);
 /* for continuous/multiple allocations per type */
 unsigned long physmem_alloc_or_die(enum reserved_range_type type, unsigned long size,
                                   unsigned long align);
+unsigned long physmem_alloc(enum reserved_range_type type, unsigned long size,
+                           unsigned long align, bool die_on_oom);
 /* for single allocations, 1 per type */
 unsigned long physmem_alloc_range(enum reserved_range_type type, unsigned long size,
                                  unsigned long align, unsigned long min, unsigned long max,
index 34d310a6d8a523809dcc4846c00aee5b5e036402..f585f015abfe2fb0a0bc5ad929ac21463f3c338b 100644 (file)
@@ -343,8 +343,8 @@ unsigned long physmem_alloc_range(enum reserved_range_type type, unsigned long s
        return addr;
 }
 
-unsigned long physmem_alloc_or_die(enum reserved_range_type type, unsigned long size,
-                                  unsigned long align)
+unsigned long physmem_alloc(enum reserved_range_type type, unsigned long size,
+                           unsigned long align, bool die_on_oom)
 {
        struct reserved_range *range = &physmem_info.reserved[type];
        struct reserved_range *new_range;
@@ -352,18 +352,22 @@ unsigned long physmem_alloc_or_die(enum reserved_range_type type, unsigned long
        unsigned long addr;
 
        addr = __physmem_alloc_range(size, align, 0, physmem_alloc_pos, physmem_alloc_ranges,
-                                    &ranges_left, true);
+                                    &ranges_left, die_on_oom);
+       if (!addr)
+               return 0;
        /* if not a consecutive allocation of the same type or first allocation */
        if (range->start != addr + size) {
                if (range->end) {
-                       physmem_alloc_pos = __physmem_alloc_range(
-                               sizeof(struct reserved_range), 0, 0, physmem_alloc_pos,
-                               physmem_alloc_ranges, &ranges_left, true);
-                       new_range = (struct reserved_range *)physmem_alloc_pos;
+                       addr = __physmem_alloc_range(sizeof(struct reserved_range), 0, 0,
+                                                    physmem_alloc_pos, physmem_alloc_ranges,
+                                                    &ranges_left, true);
+                       new_range = (struct reserved_range *)addr;
+                       addr = __physmem_alloc_range(size, align, 0, addr, ranges_left,
+                                                    &ranges_left, die_on_oom);
+                       if (!addr)
+                               return 0;
                        *new_range = *range;
                        range->chain = new_range;
-                       addr = __physmem_alloc_range(size, align, 0, physmem_alloc_pos,
-                                                    ranges_left, &ranges_left, true);
                }
                range->end = addr + size;
        }
@@ -373,6 +377,12 @@ unsigned long physmem_alloc_or_die(enum reserved_range_type type, unsigned long
        return addr;
 }
 
+unsigned long physmem_alloc_or_die(enum reserved_range_type type, unsigned long size,
+                                  unsigned long align)
+{
+       return physmem_alloc(type, size, align, true);
+}
+
 unsigned long get_physmem_alloc_pos(void)
 {
        return physmem_alloc_pos;