Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

s390/tty: Fix a potential memory leak bug

The check for get_zeroed_page() leads to a direct return
and overlooked the memory leak caused by loop allocation.
Add a free helper to free spaces allocated by get_zeroed_page().

Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
Acked-by: Heiko Carstens <hca@linux.ibm.com>
Link: https://lore.kernel.org/r/20250218034104.2436469-1-haoxiang_li2024@163.com
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>

authored by

Haoxiang Li and committed by
Vasily Gorbik
ad9bb8f0 3db42c75

+12
+12
drivers/s390/char/sclp_tty.c
··· 490 490 .flush_buffer = sclp_tty_flush_buffer, 491 491 }; 492 492 493 + /* Release allocated pages. */ 494 + static void __init __sclp_tty_free_pages(void) 495 + { 496 + struct list_head *page, *p; 497 + 498 + list_for_each_safe(page, p, &sclp_tty_pages) { 499 + list_del(page); 500 + free_page((unsigned long)page); 501 + } 502 + } 503 + 493 504 static int __init 494 505 sclp_tty_init(void) 495 506 { ··· 527 516 for (i = 0; i < MAX_KMEM_PAGES; i++) { 528 517 page = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA); 529 518 if (page == NULL) { 519 + __sclp_tty_free_pages(); 530 520 tty_driver_kref_put(driver); 531 521 return -ENOMEM; 532 522 }