public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: "Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"David Airlie" <airlied@linux.ie>,
	"Daniel Vetter" <daniel@ffwll.ch>,
	"Javier Martinez Canillas" <javierm@redhat.com>,
	"Noralf Trønnes" <noralf@tronnes.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	Geert Uytterhoeven <geert@linux-m68k.org>
Subject: [PATCH 4/5] drm: ssd130x: Reduce temporary buffer sizes
Date: Tue, 15 Mar 2022 12:07:06 +0100	[thread overview]
Message-ID: <20220315110707.628166-5-geert@linux-m68k.org> (raw)
In-Reply-To: <20220315110707.628166-1-geert@linux-m68k.org>

ssd130x_clear_screen() allocates a temporary buffer sized to hold one
byte per pixel, while it only needs to hold one bit per pixel.

ssd130x_fb_blit_rect() allocates a temporary buffer sized to hold one
byte per pixel for the whole frame buffer, while it only needs to hold
one bit per pixel for the part that is to be updated.
Pass dst_pitch to drm_fb_xrgb8888_to_mono_reversed(), as we have already
calculated it anyway.

Fixes: a61732e808672cfa ("drm: Add driver for Solomon SSD130x OLED displays")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 drivers/gpu/drm/solomon/ssd130x.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/solomon/ssd130x.c b/drivers/gpu/drm/solomon/ssd130x.c
index 7c99af4ce9dd4e5c..38b6c2c14f53644b 100644
--- a/drivers/gpu/drm/solomon/ssd130x.c
+++ b/drivers/gpu/drm/solomon/ssd130x.c
@@ -440,7 +440,8 @@ static void ssd130x_clear_screen(struct ssd130x_device *ssd130x)
 		.y2 = ssd130x->height,
 	};
 
-	buf = kcalloc(ssd130x->width, ssd130x->height, GFP_KERNEL);
+	buf = kcalloc(DIV_ROUND_UP(ssd130x->width, 8), ssd130x->height,
+		      GFP_KERNEL);
 	if (!buf)
 		return;
 
@@ -454,6 +455,7 @@ static int ssd130x_fb_blit_rect(struct drm_framebuffer *fb, const struct iosys_m
 {
 	struct ssd130x_device *ssd130x = drm_to_ssd130x(fb->dev);
 	void *vmap = map->vaddr; /* TODO: Use mapping abstraction properly */
+	unsigned int dst_pitch;
 	int ret = 0;
 	u8 *buf = NULL;
 
@@ -461,11 +463,12 @@ static int ssd130x_fb_blit_rect(struct drm_framebuffer *fb, const struct iosys_m
 	rect->y1 = round_down(rect->y1, 8);
 	rect->y2 = min_t(unsigned int, round_up(rect->y2, 8), ssd130x->height);
 
-	buf = kcalloc(fb->width, fb->height, GFP_KERNEL);
+	dst_pitch = DIV_ROUND_UP(drm_rect_width(rect), 8);
+	buf = kcalloc(dst_pitch, drm_rect_height(rect), GFP_KERNEL);
 	if (!buf)
 		return -ENOMEM;
 
-	drm_fb_xrgb8888_to_mono(buf, 0, vmap, fb, rect);
+	drm_fb_xrgb8888_to_mono(buf, dst_pitch, vmap, fb, rect);
 
 	ssd130x_update_rect(ssd130x, buf, rect);
 
-- 
2.25.1


  parent reply	other threads:[~2022-03-15 11:07 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-15 11:07 [PATCH 0/5] drm: Fix monochrome conversion for sdd130x Geert Uytterhoeven
2022-03-15 11:07 ` [PATCH 1/5] drm/format-helper: Rename drm_fb_xrgb8888_to_mono_reversed() Geert Uytterhoeven
2022-03-15 11:59   ` Javier Martinez Canillas
2022-03-15 13:32   ` Andy Shevchenko
2022-03-15 13:37     ` Geert Uytterhoeven
2022-03-15 11:07 ` [PATCH 2/5] drm/format-helper: Fix XRGB888 to monochrome conversion Geert Uytterhoeven
2022-03-15 12:18   ` Javier Martinez Canillas
2022-03-15 12:48     ` Geert Uytterhoeven
2022-03-15 13:39     ` Andy Shevchenko
2022-03-15 13:38   ` Andy Shevchenko
2022-03-15 11:07 ` [PATCH 3/5] drm: ssd130x: Fix rectangle updates Geert Uytterhoeven
2022-03-15 12:28   ` Javier Martinez Canillas
2022-03-15 11:07 ` Geert Uytterhoeven [this message]
2022-03-15 12:32   ` [PATCH 4/5] drm: ssd130x: Reduce temporary buffer sizes Javier Martinez Canillas
2022-03-15 12:57     ` Geert Uytterhoeven
2022-03-15 13:50   ` Andy Shevchenko
2022-03-15 14:01     ` Geert Uytterhoeven
2022-03-15 11:07 ` [PATCH 5/5] drm/repaper: Reduce temporary buffer size in repaper_fb_dirty() Geert Uytterhoeven
2022-03-15 12:36   ` Javier Martinez Canillas
2022-03-15 13:56   ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220315110707.628166-5-geert@linux-m68k.org \
    --to=geert@linux-m68k.org \
    --cc=airlied@linux.ie \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=javierm@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=noralf@tronnes.org \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox