Skip to content

Commit 1c4bc43

Browse files
agnerstorvalds
authored andcommitted
mm/memblock: introduce PHYS_ADDR_MAX
So far code was using ULLONG_MAX and type casting to obtain a phys_addr_t with all bits set. The typecast is necessary to silence compiler warnings on 32-bit platforms. Use the simpler but still type safe approach "~(phys_addr_t)0" to create a preprocessor define for all bits set. Link: http://lkml.kernel.org/r/20180406213809.566-1-stefan@agner.ch Signed-off-by: Stefan Agner <stefan@agner.ch> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Acked-by: Michal Hocko <mhocko@suse.com> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Pavel Tatashin <pasha.tatashin@oracle.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 00b3a33 commit 1c4bc43

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

include/linux/kernel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#define LLONG_MIN (-LLONG_MAX - 1)
3030
#define ULLONG_MAX (~0ULL)
3131
#define SIZE_MAX (~(size_t)0)
32+
#define PHYS_ADDR_MAX (~(phys_addr_t)0)
3233

3334
#define U8_MAX ((u8)~0U)
3435
#define S8_MAX ((s8)(U8_MAX>>1))

mm/memblock.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ ulong __init_memblock choose_memblock_flags(void)
6868
/* adjust *@size so that (@base + *@size) doesn't overflow, return new size */
6969
static inline phys_addr_t memblock_cap_size(phys_addr_t base, phys_addr_t *size)
7070
{
71-
return *size = min(*size, (phys_addr_t)ULLONG_MAX - base);
71+
return *size = min(*size, PHYS_ADDR_MAX - base);
7272
}
7373

7474
/*
@@ -925,7 +925,7 @@ void __init_memblock __next_mem_range(u64 *idx, int nid, ulong flags,
925925
r = &type_b->regions[idx_b];
926926
r_start = idx_b ? r[-1].base + r[-1].size : 0;
927927
r_end = idx_b < type_b->cnt ?
928-
r->base : (phys_addr_t)ULLONG_MAX;
928+
r->base : PHYS_ADDR_MAX;
929929

930930
/*
931931
* if idx_b advanced past idx_a,
@@ -1041,7 +1041,7 @@ void __init_memblock __next_mem_range_rev(u64 *idx, int nid, ulong flags,
10411041
r = &type_b->regions[idx_b];
10421042
r_start = idx_b ? r[-1].base + r[-1].size : 0;
10431043
r_end = idx_b < type_b->cnt ?
1044-
r->base : (phys_addr_t)ULLONG_MAX;
1044+
r->base : PHYS_ADDR_MAX;
10451045
/*
10461046
* if idx_b advanced past idx_a,
10471047
* break out to advance idx_a
@@ -1516,13 +1516,13 @@ phys_addr_t __init_memblock memblock_end_of_DRAM(void)
15161516

15171517
static phys_addr_t __init_memblock __find_max_addr(phys_addr_t limit)
15181518
{
1519-
phys_addr_t max_addr = (phys_addr_t)ULLONG_MAX;
1519+
phys_addr_t max_addr = PHYS_ADDR_MAX;
15201520
struct memblock_region *r;
15211521

15221522
/*
15231523
* translate the memory @limit size into the max address within one of
15241524
* the memory memblock regions, if the @limit exceeds the total size
1525-
* of those regions, max_addr will keep original value ULLONG_MAX
1525+
* of those regions, max_addr will keep original value PHYS_ADDR_MAX
15261526
*/
15271527
for_each_memblock(memory, r) {
15281528
if (limit <= r->size) {
@@ -1537,22 +1537,22 @@ static phys_addr_t __init_memblock __find_max_addr(phys_addr_t limit)
15371537

15381538
void __init memblock_enforce_memory_limit(phys_addr_t limit)
15391539
{
1540-
phys_addr_t max_addr = (phys_addr_t)ULLONG_MAX;
1540+
phys_addr_t max_addr = PHYS_ADDR_MAX;
15411541

15421542
if (!limit)
15431543
return;
15441544

15451545
max_addr = __find_max_addr(limit);
15461546

15471547
/* @limit exceeds the total size of the memory, do nothing */
1548-
if (max_addr == (phys_addr_t)ULLONG_MAX)
1548+
if (max_addr == PHYS_ADDR_MAX)
15491549
return;
15501550

15511551
/* truncate both memory and reserved regions */
15521552
memblock_remove_range(&memblock.memory, max_addr,
1553-
(phys_addr_t)ULLONG_MAX);
1553+
PHYS_ADDR_MAX);
15541554
memblock_remove_range(&memblock.reserved, max_addr,
1555-
(phys_addr_t)ULLONG_MAX);
1555+
PHYS_ADDR_MAX);
15561556
}
15571557

15581558
void __init memblock_cap_memory_range(phys_addr_t base, phys_addr_t size)
@@ -1580,7 +1580,7 @@ void __init memblock_cap_memory_range(phys_addr_t base, phys_addr_t size)
15801580
/* truncate the reserved regions */
15811581
memblock_remove_range(&memblock.reserved, 0, base);
15821582
memblock_remove_range(&memblock.reserved,
1583-
base + size, (phys_addr_t)ULLONG_MAX);
1583+
base + size, PHYS_ADDR_MAX);
15841584
}
15851585

15861586
void __init memblock_mem_limit_remove_map(phys_addr_t limit)
@@ -1593,7 +1593,7 @@ void __init memblock_mem_limit_remove_map(phys_addr_t limit)
15931593
max_addr = __find_max_addr(limit);
15941594

15951595
/* @limit exceeds the total size of the memory, do nothing */
1596-
if (max_addr == (phys_addr_t)ULLONG_MAX)
1596+
if (max_addr == PHYS_ADDR_MAX)
15971597
return;
15981598

15991599
memblock_cap_memory_range(0, max_addr);

0 commit comments

Comments
 (0)