Commit e192fba2 authored by Emil Velikov's avatar Emil Velikov Committed by Sam Ravnborg

drm/dsi: use stack buffer in mipi_dsi_dcs_write()

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: default avatarEmil Velikov <emil.velikov@collabora.com>
Reviewed-by: default avatarThierry Reding <treding@nvidia.com>
Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20200505160329.2976059-1-emil.l.velikov@gmail.com
parent 8767c3fc
...@@ -748,26 +748,26 @@ ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd, ...@@ -748,26 +748,26 @@ ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd,
{ {
ssize_t err; ssize_t err;
size_t size; size_t size;
u8 stack_tx[8];
u8 *tx; u8 *tx;
if (len > 0) { size = 1 + len;
size = 1 + len; if (len > ARRAY_SIZE(stack_tx) - 1) {
tx = kmalloc(size, GFP_KERNEL); tx = kmalloc(size, GFP_KERNEL);
if (!tx) if (!tx)
return -ENOMEM; return -ENOMEM;
/* concatenate the DCS command byte and the payload */
tx[0] = cmd;
memcpy(&tx[1], data, len);
} else { } else {
tx = &cmd; tx = stack_tx;
size = 1;
} }
/* 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); err = mipi_dsi_dcs_write_buffer(dsi, tx, size);
if (len > 0) if (tx != stack_tx)
kfree(tx); kfree(tx);
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment