All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] drm/dsi: use stack buffer in mipi_dsi_dcs_write()
@ 2020-05-05 16:03 Emil Velikov
  2020-05-05 16:03 ` [PATCH 2/3] drm/panel: use mipi_dsi_dcs_write_buffer where possible Emil Velikov
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Emil Velikov @ 2020-05-05 16:03 UTC (permalink / raw)
  To: dri-devel; +Cc: Jani Nikula, Thierry Reding, emil.l.velikov

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>
---
 drivers/gpu/drm/drm_mipi_dsi.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
index 55531895dde6..b96d5b4629d7 100644
--- a/drivers/gpu/drm/drm_mipi_dsi.c
+++ b/drivers/gpu/drm/drm_mipi_dsi.c
@@ -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;
-- 
2.25.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2020-06-29  7:58 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-05 16:03 [PATCH 1/3] drm/dsi: use stack buffer in mipi_dsi_dcs_write() Emil Velikov
2020-05-05 16:03 ` [PATCH 2/3] drm/panel: use mipi_dsi_dcs_write_buffer where possible Emil Velikov
2020-05-11 11:28   ` Emil Velikov
2020-06-29  7:46     ` Sam Ravnborg
2020-05-05 16:03 ` [PATCH 3/3] drm/mipi: use dcs write for mipi_dsi_dcs_set_tear_scanline Emil Velikov
2020-05-07 12:29   ` Vinay Simha B N
2020-05-07 16:18     ` Emil Velikov
2020-05-13  9:44       ` Emil Velikov
2020-06-07 16:17         ` Vinay Simha B N
2020-06-05 17:36   ` Thierry Reding
2020-06-29  7:47   ` Sam Ravnborg
2020-05-28 16:47 ` [PATCH 1/3] drm/dsi: use stack buffer in mipi_dsi_dcs_write() Emil Velikov
2020-06-05 17:37   ` Thierry Reding
2020-06-05 17:26 ` Thierry Reding
2020-06-29  7:46 ` Sam Ravnborg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.