On Tue, 17 Dec 2019 15:49:48 +0100
Andrzej Pietrasiewicz <andrze...@collabora.com> wrote:

> +/**
> + * drm_gem_fb_size_check() - Helper function for use in
> + *                        &drm_mode_config_funcs.fb_create implementations
> + * @dev: DRM device
> + * @mode_cmd: Metadata from the userspace framebuffer creation request
> + *
> + * This function can be used to verify buffer sizes for all planes.
> + * It is caller's responsibility to put the objects on failure.
> + *
> + * Returns:
> + * Zero on success or a negative error code on failure.
> + */
> +int drm_gem_fb_size_check(struct drm_device *dev,
> +                       const struct drm_mode_fb_cmd2 *mode_cmd,
> +                       struct drm_gem_object **objs)

Maybe we should rename that one drm_gem_fb_linear_size_check().

> +{
> +     const struct drm_format_info *info;
> +     int i;
> +
> +     info = drm_get_format_info(dev, mode_cmd);
> +     if (!info)
> +             return -EINVAL;
> +
> +     for (i = 0; i < info->num_planes; i++) {
> +             unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
> +             unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
> +             unsigned int min_size;
> +
> +             min_size = (height - 1) * mode_cmd->pitches[i]
> +                      + drm_format_info_min_pitch(info, i, width)
> +                      + mode_cmd->offsets[i];
> +
> +             if (objs[i]->size < min_size)
> +                     return -EINVAL;
> +     }
> +
> +     return 0;
> +
> +}
> +EXPORT_SYMBOL_GPL(drm_gem_fb_size_check);
> +
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reply via email to