]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
drm/dsi: use stack buffer in mipi_dsi_dcs_write()
authorEmil Velikov <emil.l.velikov@gmail.com>
Tue, 5 May 2020 16:03:27 +0000 (17:03 +0100)
committerSam Ravnborg <sam@ravnborg.org>
Mon, 29 Jun 2020 07:40:41 +0000 (09:40 +0200)
Currently the function heap allocates when we have any payload. Where in
many case the payload is 1 byte - ouch.

>From casual observation, vast majority of the payloads are smaller than
8 bytes - so use a stack array tx[8] to avoid the senseless kmalloc and
kfree dance.

Cc: Jani Nikula <jani.nikula@intel.com>
Cc: Thierry Reding <treding@nvidia.com>
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20200505160329.2976059-1-emil.l.velikov@gmail.com
drivers/gpu/drm/drm_mipi_dsi.c

index 55531895dde6d53a70792712c00608704801b13a..b96d5b4629d7bb94100ae8609f3094ca6fa1d2c7 100644 (file)
@@ -748,26 +748,26 @@ ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd,
 {
        ssize_t err;
        size_t size;
+       u8 stack_tx[8];
        u8 *tx;
 
-       if (len > 0) {
-               size = 1 + len;
-
+       size = 1 + len;
+       if (len > ARRAY_SIZE(stack_tx) - 1) {
                tx = kmalloc(size, GFP_KERNEL);
                if (!tx)
                        return -ENOMEM;
-
-               /* concatenate the DCS command byte and the payload */
-               tx[0] = cmd;
-               memcpy(&tx[1], data, len);
        } else {
-               tx = &cmd;
-               size = 1;
+               tx = stack_tx;
        }
 
+       /* concatenate the DCS command byte and the payload */
+       tx[0] = cmd;
+       if (data)
+               memcpy(&tx[1], data, len);
+
        err = mipi_dsi_dcs_write_buffer(dsi, tx, size);
 
-       if (len > 0)
+       if (tx != stack_tx)
                kfree(tx);
 
        return err;