All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: dri-devel@lists.freedesktop.org
Subject: [PATCH] drm: Add deprecation warnings to the old midlayer callbacks
Date: Thu,  1 Jun 2017 14:00:26 +0100	[thread overview]
Message-ID: <20170601130026.15964-1-chris@chris-wilson.co.uk> (raw)

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@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

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

             reply	other threads:[~2017-06-01 13:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-01 13:00 Chris Wilson [this message]
2017-06-01 18:25 ` [PATCH] drm: Add deprecation warnings to the old midlayer callbacks Emil Velikov
2017-06-20  9:00   ` Daniel Vetter
2017-06-01 23:04 ` kbuild test robot
2017-06-01 23:06 ` kbuild test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170601130026.15964-1-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --cc=dri-devel@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.