Skip to content

Commit ad9bb8f

Browse files
Haoxiang LiVasily Gorbik
authored andcommitted
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 <[email protected]> Acked-by: Heiko Carstens <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vasily Gorbik <[email protected]>
1 parent 3db42c7 commit ad9bb8f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

drivers/s390/char/sclp_tty.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,17 @@ static const struct tty_operations sclp_ops = {
490490
.flush_buffer = sclp_tty_flush_buffer,
491491
};
492492

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+
493504
static int __init
494505
sclp_tty_init(void)
495506
{
@@ -516,6 +527,7 @@ sclp_tty_init(void)
516527
for (i = 0; i < MAX_KMEM_PAGES; i++) {
517528
page = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
518529
if (page == NULL) {
530+
__sclp_tty_free_pages();
519531
tty_driver_kref_put(driver);
520532
return -ENOMEM;
521533
}

0 commit comments

Comments
 (0)