Re: [PATCH 10/13] drm/vkms: Allow to configure multiple encoders

Louis Chauvet
2025-01-30T13:48:33Z

On 29/01/25 - 12:00, José Expósito wrote:
> Add a list of encoders to vkms_config and helper functions to add and
> remove as many encoders as wanted.
>
> For backwards compatibility, add one encoder to the default
> configuration.
>
> A future patch will allow to attach encoders and CRTCs, but for the
> moment there are no changes in the way the output is configured.
>
> Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
> Signed-off-by: José Expósito <jose.exposito89@gmail.com>

Co-developped-by: Louis Chauvet <louis.chauvet@bootlin.com>
Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
Signed-off-by: José Expósito <jose.exposito89@gmail.com>

[...]

> +static void vkms_config_test_valid_encoder_number(struct kunit *test)

Same as before, can you rename to vkms_config_test_invalid_encoder_number

> +{
> + struct vkms_config *config;
> + struct vkms_config_encoder *encoder_cfg;
> + int n;
> +
> + config = vkms_config_default_create(false, false, false);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, config);
> +
> + /* Invalid: No encoders */
> + encoder_cfg = list_first_entry(&config->encoders, typeof(*encoder_cfg), link);
> + vkms_config_destroy_encoder(config, encoder_cfg);
> + KUNIT_EXPECT_FALSE(test, vkms_config_is_valid(config));
> +
> + /* Invalid: Too many encoders */
> + for (n = 0; n <= 32; n++)
> + vkms_config_add_encoder(config);
> +
> + KUNIT_EXPECT_FALSE(test, vkms_config_is_valid(config));
> +
> + vkms_config_destroy(config);
> +}
> +

[...]

> +struct vkms_config_encoder **vkms_config_get_encoders(const struct vkms_config *config,
> + size_t *out_length)
> +{
> + struct vkms_config_encoder **array;
> + struct vkms_config_encoder *encoder_cfg;
> + size_t length;
> + int n = 0;
> +
> + length = list_count_nodes((struct list_head *)&config->encoders);
> + if (length == 0) {
> + *out_length = length;
> + return NULL;
> + }
> +
> + array = kmalloc_array(length, sizeof(*array), GFP_KERNEL);
> + if (!array)
> + return ERR_PTR(-ENOMEM);
> +
> + list_for_each_entry(encoder_cfg, &config->encoders, link) {
> + array[n] = encoder_cfg;
> + n++;
> + }
> +
> + *out_length = length;
> + return array;
> +}

Same as before, can we use an iterator?

> +struct vkms_config_encoder *vkms_config_add_encoder(struct vkms_config *config)
> +{
> + struct vkms_config_encoder *encoder_cfg;
> +
> + encoder_cfg = kzalloc(sizeof(*encoder_cfg), GFP_KERNEL);
> + if (!encoder_cfg)
> + return ERR_PTR(-ENOMEM);
> +
> + list_add_tail(&encoder_cfg->link, &config->encoders);
> +
> + return encoder_cfg;
> +}
> +
> +void vkms_config_destroy_encoder(struct vkms_config *config,
> + struct vkms_config_encoder *encoder_cfg)
> +{
> + list_del(&encoder_cfg->link);
> + kfree(encoder_cfg);
> +}

Same as before, can we change the add/destroy naming?