Re: [PATCH RESEND v2 16/32] drm/vkms: Introduce config for plane format

Louis Chauvet
2025-12-19T18:31:10Z

On 12/19/25 15:55, Luca Ceresoli wrote:
> Hi Louis,
>
> On Wed Oct 29, 2025 at 3:36 PM CET, Louis Chauvet wrote:
>> VKMS driver supports all the pixel formats for planes, but for testing it
>> can be useful to only advertise few of them. This new configuration
>> interface will allow configuring the pixel format per planes.
>
> [...]
>
>> Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
>> +int __must_check vkms_config_plane_add_format(struct vkms_config_plane *plane_cfg, u32 drm_format)
>> +{
>> + bool found = false;
>> +
>> + for (int i = 0; i < ARRAY_SIZE(vkms_supported_plane_formats); i++) {
>> + if (vkms_supported_plane_formats[i] == drm_format) {
>> + found = true;
>> + break;
>> + }
>> + }
>> +
>> + if (!found)
>> + return -EINVAL;
>> + for (unsigned int i = 0; i < plane_cfg->supported_formats_count; i++) {
>> + if (plane_cfg->supported_formats[i] == drm_format)
>> + return 0;
>> + }
>> + u32 *new_ptr = krealloc_array(plane_cfg->supported_formats,
>> + plane_cfg->supported_formats_count + 1,
>> + sizeof(*plane_cfg->supported_formats), GFP_KERNEL);
>> + if (!new_ptr)
>> + return -ENOMEM;
>> +
>> + plane_cfg->supported_formats = new_ptr;
>> + plane_cfg->supported_formats[plane_cfg->supported_formats_count] = drm_format;
>> + plane_cfg->supported_formats_count++;
>> +
>> + return 0;
>> +}
>
> This whole logic appears quite complex for what you need here. I suspect
> using the facilities in linux/bitmap.h would make your code simpler by
> allocating a (multi-)ulong array of
> ARRAY_SIZE(vkms_supported_plane_formats) bits. This would surely use less
> memory and avoid all reallocations, too.

I agree this look complex, but I need an array anyway to interface with
DRM core. If I use a bitmap, I would have to manage a mapping bit <=>
fourcc value, which would not be really simpler I think.

I will simplify it a little bit by extracting some helpers for v2:

int __must_check vkms_config_plane_add_format(struct vkms_config_plane
*plane_cfg, u32 drm_format) {
if (!supported_format(drm_format))
return -EINVAL;
if (already_present(drm_format))
return 0;
new_ptr = krealloc
[...]
}

If this is not sufficient, I will take a look at bitfield next year.

>> --- a/drivers/gpu/drm/vkms/vkms_config.h
>> +++ b/drivers/gpu/drm/vkms/vkms_config.h
>
>> +/**
>> + * vkms_config_plane_remove_format - Remove a specific format from a plane
>> + * @plane_cfg: Plane to remove the format to
>> + * @drm_format: Format to remove
>> + */
>> +void vkms_config_plane_remove_format(struct vkms_config_plane *plane_cfg, u32 drm_format);
>> +
>> +/**
>> + * vkms_config_plane_remove_all_formats - Remove all formast from a plane
> formats
>
> Luca
>
> --
> Luca Ceresoli, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com