drivers/gpu/drm/tiny/repaper.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
Use drm_format_info_min_pitch() to calculate the framebuffer line pitch
instead of directly multiplying width and height. This aligns with DRM
helpers for determining per-line byte size and avoids manual assumptions
about bytes per pixel.
Suggested-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>
---
drivers/gpu/drm/tiny/repaper.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/tiny/repaper.c b/drivers/gpu/drm/tiny/repaper.c
index 4824f863fdba..aeff49bc6ba7 100644
--- a/drivers/gpu/drm/tiny/repaper.c
+++ b/drivers/gpu/drm/tiny/repaper.c
@@ -517,6 +517,8 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb, const struct iosys_map *
unsigned int dst_pitch = 0;
struct iosys_map dst;
struct drm_rect clip;
+ const struct drm_format_info *info = fb->format;
+ size_t pitch;
int idx, ret = 0;
u8 *buf = NULL;
@@ -534,7 +536,9 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb, const struct iosys_map *
DRM_DEBUG("Flushing [FB:%d] st=%ums\n", fb->base.id,
epd->factored_stage_time);
- buf = kmalloc(fb->width * fb->height / 8, GFP_KERNEL);
+ pitch = drm_format_info_min_pitch(info, 0, fb->width);
+
+ buf = kmalloc_array(fb->height, pitch, GFP_KERNEL);
if (!buf) {
ret = -ENOMEM;
goto out_exit;
--
2.51.1.dirty
Hi
Am 20.10.25 um 13:57 schrieb Mehdi Ben Hadj Khelifa:
> Use drm_format_info_min_pitch() to calculate the framebuffer line pitch
> instead of directly multiplying width and height. This aligns with DRM
> helpers for determining per-line byte size and avoids manual assumptions
> about bytes per pixel.
>
> Suggested-by: Thomas Zimmermann <tzimmermann@suse.de>
> Signed-off-by: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>
> ---
> drivers/gpu/drm/tiny/repaper.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/tiny/repaper.c b/drivers/gpu/drm/tiny/repaper.c
> index 4824f863fdba..aeff49bc6ba7 100644
> --- a/drivers/gpu/drm/tiny/repaper.c
> +++ b/drivers/gpu/drm/tiny/repaper.c
> @@ -517,6 +517,8 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb, const struct iosys_map *
> unsigned int dst_pitch = 0;
> struct iosys_map dst;
> struct drm_rect clip;
> + const struct drm_format_info *info = fb->format;
This is the wrong format. You're allocating the output buffer here, but
you're using the input format. IIUC the output format is DRM_FORMAT_R1.
The input is _XRGB8888.
Best regards
Thomas
> + size_t pitch;
> int idx, ret = 0;
> u8 *buf = NULL;
>
> @@ -534,7 +536,9 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb, const struct iosys_map *
> DRM_DEBUG("Flushing [FB:%d] st=%ums\n", fb->base.id,
> epd->factored_stage_time);
>
> - buf = kmalloc(fb->width * fb->height / 8, GFP_KERNEL);
> + pitch = drm_format_info_min_pitch(info, 0, fb->width);
> +
> + buf = kmalloc_array(fb->height, pitch, GFP_KERNEL);
> if (!buf) {
> ret = -ENOMEM;
> goto out_exit;
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
On 10/21/25 7:51 AM, Thomas Zimmermann wrote:
> Hi
>
> Am 20.10.25 um 13:57 schrieb Mehdi Ben Hadj Khelifa:
>> Use drm_format_info_min_pitch() to calculate the framebuffer line pitch
>> instead of directly multiplying width and height. This aligns with DRM
>> helpers for determining per-line byte size and avoids manual assumptions
>> about bytes per pixel.
>>
>> Suggested-by: Thomas Zimmermann <tzimmermann@suse.de>
>> Signed-off-by: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>
>> ---
>> drivers/gpu/drm/tiny/repaper.c | 6 +++++-
>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/tiny/repaper.c b/drivers/gpu/drm/tiny/
>> repaper.c
>> index 4824f863fdba..aeff49bc6ba7 100644
>> --- a/drivers/gpu/drm/tiny/repaper.c
>> +++ b/drivers/gpu/drm/tiny/repaper.c
>> @@ -517,6 +517,8 @@ static int repaper_fb_dirty(struct drm_framebuffer
>> *fb, const struct iosys_map *
>> unsigned int dst_pitch = 0;
>> struct iosys_map dst;
>> struct drm_rect clip;
>> + const struct drm_format_info *info = fb->format;
>
> This is the wrong format. You're allocating the output buffer here, but
> you're using the input format. IIUC the output format is DRM_FORMAT_R1.
> The input is _XRGB8888.
>
Ah. Thanks for clarification.I thought since it had the same output
format. I will send a v3 shortly.> Best regards
> Thomas
>
>> + size_t pitch;
>> int idx, ret = 0;
>> u8 *buf = NULL;
>> @@ -534,7 +536,9 @@ static int repaper_fb_dirty(struct drm_framebuffer
>> *fb, const struct iosys_map *
>> DRM_DEBUG("Flushing [FB:%d] st=%ums\n", fb->base.id,
>> epd->factored_stage_time);
>> - buf = kmalloc(fb->width * fb->height / 8, GFP_KERNEL);
>> + pitch = drm_format_info_min_pitch(info, 0, fb->width);
>> +
>> + buf = kmalloc_array(fb->height, pitch, GFP_KERNEL);
>> if (!buf) {
>> ret = -ENOMEM;
>> goto out_exit;
>
Hi
Am 21.10.25 um 10:41 schrieb Mehdi Ben Hadj Khelifa:
> On 10/21/25 7:51 AM, Thomas Zimmermann wrote:
>> Hi
>>
>> Am 20.10.25 um 13:57 schrieb Mehdi Ben Hadj Khelifa:
>>> Use drm_format_info_min_pitch() to calculate the framebuffer line pitch
>>> instead of directly multiplying width and height. This aligns with DRM
>>> helpers for determining per-line byte size and avoids manual
>>> assumptions
>>> about bytes per pixel.
>>>
>>> Suggested-by: Thomas Zimmermann <tzimmermann@suse.de>
>>> Signed-off-by: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>
>>> ---
>>> drivers/gpu/drm/tiny/repaper.c | 6 +++++-
>>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/gpu/drm/tiny/repaper.c b/drivers/gpu/drm/tiny/
>>> repaper.c
>>> index 4824f863fdba..aeff49bc6ba7 100644
>>> --- a/drivers/gpu/drm/tiny/repaper.c
>>> +++ b/drivers/gpu/drm/tiny/repaper.c
>>> @@ -517,6 +517,8 @@ static int repaper_fb_dirty(struct
>>> drm_framebuffer *fb, const struct iosys_map *
>>> unsigned int dst_pitch = 0;
>>> struct iosys_map dst;
>>> struct drm_rect clip;
>>> + const struct drm_format_info *info = fb->format;
>>
>> This is the wrong format. You're allocating the output buffer here,
>> but you're using the input format. IIUC the output format is
>> DRM_FORMAT_R1. The input is _XRGB8888.
>>
> Ah. Thanks for clarification.I thought since it had the same output
> format. I will send a v3 shortly.> Best regards
Maybe just don't do it. This is just churn with no clear goal.
Best regards
Thomas
>> Thomas
>>
>>> + size_t pitch;
>>> int idx, ret = 0;
>>> u8 *buf = NULL;
>>> @@ -534,7 +536,9 @@ static int repaper_fb_dirty(struct
>>> drm_framebuffer *fb, const struct iosys_map *
>>> DRM_DEBUG("Flushing [FB:%d] st=%ums\n", fb->base.id,
>>> epd->factored_stage_time);
>>> - buf = kmalloc(fb->width * fb->height / 8, GFP_KERNEL);
>>> + pitch = drm_format_info_min_pitch(info, 0, fb->width);
>>> +
>>> + buf = kmalloc_array(fb->height, pitch, GFP_KERNEL);
>>> if (!buf) {
>>> ret = -ENOMEM;
>>> goto out_exit;
>>
>
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
On 10/21/25 9:32 AM, Thomas Zimmermann wrote:
> Hi
>
> Am 21.10.25 um 10:41 schrieb Mehdi Ben Hadj Khelifa:
>> On 10/21/25 7:51 AM, Thomas Zimmermann wrote:
>>> Hi
>>>
>>> Am 20.10.25 um 13:57 schrieb Mehdi Ben Hadj Khelifa:
>>>> Use drm_format_info_min_pitch() to calculate the framebuffer line pitch
>>>> instead of directly multiplying width and height. This aligns with DRM
>>>> helpers for determining per-line byte size and avoids manual
>>>> assumptions
>>>> about bytes per pixel.
>>>>
>>>> Suggested-by: Thomas Zimmermann <tzimmermann@suse.de>
>>>> Signed-off-by: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>
>>>> ---
>>>> drivers/gpu/drm/tiny/repaper.c | 6 +++++-
>>>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/gpu/drm/tiny/repaper.c b/drivers/gpu/drm/tiny/
>>>> repaper.c
>>>> index 4824f863fdba..aeff49bc6ba7 100644
>>>> --- a/drivers/gpu/drm/tiny/repaper.c
>>>> +++ b/drivers/gpu/drm/tiny/repaper.c
>>>> @@ -517,6 +517,8 @@ static int repaper_fb_dirty(struct
>>>> drm_framebuffer *fb, const struct iosys_map *
>>>> unsigned int dst_pitch = 0;
>>>> struct iosys_map dst;
>>>> struct drm_rect clip;
>>>> + const struct drm_format_info *info = fb->format;
>>>
>>> This is the wrong format. You're allocating the output buffer here,
>>> but you're using the input format. IIUC the output format is
>>> DRM_FORMAT_R1. The input is _XRGB8888.
>>>
>> Ah. Thanks for clarification.I thought since it had the same output
>> format. I will send a v3 shortly.> Best regards
>
> Maybe just don't do it. This is just churn with no clear goal.
>
Okay,I will abort working on it.Though my goal was to remove the manual
assumption that height is multiple of 8 and to align with other
'correct' API used in other drm drivers as you suggested[1].
[1]:https://lore.kernel.org/all/cb0f0a36-0593-4d4c-8450-d086b9c99d87@suse.de/
Best Regards,
Mehdi Ben Hadj Khelifa> Best regards
> Thomas
>
>>> Thomas
>>>
>>>> + size_t pitch;
>>>> int idx, ret = 0;
>>>> u8 *buf = NULL;
>>>> @@ -534,7 +536,9 @@ static int repaper_fb_dirty(struct
>>>> drm_framebuffer *fb, const struct iosys_map *
>>>> DRM_DEBUG("Flushing [FB:%d] st=%ums\n", fb->base.id,
>>>> epd->factored_stage_time);
>>>> - buf = kmalloc(fb->width * fb->height / 8, GFP_KERNEL);
>>>> + pitch = drm_format_info_min_pitch(info, 0, fb->width);
>>>> +
>>>> + buf = kmalloc_array(fb->height, pitch, GFP_KERNEL);
>>>> if (!buf) {
>>>> ret = -ENOMEM;
>>>> goto out_exit;
>>>
>>
>
Am 21.10.25 um 08:51 schrieb Thomas Zimmermann:
> Hi
>
> Am 20.10.25 um 13:57 schrieb Mehdi Ben Hadj Khelifa:
>> Use drm_format_info_min_pitch() to calculate the framebuffer line pitch
>> instead of directly multiplying width and height. This aligns with DRM
>> helpers for determining per-line byte size and avoids manual assumptions
>> about bytes per pixel.
>>
>> Suggested-by: Thomas Zimmermann <tzimmermann@suse.de>
>> Signed-off-by: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>
>> ---
>> drivers/gpu/drm/tiny/repaper.c | 6 +++++-
>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/tiny/repaper.c
>> b/drivers/gpu/drm/tiny/repaper.c
>> index 4824f863fdba..aeff49bc6ba7 100644
>> --- a/drivers/gpu/drm/tiny/repaper.c
>> +++ b/drivers/gpu/drm/tiny/repaper.c
>> @@ -517,6 +517,8 @@ static int repaper_fb_dirty(struct
>> drm_framebuffer *fb, const struct iosys_map *
>> unsigned int dst_pitch = 0;
>> struct iosys_map dst;
>> struct drm_rect clip;
>> + const struct drm_format_info *info = fb->format;
>
> This is the wrong format. You're allocating the output buffer here,
> but you're using the input format. IIUC the output format is
> DRM_FORMAT_R1. The input is _XRGB8888.
>
> Best regards
> Thomas
>
>> + size_t pitch;
>> int idx, ret = 0;
>> u8 *buf = NULL;
>> @@ -534,7 +536,9 @@ static int repaper_fb_dirty(struct
>> drm_framebuffer *fb, const struct iosys_map *
>> DRM_DEBUG("Flushing [FB:%d] st=%ums\n", fb->base.id,
>> epd->factored_stage_time);
>> - buf = kmalloc(fb->width * fb->height / 8, GFP_KERNEL);
>> + pitch = drm_format_info_min_pitch(info, 0, fb->width);
>> +
>> + buf = kmalloc_array(fb->height, pitch, GFP_KERNEL);
And TBH I'm not sure if we should really convert this call. It's not an
array in the sense of that API.
Good candidates look like 'kmalloc(count * sizeof(<some type or variable>))'
>> if (!buf) {
>> ret = -ENOMEM;
>> goto out_exit;
>
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
On 10/21/25 7:57 AM, Thomas Zimmermann wrote:
>
>
> Am 21.10.25 um 08:51 schrieb Thomas Zimmermann:
>> Hi
>>
>> Am 20.10.25 um 13:57 schrieb Mehdi Ben Hadj Khelifa:
>>> Use drm_format_info_min_pitch() to calculate the framebuffer line pitch
>>> instead of directly multiplying width and height. This aligns with DRM
>>> helpers for determining per-line byte size and avoids manual assumptions
>>> about bytes per pixel.
>>>
>>> Suggested-by: Thomas Zimmermann <tzimmermann@suse.de>
>>> Signed-off-by: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>
>>> ---
>>> drivers/gpu/drm/tiny/repaper.c | 6 +++++-
>>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/gpu/drm/tiny/repaper.c b/drivers/gpu/drm/tiny/
>>> repaper.c
>>> index 4824f863fdba..aeff49bc6ba7 100644
>>> --- a/drivers/gpu/drm/tiny/repaper.c
>>> +++ b/drivers/gpu/drm/tiny/repaper.c
>>> @@ -517,6 +517,8 @@ static int repaper_fb_dirty(struct
>>> drm_framebuffer *fb, const struct iosys_map *
>>> unsigned int dst_pitch = 0;
>>> struct iosys_map dst;
>>> struct drm_rect clip;
>>> + const struct drm_format_info *info = fb->format;
>>
>> This is the wrong format. You're allocating the output buffer here,
>> but you're using the input format. IIUC the output format is
>> DRM_FORMAT_R1. The input is _XRGB8888.
>>
>> Best regards
>> Thomas
>>
>>> + size_t pitch;
>>> int idx, ret = 0;
>>> u8 *buf = NULL;
>>> @@ -534,7 +536,9 @@ static int repaper_fb_dirty(struct
>>> drm_framebuffer *fb, const struct iosys_map *
>>> DRM_DEBUG("Flushing [FB:%d] st=%ums\n", fb->base.id,
>>> epd->factored_stage_time);
>>> - buf = kmalloc(fb->width * fb->height / 8, GFP_KERNEL);
>>> + pitch = drm_format_info_min_pitch(info, 0, fb->width);
>>> +
>>> + buf = kmalloc_array(fb->height, pitch, GFP_KERNEL);
>
> And TBH I'm not sure if we should really convert this call. It's not an
> array in the sense of that API.
>
> Good candidates look like 'kmalloc(count * sizeof(<some type or
> variable>))'
>
I will leave kmalloc in v3. Do you want me to send deep testing
information on this patch?
BR,
Mehdi>>> if (!buf) {
>>> ret = -ENOMEM;
>>> goto out_exit;
>>
>
© 2016 - 2026 Red Hat, Inc.