Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit e254b58

Browse files
drm/ssd130x: Remove hardcoded bits-per-pixel in ssd130x_buf_alloc()
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 <[email protected]> Reviewed-by: Thomas Zimmermann <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 49d7d58 commit e254b58

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/gpu/drm/solomon/ssd130x.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,16 @@ static int ssd130x_buf_alloc(struct ssd130x_device *ssd130x)
150150
{
151151
unsigned int page_height = ssd130x->device_info->page_height;
152152
unsigned int pages = DIV_ROUND_UP(ssd130x->height, page_height);
153+
const struct drm_format_info *fi;
154+
unsigned int pitch;
153155

154-
ssd130x->buffer = kcalloc(DIV_ROUND_UP(ssd130x->width, 8),
155-
ssd130x->height, GFP_KERNEL);
156+
fi = drm_format_info(DRM_FORMAT_C1);
157+
if (!fi)
158+
return -EINVAL;
159+
160+
pitch = drm_format_info_min_pitch(fi, 0, ssd130x->width);
161+
162+
ssd130x->buffer = kcalloc(pitch, ssd130x->height, GFP_KERNEL);
156163
if (!ssd130x->buffer)
157164
return -ENOMEM;
158165

0 commit comments

Comments
 (0)