linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc/mm: Fix null-pointer dereference in pgtable_cache_add
@ 2023-11-22  9:00 Kunwu Chan
  2023-11-24 15:17 ` Christophe Leroy
  0 siblings, 1 reply; 5+ messages in thread
From: Kunwu Chan @ 2023-11-22  9:00 UTC (permalink / raw)
  To: mpe, npiggin, christophe.leroy
  Cc: linuxppc-dev, linux-kernel, Kunwu Chan, kunwu.chan

kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful
by checking the pointer validity.

Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 arch/powerpc/mm/init-common.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/mm/init-common.c b/arch/powerpc/mm/init-common.c
index 119ef491f797..0884fc601c46 100644
--- a/arch/powerpc/mm/init-common.c
+++ b/arch/powerpc/mm/init-common.c
@@ -139,6 +139,8 @@ void pgtable_cache_add(unsigned int shift)
 
 	align = max_t(unsigned long, align, minalign);
 	name = kasprintf(GFP_KERNEL, "pgtable-2^%d", shift);
+	if (!name)
+		return;
 	new = kmem_cache_create(name, table_size, align, 0, ctor(shift));
 	if (!new)
 		panic("Could not allocate pgtable cache for order %d", shift);
-- 
2.34.1


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

end of thread, other threads:[~2023-11-30  8:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-22  9:00 [PATCH] powerpc/mm: Fix null-pointer dereference in pgtable_cache_add Kunwu Chan
2023-11-24 15:17 ` Christophe Leroy
2023-11-27  6:04   ` Kunwu Chan
2023-11-28 11:32     ` Michael Ellerman
     [not found]     ` <1701224210300483.328.seg@mailgw>
2023-11-30  8:45       ` Kunwu Chan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).