On Sun, 16 Mar 2025 21:51:33 +0000
Adrián Larumbe <adrian.laru...@collabora.com> wrote:

> Allow UM to label a BO for which it possesses a DRM handle.
> 
> Signed-off-by: Adrián Larumbe <adrian.laru...@collabora.com>
> ---
>  drivers/gpu/drm/panthor/panthor_drv.c | 31 +++++++++++++++++++++++++++
>  include/uapi/drm/panthor_drm.h        | 14 ++++++++++++
>  2 files changed, 45 insertions(+)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_drv.c 
> b/drivers/gpu/drm/panthor/panthor_drv.c
> index 310bb44abe1a..f41b8946258f 100644
> --- a/drivers/gpu/drm/panthor/panthor_drv.c
> +++ b/drivers/gpu/drm/panthor/panthor_drv.c
> @@ -1330,6 +1330,35 @@ static int panthor_ioctl_vm_get_state(struct 
> drm_device *ddev, void *data,
>       return 0;
>  }
>  
> +static int panthor_ioctl_label_bo(struct drm_device *ddev, void *data,
> +                               struct drm_file *file)
> +{
> +     struct drm_panthor_label_bo *args = data;
> +     struct drm_gem_object *obj;
> +     const char *label;
> +     int ret = 0;
> +
> +     obj = drm_gem_object_lookup(file, args->handle);
> +     if (!obj)
> +             return -ENOENT;
> +
> +     if (args->len && args->label) {

We probably want to have a limit on the label length (PAGE_SIZE or
less?). I would also return -EINVAL if the length is not zero and the
label is NULL instead of silently setting the label to NULL.

> +             label = strndup_user(u64_to_user_ptr(args->label), args->len + 
> 1);
> +             if (IS_ERR(label)) {
> +                     ret = PTR_ERR(label);
> +                     goto err_label;
> +             }
> +     } else
> +             label = NULL;

        } else {
                label = NULL;
        }
> +
> +     panthor_gem_label_bo(obj, label);
> +
> +err_label:
> +     drm_gem_object_put(obj);
> +
> +     return ret;
> +}
> +

Reply via email to