[PATCH] drm: Add deprecation warnings to the old midlayer callbacks

Chris Wilson chris at chris-wilson.co.uk
Thu Jun 1 13:00:26 UTC 2017


Daniel started a crusade a few years back to move control over the
initialisation and teardown into the driver rather than drm core, for
greater control and far fewer surprises. Help in that fight by adding
compiler warnings to the stale functions.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---

This is not as useful as I hoped. I wanted for gcc to emit a
compile-time warning when a deprecated field was assigned, however it
only emits when it is used. So we end up with a lot of noise in drm_core
and none in the drivers. However, the runtime warning is probably useful
and a motivator for change?

Should be made WARN_ONCE though

---
 drivers/gpu/drm/Kconfig      | 11 +++++++++++
 drivers/gpu/drm/drm_drv.c    |  4 ++--
 drivers/gpu/drm/drm_gem.c    |  2 +-
 include/drm/drm_deprecated.h | 35 +++++++++++++++++++++++++++++++++++
 include/drm/drm_drv.h        |  4 ++++
 5 files changed, 53 insertions(+), 3 deletions(-)
 create mode 100644 include/drm/drm_deprecated.h

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 83cb2a88c204..530d56a2fa01 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -34,6 +34,17 @@ config DRM_DP_AUX_CHARDEV
 	  read and write values to arbitrary DPCD registers on the DP aux
 	  channel.
 
+config DRM_DEBUG_DEPRECATED
+	bool "Insert extra warnings if deprecated code is used"
+	default n
+	depends on DRM
+	help
+	  Enables extra warnings if deprecated code and callbacks are used.
+
+	  Recommended for driver developers only.
+
+	  If in doubt, say "N".
+
 config DRM_DEBUG_MM
 	bool "Insert extra checks and debug info into the DRM range managers"
 	default n
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index b5c6bb46a425..63f968ec1f05 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -778,7 +778,7 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
 
 	dev->registered = true;
 
-	if (dev->driver->load) {
+	if (DRM_DEPRECATED_WARN(dev->driver->load)) {
 		ret = dev->driver->load(dev, flags);
 		if (ret)
 			goto err_minors;
@@ -830,7 +830,7 @@ void drm_dev_unregister(struct drm_device *dev)
 	if (drm_core_check_feature(dev, DRIVER_MODESET))
 		drm_modeset_unregister_all(dev);
 
-	if (dev->driver->unload)
+	if (DRM_DEPRECATED_WARN(dev->driver->unload))
 		dev->driver->unload(dev);
 
 	if (dev->agp)
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 8dc11064253d..c0998a9b1ba0 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -800,7 +800,7 @@ drm_gem_object_free(struct kref *kref)
 
 	if (dev->driver->gem_free_object_unlocked) {
 		dev->driver->gem_free_object_unlocked(obj);
-	} else if (dev->driver->gem_free_object) {
+	} else if (DRM_DEPRECATED_WARN(dev->driver->gem_free_object)) {
 		WARN_ON(!mutex_is_locked(&dev->struct_mutex));
 
 		dev->driver->gem_free_object(obj);
diff --git a/include/drm/drm_deprecated.h b/include/drm/drm_deprecated.h
new file mode 100644
index 000000000000..e0debe496f28
--- /dev/null
+++ b/include/drm/drm_deprecated.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2017 Intel Corp.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _DRM_DEPRECATED_H_
+#define _DRM_DEPRECATED_H_
+
+#ifdef CONFIG_DRM_DEBUG_DEPRECATED
+#define drm_deprecated __deprecated
+#define DRM_DEPRECATED_WARN(cond) WARN(cond, "Use of %s is deprecated\n", #cond)
+#else
+#define drm_deprecated
+#define DRM_DEPRECATED_WARN(cond) (cond)
+#endif
+
+#endif
diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
index 18f3181674e8..a2cb895cdfe3 100644
--- a/include/drm/drm_drv.h
+++ b/include/drm/drm_drv.h
@@ -29,6 +29,7 @@
 
 #include <linux/list.h>
 #include <linux/irqreturn.h>
+#include <drm/drm_deprecated.h>
 
 struct drm_device;
 struct drm_file;
@@ -81,6 +82,7 @@ struct drm_driver {
 	 *
 	 * Zero on success, non-zero value on failure.
 	 */
+	drm_deprecated
 	int (*load) (struct drm_device *, unsigned long flags);
 
 	/**
@@ -160,6 +162,7 @@ struct drm_driver {
 	 * the device.
 	 *
 	 */
+	drm_deprecated
 	void (*unload) (struct drm_device *);
 
 	/**
@@ -399,6 +402,7 @@ struct drm_driver {
 	 * This is deprecated and should not be used by new drivers. Use
 	 * @gem_free_object_unlocked instead.
 	 */
+	drm_deprecated
 	void (*gem_free_object) (struct drm_gem_object *obj);
 
 	/**
-- 
2.11.0



More information about the dri-devel mailing list