[PATCH 4/4] drm/connector: Make init functions panic consitently and explicitly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



All of the current encoder init / allocation functions behave slightly
differently when it comes to argument sanitizing:

 - drm_connector_init() and drm_connector_init_with_ddc() implicitly
   panic if the drm_device pointer, or the drm_connector pointer are
   NULL, and will call WARN_ON and error out if the
   drm_connector_funcs pointer is NULL or if there's no destroy
   implementation.

 - drmm_connector_init() implicitly panics if the drm_device pointer,
   the drm_connector_funcs pointer, or the drm_connector pointer are
   NULL, and will call WARN_ON and error out if there's a destroy
   implementation.

The current consensus is that the drm_device pointer, the drm_connector
pointer, and the drm_connector_funcs pointer should be considered
pre-requisite and the function should panic if we encounter such a
situation, and that returning an error in such a situation is not
welcome.

Let's make all functions consider those three pointers to be always set
and explicitly panic if they aren't. And let's document that behaviour
too.

Link: https://lore.kernel.org/dri-devel/20231128-kms-hdmi-connector-state-v4-5-c7602158306e@xxxxxxxxxx/
Signed-off-by: Maxime Ripard <mripard@xxxxxxxxxx>
---
 drivers/gpu/drm/drm_connector.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
index b0516505f7ae..e7a463db11ea 100644
--- a/drivers/gpu/drm/drm_connector.c
+++ b/drivers/gpu/drm/drm_connector.c
@@ -351,14 +351,19 @@ static int __drm_connector_init(struct drm_device *dev,
  *
  * Returns:
  * Zero on success, error code on failure.
+ *
+ * Panics:
+ * If @dev, @connector, or @funcs are NULL.
  */
 int drm_connector_init(struct drm_device *dev,
 		       struct drm_connector *connector,
 		       const struct drm_connector_funcs *funcs,
 		       int connector_type)
 {
-	if (drm_WARN_ON(dev, !(funcs && funcs->destroy)))
-		return -EINVAL;
+	BUG_ON(!dev);
+	BUG_ON(!connector);
+	BUG_ON(!funcs);
+	drm_WARN_ON(dev, !funcs->destroy);
 
 	return __drm_connector_init(dev, connector, funcs, connector_type, NULL);
 }
@@ -387,6 +392,9 @@ EXPORT_SYMBOL(drm_connector_init);
  *
  * Returns:
  * Zero on success, error code on failure.
+ *
+ * Panics:
+ * If @dev, @connector, or @funcs are NULL.
  */
 int drm_connector_init_with_ddc(struct drm_device *dev,
 				struct drm_connector *connector,
@@ -394,8 +402,10 @@ int drm_connector_init_with_ddc(struct drm_device *dev,
 				int connector_type,
 				struct i2c_adapter *ddc)
 {
-	if (drm_WARN_ON(dev, !(funcs && funcs->destroy)))
-		return -EINVAL;
+	BUG_ON(!dev);
+	BUG_ON(!connector);
+	BUG_ON(!funcs);
+	drm_WARN_ON(dev, !funcs->destroy);
 
 	return __drm_connector_init(dev, connector, funcs, connector_type, ddc);
 }
@@ -427,6 +437,9 @@ static void drm_connector_cleanup_action(struct drm_device *dev,
  *
  * Returns:
  * Zero on success, error code on failure.
+ *
+ * Panics:
+ * If @dev, @connector, or @funcs are NULL.
  */
 int drmm_connector_init(struct drm_device *dev,
 			struct drm_connector *connector,
@@ -436,8 +449,10 @@ int drmm_connector_init(struct drm_device *dev,
 {
 	int ret;
 
-	if (drm_WARN_ON(dev, funcs && funcs->destroy))
-		return -EINVAL;
+	BUG_ON(!dev);
+	BUG_ON(!connector);
+	BUG_ON(!funcs);
+	drm_WARN_ON(dev, funcs->destroy);
 
 	ret = __drm_connector_init(dev, connector, funcs, connector_type, ddc);
 	if (ret)
-- 
2.43.0




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux