]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
s390/tty: Fix a potential memory leak bug
authorHaoxiang Li <haoxiang_li2024@163.com>
Tue, 18 Feb 2025 03:41:04 +0000 (11:41 +0800)
committerVasily Gorbik <gor@linux.ibm.com>
Tue, 4 Mar 2025 16:18:08 +0000 (17:18 +0100)
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>
drivers/s390/char/sclp_tty.c

index acd5ea0f7381ca52c00ba4a24adfc2d742206da9..0a92d08830e7c4972af5923e5a40fff24af89364 100644 (file)
@@ -490,6 +490,17 @@ static const struct tty_operations sclp_ops = {
        .flush_buffer = sclp_tty_flush_buffer,
 };
 
+/* Release allocated pages. */
+static void __init __sclp_tty_free_pages(void)
+{
+       struct list_head *page, *p;
+
+       list_for_each_safe(page, p, &sclp_tty_pages) {
+               list_del(page);
+               free_page((unsigned long)page);
+       }
+}
+
 static int __init
 sclp_tty_init(void)
 {
@@ -516,6 +527,7 @@ sclp_tty_init(void)
        for (i = 0; i < MAX_KMEM_PAGES; i++) {
                page = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
                if (page == NULL) {
+                       __sclp_tty_free_pages();
                        tty_driver_kref_put(driver);
                        return -ENOMEM;
                }