From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93908248883; Tue, 29 Apr 2025 18:05:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745949935; cv=none; b=Y7S49nJ3NxSRS/jpdYJlx4Mlgfx41YpZxVMF9HiYYMTmaqTrkMmip21z6cjHXPNKqbPDvLu8XIFDuvCxmBWQTqyMMJt0k2WtMf0ek5+sf7BF7b4RP1dsxSAHEkkqFIqe0M/4zHzsVRU6ApIsELe1+77nh63C58H7OaYVrlNVlvY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745949935; c=relaxed/simple; bh=rmsYIhGr+VqVvJHzJS1s3XT7F8NpqOroFCnu1WF9UjY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K8YHRIavYQSlH6kgA/jtTAkXZztlG3HoQvMaNlcWaBJ3lmu49LlewxGevIP9mDH4//5EkjpP+fheypNshQ4ZocyuOP9yT5OlDwq6dpd7EyOkkDzItkdpY41bRKdgrO7cuf2Z9PIQGBSz+BmAI2PzbNEWpIMbk3OyIxBwfYqueRk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=nQWQQ61/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="nQWQQ61/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03004C4CEE3; Tue, 29 Apr 2025 18:05:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1745949935; bh=rmsYIhGr+VqVvJHzJS1s3XT7F8NpqOroFCnu1WF9UjY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nQWQQ61/kDPoCI6xf2uf1N/vt4NWBDG9Gj6cT0ySA7hfOMHxOKNyy+RlVnZcXeV7A OiQq7Zc/7YGJ0d5keBavnFC0P5DRGw+GtEA3y310gYQs+BrdsSgqfJg0i9vz+AvRY7 9S8ICOEiWCOBgYvSnH9A3GFrbixlVwnLIVYXea+4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Haoxiang Li , Heiko Carstens , Vasily Gorbik , Sasha Levin Subject: [PATCH 6.1 104/167] s390/tty: Fix a potential memory leak bug Date: Tue, 29 Apr 2025 18:43:32 +0200 Message-ID: <20250429161055.956245798@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250429161051.743239894@linuxfoundation.org> References: <20250429161051.743239894@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Haoxiang Li [ Upstream commit ad9bb8f049717d64c5e62b2a44954be9f681c65b ] 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 Acked-by: Heiko Carstens Link: https://lore.kernel.org/r/20250218034104.2436469-1-haoxiang_li2024@163.com Signed-off-by: Vasily Gorbik Signed-off-by: Sasha Levin --- drivers/s390/char/sclp_tty.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/s390/char/sclp_tty.c b/drivers/s390/char/sclp_tty.c index 971fbb52740bf..432dad2a22664 100644 --- a/drivers/s390/char/sclp_tty.c +++ b/drivers/s390/char/sclp_tty.c @@ -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; } -- 2.39.5