[PATCH 02/12] drm/panic: Make allocation of zlib workspace more robust

Thomas Zimmermann <[email protected]>
Newsgroups dev.linux.lists.virtualization,dev.linux.lists.imx,dev.linux.lists.sashiko-reviews,org.freedesktop.lists.amd-gfx,org.freedesktop.lists.dri-devel,org.freedesktop.lists.intel-gfx,org.freedesktop.lists.intel-xe,org.freedesktop.lists.nouveau,org.infradead.lists.linux-arm-kernel,org.kernel.vger.linux-doc,org.kernel.vger.linux-hyperv,org.kernel.vger.linux-renesas-soc,org.kernel.vger.rust-for-linux
Message-ID <[email protected]>
Test the zlib workspace size to not have a negative value. This
would be a driver bug. Also touch allocated memory so that the
pages are available upon a panic.

Signed-off-by: Thomas Zimmermann <[email protected]>
---
 drivers/gpu/drm/drm_panic.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_panic.c b/drivers/gpu/drm/drm_panic.c
index 0685f7d8dba2..705b72bf0d83 100644
--- a/drivers/gpu/drm/drm_panic.c
+++ b/drivers/gpu/drm/drm_panic.c
@@ -634,13 +634,19 @@ static struct z_stream_s stream;
 
 static void __init drm_panic_qr_init(void)
 {
+	int wssize;
+
+	wssize = zlib_deflate_workspacesize(WINDOW_BITS, MEM_LEVEL);
+	if (WARN_ON_ONCE(wssize < 0))
+		return;
 	/* best-effort allocation; can be NULL */
-	stream.workspace = kmalloc(zlib_deflate_workspacesize(WINDOW_BITS, MEM_LEVEL),
-				   GFP_KERNEL);
+	stream.workspace = kmalloc(wssize, GFP_KERNEL);
 
 	/* touch memory so that pages are there in the case of a panic */
 	memset(qrbuf1, 0, sizeof(qrbuf1));
 	memset(qrbuf2, 0, sizeof(qrbuf2));
+	if (stream.workspace)
+		memset(stream.workspace, 0, wssize);
 }
 
 static void drm_panic_qr_exit(void)
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.