linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/mempolicy: prevent the risk of division by 0
@ 2025-09-07 16:08 Chelsy Ratnawat
  2025-09-07 23:53 ` Joshua Hahn
  2025-09-08 18:12 ` Gregory Price
  0 siblings, 2 replies; 6+ messages in thread
From: Chelsy Ratnawat @ 2025-09-07 16:08 UTC (permalink / raw)
  To: akpm, david, joshua.hahnjy, ziy, ying.huang
  Cc: rakie.kim, byungchul, apopple, linux-mm, Chelsy Ratnawat

If no bits are set in the policy's node mask, then nodes will be 0.
This patch adds a check if nodes == 0 before dividing.

Signed-off-by: Chelsy Ratnawat <chelsyratnawat2001@gmail.com>
---
 mm/mempolicy.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index eb83cff7db8c..faacc604fc16 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -2530,6 +2530,8 @@ static unsigned long alloc_pages_bulk_interleave(gfp_t gfp,
 	unsigned long total_allocated = 0;
 
 	nodes = nodes_weight(pol->nodes);
+	if (nodes == 0)
+		return 0;
 	nr_pages_per_node = nr_pages / nodes;
 	delta = nr_pages - nodes * nr_pages_per_node;
 
-- 
2.47.3



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-09-08 21:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-07 16:08 [PATCH] mm/mempolicy: prevent the risk of division by 0 Chelsy Ratnawat
2025-09-07 23:53 ` Joshua Hahn
2025-09-08  3:48   ` Huang, Ying
2025-09-08  7:50     ` David Hildenbrand
2025-09-08 18:12 ` Gregory Price
2025-09-08 21:25   ` Gregory Price

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox