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

Reply via email to