drm/ssd130x: Remove hardcoded bits-per-pixel in ssd130x_buf_alloc()
authorJavier Martinez Canillas <javierm@redhat.com>
Fri, 9 Jun 2023 17:09:40 +0000 (19:09 +0200)
committerJavier Martinez Canillas <javierm@redhat.com>
Thu, 15 Jun 2023 21:50:46 +0000 (23:50 +0200)
The driver only supports OLED controllers that have a native DRM_FORMAT_C1
pixel format and that is why it has harcoded a division of the width by 8.

But the driver might be extended to support devices that have a different
pixel format. So it's better to use the struct drm_format_info helpers to
compute the size of the buffer, used to store the pixels in native format.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20230609170941.1150941-6-javierm@redhat.com
drivers/gpu/drm/solomon/ssd130x.c

index 0be3b47..b3dc1ca 100644 (file)
@@ -150,9 +150,16 @@ static int ssd130x_buf_alloc(struct ssd130x_device *ssd130x)
 {
        unsigned int page_height = ssd130x->device_info->page_height;
        unsigned int pages = DIV_ROUND_UP(ssd130x->height, page_height);
+       const struct drm_format_info *fi;
+       unsigned int pitch;
 
-       ssd130x->buffer = kcalloc(DIV_ROUND_UP(ssd130x->width, 8),
-                                 ssd130x->height, GFP_KERNEL);
+       fi = drm_format_info(DRM_FORMAT_C1);
+       if (!fi)
+               return -EINVAL;
+
+       pitch = drm_format_info_min_pitch(fi, 0, ssd130x->width);
+
+       ssd130x->buffer = kcalloc(pitch, ssd130x->height, GFP_KERNEL);
        if (!ssd130x->buffer)
                return -ENOMEM;