* [PATCH] memblock: Correct calculation method for overflowing range @size
@ 2023-03-24 5:23 Hongbin Ji
2023-03-24 5:56 ` 电子
0 siblings, 1 reply; 2+ messages in thread
From: Hongbin Ji @ 2023-03-24 5:23 UTC (permalink / raw)
To: rppt; +Cc: akpm, linux-mm, linux-kernel, Hongbin Ji
When memblock users to specify range where @base + @size overflows
and automatically cap it at maximum, The new size should be
PHYS_ADDR_MAX - @base + 1.
Assuming that base is 0, PHYS_ADDR_MAX is 0xff, which is 255 in decimal,
then @size should be 256 instead of 255
Signed-off-by: Hongbin Ji <jhb_ee@163.com>
---
mm/memblock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/memblock.c b/mm/memblock.c
index 25fd0626a9e7..f1683d1dae65 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -169,7 +169,7 @@ static enum memblock_flags __init_memblock choose_memblock_flags(void)
/* adjust *@size so that (@base + *@size) doesn't overflow, return new size */
static inline phys_addr_t memblock_cap_size(phys_addr_t base, phys_addr_t *size)
{
- return *size = min(*size, PHYS_ADDR_MAX - base);
+ return *size = min(*size, PHYS_ADDR_MAX - base + 1);
}
/*
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread* Re:[PATCH] memblock: Correct calculation method for overflowing range @size
2023-03-24 5:23 [PATCH] memblock: Correct calculation method for overflowing range @size Hongbin Ji
@ 2023-03-24 5:56 ` 电子
0 siblings, 0 replies; 2+ messages in thread
From: 电子 @ 2023-03-24 5:56 UTC (permalink / raw)
To: rppt; +Cc: akpm, linux-mm, linux-kernel
Sorry, the size here may be calculated according to this formula, cancel this patch
At 2023-03-24 13:23:51, "Hongbin Ji" <jhb_ee@163.com> wrote:
>When memblock users to specify range where @base + @size overflows
>and automatically cap it at maximum, The new size should be
>PHYS_ADDR_MAX - @base + 1.
>
>Assuming that base is 0, PHYS_ADDR_MAX is 0xff, which is 255 in decimal,
>then @size should be 256 instead of 255
>
>Signed-off-by: Hongbin Ji <jhb_ee@163.com>
>---
> mm/memblock.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/mm/memblock.c b/mm/memblock.c
>index 25fd0626a9e7..f1683d1dae65 100644
>--- a/mm/memblock.c
>+++ b/mm/memblock.c
>@@ -169,7 +169,7 @@ static enum memblock_flags __init_memblock choose_memblock_flags(void)
> /* adjust *@size so that (@base + *@size) doesn't overflow, return new size */
> static inline phys_addr_t memblock_cap_size(phys_addr_t base, phys_addr_t *size)
> {
>- return *size = min(*size, PHYS_ADDR_MAX - base);
>+ return *size = min(*size, PHYS_ADDR_MAX - base + 1);
> }
>
> /*
>--
>2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-24 6:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-24 5:23 [PATCH] memblock: Correct calculation method for overflowing range @size Hongbin Ji
2023-03-24 5:56 ` 电子
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®