[PATCH v5 2/2] drm/ssd130x: Allocate buffer in the plane's .atomic_check() callback

Javier Martinez Canillas javierm at redhat.com
Wed Jul 26 12:25:15 UTC 2023


Geert Uytterhoeven <geert at linux-m68k.org> writes:

> Hi Javier,
>
> On Wed, Jul 26, 2023 at 12:55 PM Javier Martinez Canillas
> <javierm at redhat.com> wrote:
>> Drivers are not allowed to fail after drm_atomic_helper_swap_state() has
>> been called and the new atomic state is stored into the current sw state.
>>
>> Since the struct ssd130x_device .data_array is allocated in the encoder's
>> .atomic_enable callback, the operation can fail and this is after the new
>> state has been stored. So it can break an atomic mode settings assumption.
>>
>> Fix this by having custom helpers to allocate, duplicate and destroy the
>> plane state, that will take care of allocating and freeing these buffers.
>>
>> Suggested-by: Maxime Ripard <mripard at kernel.org>
>> Signed-off-by: Javier Martinez Canillas <javierm at redhat.com>
>> Acked-by: Maxime Ripard <mripard at kernel.org>
>> Tested-by: Geert Uytterhoeven <geert at linux-m68k.org>
>> ---
>>
>> Changes in v5:
>> - Add collected tags from Maxime and Geert.
>> - Update commit message to not mention the kernel oops (Geert Uytterhoeven).
>> - Drop Reported-by and Fixes tags (Geert Uytterhoeven).
>> - Update comment about buffer and data_array fields (Geert Uytterhoeven).
>> - Remove superfluous NULL check in ssd130x_fb_blit_rect() (Geert Uytterhoeven).
>> - Reset .buffer to NULL if .data_array allocation fails (Geert Uytterhoeven).
>> - Inline buffer alloc/free helper functions (Geert Uytterhoeven).
>
> Thanks for the update!
>

You are welcome, and thanks for the review!

>> --- a/drivers/gpu/drm/solomon/ssd130x.c
>> +++ b/drivers/gpu/drm/solomon/ssd130x.c
>
>> @@ -535,7 +550,8 @@ static int ssd130x_update_rect(struct ssd130x_device *ssd130x, struct drm_rect *
>>         return ret;
>>  }
>>
>> -static void ssd130x_clear_screen(struct ssd130x_device *ssd130x)
>> +static void ssd130x_clear_screen(struct ssd130x_device *ssd130x,
>> +                                struct ssd130x_plane_state *ssd130x_state)
>>  {
>>         struct drm_rect fullscreen = {
>>                 .x1 = 0,
>> @@ -544,21 +560,21 @@ static void ssd130x_clear_screen(struct ssd130x_device *ssd130x)
>>                 .y2 = ssd130x->height,
>>         };
>>
>> -       ssd130x_update_rect(ssd130x, &fullscreen);
>> +       ssd130x_update_rect(ssd130x, ssd130x_state, &fullscreen);
>
> I've just realized another issue: since 49d7d581ceaf4cf8 ("drm/ssd130x:
> Don't allocate buffers on each plane update"). this no longer
> clears the screens, but just updates the hardware with the data in
> ssd130x_device.buffer, i.e. with the last image shown.
> So this should at least clear all of ssd130x_device.buffer before
> calling ssd130x_update_rect().
>

Oh, you are right. I missed that.

> As it's a bit pointless to transpose a black image, a better fix would
> be to just clear ssd130x.data_array, and call the low-level hardware
> functions like ssd130x_update_rect() does.
>

Yeah, this is a left over when we used to allocate a buffer here and I
agree with you that calling ssd130x_update_rect() is a pointless.

We can fix this as a separate follow-up patch though if you agree.

-- 
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat



More information about the dri-devel mailing list