From: Thomas Zimmermann <tzimmermann@suse.de>
To: linux@armlinux.org.uk, airlied@gmail.com, simona@ffwll.ch,
mripard@kernel.org, maarten.lankhorst@linux.intel.com
Cc: dri-devel@lists.freedesktop.org, sashiko-reviews@lists.linux.dev,
Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH v2 1/3] drm/armada: fbdev: Calculate buffer geometry with format helpers
Date: Thu, 11 Jun 2026 09:20:11 +0200 [thread overview]
Message-ID: <20260611072121.71492-2-tzimmermann@suse.de> (raw)
In-Reply-To: <20260611072121.71492-1-tzimmermann@suse.de>
Replace the geometry and size calculation in armada's fbdev emulation
with DRM format helpers. This consists of a 4CC lookup from the fbdev
parameters, format lookup, pitch calculation and size calculation.
Then allocate the GEM buffer object for the framebuffer memory from
the calculated size. Mmap provides the allocated buffer to user space,
so align the buffer size to PAGE_SIZE.
Slightly rearrange cleaning up the GEM object and rolling back on
errors. This will simplify error handling when the code uses client
buffers.
v2:
- add more error checks to geometry calculations
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
drivers/gpu/drm/armada/armada_fbdev.c | 65 ++++++++++++++++-----------
1 file changed, 39 insertions(+), 26 deletions(-)
diff --git a/drivers/gpu/drm/armada/armada_fbdev.c b/drivers/gpu/drm/armada/armada_fbdev.c
index 8bbae94804f8..f95658091acf 100644
--- a/drivers/gpu/drm/armada/armada_fbdev.c
+++ b/drivers/gpu/drm/armada/armada_fbdev.c
@@ -45,20 +45,30 @@ int armada_fbdev_driver_fbdev_probe(struct drm_fb_helper *fbh,
{
struct drm_device *dev = fbh->dev;
struct fb_info *info = fbh->info;
+ u32 fourcc, pitch;
+ u64 size;
+ const struct drm_format_info *format;
struct drm_mode_fb_cmd2 mode;
struct armada_framebuffer *dfb;
struct armada_gem_object *obj;
- int size, ret;
+ int ret;
void *ptr;
- memset(&mode, 0, sizeof(mode));
- mode.width = sizes->surface_width;
- mode.height = sizes->surface_height;
- mode.pitches[0] = armada_pitch(mode.width, sizes->surface_bpp);
- mode.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
- sizes->surface_depth);
+ fourcc = drm_mode_legacy_fb_format(sizes->surface_bpp, sizes->surface_depth);
+ if (fourcc == DRM_FORMAT_INVALID)
+ return -EINVAL;
+ format = drm_get_format_info(dev, fourcc, DRM_FORMAT_MOD_LINEAR);
+ if (!format)
+ return -EINVAL;
+ pitch = armada_pitch(sizes->surface_width, drm_format_info_bpp(format, 0));
+ if (!pitch)
+ return -EINVAL;
+ if (check_mul_overflow(pitch, sizes->surface_height, &size))
+ return -EINVAL;
+ size = ALIGN(size, PAGE_SIZE);
+ if (size < PAGE_SIZE)
+ return -EINVAL;
- size = mode.pitches[0] * mode.height;
obj = armada_gem_alloc_private_object(dev, size);
if (!obj) {
DRM_ERROR("failed to allocate fb memory\n");
@@ -66,30 +76,26 @@ int armada_fbdev_driver_fbdev_probe(struct drm_fb_helper *fbh,
}
ret = armada_gem_linear_back(dev, obj);
- if (ret) {
- drm_gem_object_put(&obj->obj);
- return ret;
- }
+ if (ret)
+ goto err_drm_gem_object_put;
ptr = armada_gem_map_object(dev, obj);
if (!ptr) {
- drm_gem_object_put(&obj->obj);
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto err_drm_gem_object_put;
}
- dfb = armada_framebuffer_create(dev,
- drm_get_format_info(dev, mode.pixel_format,
- mode.modifier[0]),
- &mode, obj);
-
- /*
- * A reference is now held by the framebuffer object if
- * successful, otherwise this drops the ref for the error path.
- */
- drm_gem_object_put(&obj->obj);
+ memset(&mode, 0, sizeof(mode));
+ mode.width = sizes->surface_width;
+ mode.height = sizes->surface_height;
+ mode.pitches[0] = pitch;
+ mode.pixel_format = fourcc;
- if (IS_ERR(dfb))
- return PTR_ERR(dfb);
+ dfb = armada_framebuffer_create(dev, format, &mode, obj);
+ if (IS_ERR(dfb)) {
+ ret = PTR_ERR(dfb);
+ goto err_drm_gem_object_put;
+ }
info->fbops = &armada_fb_ops;
info->fix.smem_start = obj->phys_addr;
@@ -105,5 +111,12 @@ int armada_fbdev_driver_fbdev_probe(struct drm_fb_helper *fbh,
dfb->fb.width, dfb->fb.height, dfb->fb.format->cpp[0] * 8,
(unsigned long long)obj->phys_addr);
+ /* The framebuffer still holds a reference on the GEM object. */
+ drm_gem_object_put(&obj->obj);
+
return 0;
+
+err_drm_gem_object_put:
+ drm_gem_object_put(&obj->obj);
+ return ret;
}
--
2.54.0
next prev parent reply other threads:[~2026-06-11 7:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-11 7:20 [PATCH v2 0/3] drm/armada: fbdev: Use client buffers Thomas Zimmermann
2026-06-11 7:20 ` Thomas Zimmermann [this message]
2026-06-11 7:30 ` [PATCH v2 1/3] drm/armada: fbdev: Calculate buffer geometry with format helpers sashiko-bot
2026-06-11 7:20 ` [PATCH v2 2/3] drm/armada: fbdev: Use a DRM client buffer Thomas Zimmermann
2026-06-11 7:20 ` [PATCH v2 3/3] drm/armada: Make armada_framebuffer_create() an internal interface Thomas Zimmermann
2026-06-11 7:28 ` sashiko-bot
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=20260611072121.71492-2-tzimmermann@suse.de \
--to=tzimmermann@suse.de \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux@armlinux.org.uk \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=simona@ffwll.ch \
/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 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.