[PATCH] drm: Check in drm_dev_register() that required DRM driver fields were set
From: Javier Martinez Canillas
Date: Mon Jul 04 2022 - 08:53:48 EST
Signed-off-by: Javier Martinez Canillas <javierm@xxxxxxxxxx>
---
drivers/gpu/drm/drm_drv.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 8214a0b1ab7f..d4eebaf37e23 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -842,6 +842,12 @@ static void remove_compat_control_link(struct drm_device *dev)
kfree(name);
}
+static inline bool check_drm_driver_fields(const struct drm_driver *driver)
+{
+ /* required since are copied to user-space by DRM_IOCTL_VERSION */
+ return driver->name && driver->date && driver->desc;
+}
+
/**
* drm_dev_register - Register DRM device
* @dev: Device to register
@@ -865,7 +871,11 @@ static void remove_compat_control_link(struct drm_device *dev)
int drm_dev_register(struct drm_device *dev, unsigned long flags)
{
const struct drm_driver *driver = dev->driver;
- int ret;
+ int ret = -EINVAL;
+
+ if (drm_WARN(dev, !check_drm_driver_fields(driver),
+ "Required DRM drivers fields not set.\n"))
+ goto out_err;
if (!driver->load)
drm_mode_config_validate(dev);
@@ -913,6 +923,7 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
out_unlock:
if (drm_dev_needs_global_mutex(dev))
mutex_unlock(&drm_global_mutex);
+out_err:
return ret;
}
EXPORT_SYMBOL(drm_dev_register);
--
2.36.1
--
Best regards,
Javier Martinez Canillas
Linux Engineering
Red Hat