]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
Input: ili210x - use kvmalloc() to allocate buffer for firmware update
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Sun, 9 Jun 2024 23:47:53 +0000 (16:47 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 12 Sep 2024 09:11:31 +0000 (11:11 +0200)
[ Upstream commit 17f5eebf6780eee50f887542e1833fda95f53e4d ]

Allocating a contiguous buffer of 64K may fail if memory is sufficiently
fragmented, and may cause OOM kill of an unrelated process. However we
do not need to have contiguous memory. We also do not need to zero
out the buffer since it will be overwritten with firmware data.

Switch to using kvmalloc() instead of kzalloc().

Link: https://lore.kernel.org/r/20240609234757.610273-1-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/input/touchscreen/ili210x.c

index ae7ba0c419f5a77b268b26c75007c8a52507ab41..6a77babcf7228e6afeff22d59a283e3029e48538 100644 (file)
@@ -597,7 +597,7 @@ static int ili251x_firmware_to_buffer(const struct firmware *fw,
         * once, copy them all into this buffer at the right locations, and then
         * do all operations on this linear buffer.
         */
-       fw_buf = kzalloc(SZ_64K, GFP_KERNEL);
+       fw_buf = kvmalloc(SZ_64K, GFP_KERNEL);
        if (!fw_buf)
                return -ENOMEM;
 
@@ -627,7 +627,7 @@ static int ili251x_firmware_to_buffer(const struct firmware *fw,
        return 0;
 
 err_big:
-       kfree(fw_buf);
+       kvfree(fw_buf);
        return error;
 }
 
@@ -870,7 +870,7 @@ exit:
        ili210x_hardware_reset(priv->reset_gpio);
        dev_dbg(dev, "Firmware update ended, error=%i\n", error);
        enable_irq(client->irq);
-       kfree(fwbuf);
+       kvfree(fwbuf);
        return error;
 }