Skip to contentSkip to conversation

drm: vmwgfx: remove drm_driver::master_set() return typ

PATCH Superseded Emil Velikov 2 participants 5 messages May 29, 2020 – May 30, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm: vmwgfx: remove drm_driver::master_set() return typ

The function always returns zero (success). Ideally we'll remove it all together - although that's requires a little more work.

For now, we can drop the return type and simplify the drm core code surrounding it.

Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc VMware Graphics <[email protected]>
Cc Roland Scheidegger <[email protected]>

---
VMWare team, I'm planning to push this via drm-misc. Review, ack and comments are appreciated.

---
 drivers/gpu/drm/drm_auth.c          | 33 +++++++----------------------
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c |  8 +++----
 include/drm/drm_drv.h               |  4 ++--
 3 files changed, 13 insertions(+), 32 deletions(-)
drivers/gpu/drm/drm_auth.c +8 -25
index 800ac39f3213..db701a9e9393 100644
@@ -122,27 +122,19 @@ struct drm_master *drm_master_create(struct drm_device *dev)
 	return master;
 }
 
-static int drm_set_master(struct drm_device *dev, struct drm_file *fpriv,
-			  bool new_master)
+static void drm_set_master(struct drm_device *dev, struct drm_file *fpriv,
+			   bool new_master)
 {
-	int ret = 0;
-
 	dev->master = drm_master_get(fpriv->master);
-	if (dev->driver->master_set) {
-		ret = dev->driver->master_set(dev, fpriv, new_master);
-		if (unlikely(ret != 0)) {
-			drm_master_put(&dev->master);
-		}
-	}
+	if (dev->driver->master_set)
+		dev->driver->master_set(dev, fpriv, new_master);
 
-	fpriv->was_master = (ret == 0);
-	return ret;
+	fpriv->was_master = true;
 }
 
 static int drm_new_set_master(struct drm_device *dev, struct drm_file *fpriv)
 {
 	struct drm_master *old_master;
-	int ret;
 
 	lockdep_assert_held_once(&dev->master_mutex);
 
@@ -157,22 +149,12 @@ static int drm_new_set_master(struct drm_device *dev, struct drm_file *fpriv)
 	fpriv->is_master = 1;
 	fpriv->authenticated = 1;
 
-	ret = drm_set_master(dev, fpriv, true);
-	if (ret)
-		goto out_err;
+	drm_set_master(dev, fpriv, true);
 
 	if (old_master)
 		drm_master_put(&old_master);
 
 	return 0;
-
-out_err:
-	/* drop references and restore old master on failure */
-	drm_master_put(&fpriv->master);
-	fpriv->master = old_master;
-	fpriv->is_master = 0;
-
-	return ret;
 }
 
 /*
@@ -265,7 +247,8 @@ int drm_setmaster_ioctl(struct drm_device *dev, void *data,
 		goto out_unlock;
 	}
 
-	ret = drm_set_master(dev, file_priv, false);
+	ret = 0;
+	drm_set_master(dev, file_priv, false);
 out_unlock:
 	mutex_unlock(&dev->master_mutex);
 	return ret;
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +3 -5
index c2247a893ed4..470428387878 100644
@@ -1129,9 +1129,9 @@ static long vmw_compat_ioctl(struct file *filp, unsigned int cmd,
 }
 #endif
 
-static int vmw_master_set(struct drm_device *dev,
-			  struct drm_file *file_priv,
-			  bool from_open)
+static void vmw_master_set(struct drm_device *dev,
+			   struct drm_file *file_priv,
+			   bool from_open)
 {
 	/*
 	 * Inform a new master that the layout may have changed while
@@ -1139,8 +1139,6 @@ static int vmw_master_set(struct drm_device *dev,
 	 */
 	if (!from_open)
 		drm_sysfs_hotplug_event(dev);
-
-	return 0;
 }
 
 static void vmw_master_drop(struct drm_device *dev,
include/drm/drm_drv.h +2 -2
index bb924cddc09c..835c38a76ef6 100644
@@ -311,8 +311,8 @@ struct drm_driver {
 	 *
 	 * Called whenever the minor master is set. Only used by vmwgfx.
 	 */
-	int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
-			  bool from_open);
+	void (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
+			   bool from_open);
 	/**
 	 * @master_drop:
 	 *
Signature · 6 lines
2.25.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 2/2 drm/auth: drop unnessesary variable assignments

The variables are already the exact same value or will be overwritten shortly afterwords. In either case there's no functional difference.

Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_auth.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/drm_auth.c +1 -2
index db701a9e9393..5ae5623f2482 100644
@@ -215,7 +215,7 @@ drm_master_check_perm(struct drm_device *dev, struct drm_file *file_priv)
 int drm_setmaster_ioctl(struct drm_device *dev, void *data,
 			struct drm_file *file_priv)
 {
-	int ret = 0;
+	int ret;
 
 	mutex_lock(&dev->master_mutex);
 
@@ -282,7 +282,6 @@ int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
 
 	if (file_priv->master->lessor != NULL) {
 		DRM_DEBUG_LEASE("Attempt to drop lessee %d as master\n", file_priv->master->lessee_id);
-		ret = -EINVAL;
 		goto out_unlock;
 	}
 
Signature · 6 lines
2.25.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

Re: [PATCH 2/2] drm/auth: drop unnessesary variable assignments

Hi Emil.

Quoted 2 lines · Emil Velikov

The variables are already the exact same value or will be overwritten shortly afterwords. In either case there's no functional difference.

s/afterwords/afterwards/

Quoted 13 lines
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_auth.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/drm_auth.c +0 -0
index db701a9e9393..5ae5623f2482 100644

drivers/gpu/drm/drm_auth.c drm_master_check_perm(struct drm_device *dev, struct drm_file *file_priv) · line 218

Quoted 5 lines
drivers/gpu/drm/drm_auth.c +1 -1
@@ -215,7 +215,7 @@ drm_master_check_perm(struct drm_device *dev, struct drm_file *file_priv)
 int drm_setmaster_ioctl(struct drm_device *dev, void *data,
 			struct drm_file *file_priv)
 {
-	int ret = 0;
+	int ret;

This was the redundant asignment I mentioned in first mail - good.

drivers/gpu/drm/drm_auth.c int drm_dropmaster_ioctl(struct drm_device *dev, void *data, · line 285

Quoted 8 lines
drivers/gpu/drm/drm_auth.c +0 -1
 	mutex_lock(&dev->master_mutex);
 
@@ -282,7 +282,6 @@ int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
 
 	if (file_priv->master->lessor != NULL) {
 		DRM_DEBUG_LEASE("Attempt to drop lessee %d as master\n", file_priv->master->lessee_id);
-		ret = -EINVAL;

This is wrong. ret is 0 when this code is reached, so we loose the error value if this code-path is triggered.
Or I miss something??

Sam

Quoted 10 lines
drivers/gpu/drm/drm_auth.c +0 -0
 		goto out_unlock;
 	}
 
Signature · 6 lines
2.25.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

Re: [PATCH 2/2] drm/auth: drop unnessesary variable assignments

Quoted 31 lines · Sam Ravnborg

Hi Emil.

Quoted 2 lines · Emil Velikov

The variables are already the exact same value or will be overwritten shortly afterwords. In either case there's no functional difference.

s/afterwords/afterwards/

Quoted 13 lines
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_auth.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/drm_auth.c +0 -0
index db701a9e9393..5ae5623f2482 100644

drivers/gpu/drm/drm_auth.c drm_master_check_perm(struct drm_device *dev, struct drm_file *file_priv) · line 218

Quoted 5 lines
drivers/gpu/drm/drm_auth.c +1 -1
@@ -215,7 +215,7 @@ drm_master_check_perm(struct drm_device *dev, struct drm_file *file_priv)
 int drm_setmaster_ioctl(struct drm_device *dev, void *data,
                      struct drm_file *file_priv)
 {
-     int ret = 0;
+     int ret;

This was the redundant asignment I mentioned in first mail - good.

Quoted 3 lines
drivers/gpu/drm/drm_auth.c +0 -0
      mutex_lock(&dev->master_mutex);
 
Quoted 9 lines

drivers/gpu/drm/drm_auth.c int drm_dropmaster_ioctl(struct drm_device *dev, void *data, · line 285

Quoted 5 lines
drivers/gpu/drm/drm_auth.c +0 -1
@@ -282,7 +282,6 @@ int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
 
      if (file_priv->master->lessor != NULL) {
              DRM_DEBUG_LEASE("Attempt to drop lessee %d as master\n", file_priv->master->lessee_id);
-             ret = -EINVAL;

This is wrong. ret is 0 when this code is reached, so we loose the error value if this code-path is triggered.
Or I miss something??

A few lines above [1] - there's unconditional ret = -EINVAL. Although the set<>drop paths are pretty asymmetric and misleading. Let me respin the series.

-Emil

[1] https://cgit.freedesktop.org/drm/drm-misc/tree/drivers/gpu/drm/drm_auth.c?id=6015002ece38dac85a373f041e0302781de7474b#n293
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reviewed-by on v1 1/2
#4 lore raw
In reply to Emil Velikov

Hi Emil.

Quoted 11 lines · Emil Velikov

The function always returns zero (success). Ideally we'll remove it all together - although that's requires a little more work.

For now, we can drop the return type and simplify the drm core code surrounding it.

Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc VMware Graphics <[email protected]>
Cc Roland Scheidegger <[email protected]>

Nice cleanup.

Quoted 71 lines

---
VMWare team, I'm planning to push this via drm-misc. Review, ack and comments are appreciated.

---
 drivers/gpu/drm/drm_auth.c          | 33 +++++++----------------------
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c |  8 +++----
 include/drm/drm_drv.h               |  4 ++--
 3 files changed, 13 insertions(+), 32 deletions(-)
drivers/gpu/drm/drm_auth.c +6 -24
index 800ac39f3213..db701a9e9393 100644
@@ -122,27 +122,19 @@ struct drm_master *drm_master_create(struct drm_device *dev)
 	return master;
 }
 
-static int drm_set_master(struct drm_device *dev, struct drm_file *fpriv,
-			  bool new_master)
+static void drm_set_master(struct drm_device *dev, struct drm_file *fpriv,
+			   bool new_master)
 {
-	int ret = 0;
-
 	dev->master = drm_master_get(fpriv->master);
-	if (dev->driver->master_set) {
-		ret = dev->driver->master_set(dev, fpriv, new_master);
-		if (unlikely(ret != 0)) {
-			drm_master_put(&dev->master);
-		}
-	}
+	if (dev->driver->master_set)
+		dev->driver->master_set(dev, fpriv, new_master);
 
-	fpriv->was_master = (ret == 0);
-	return ret;
+	fpriv->was_master = true;
 }
 
 static int drm_new_set_master(struct drm_device *dev, struct drm_file *fpriv)
 {
 	struct drm_master *old_master;
-	int ret;
 
 	lockdep_assert_held_once(&dev->master_mutex);
 
@@ -157,22 +149,12 @@ static int drm_new_set_master(struct drm_device *dev, struct drm_file *fpriv)
 	fpriv->is_master = 1;
 	fpriv->authenticated = 1;
 
-	ret = drm_set_master(dev, fpriv, true);
-	if (ret)
-		goto out_err;
+	drm_set_master(dev, fpriv, true);
 
 	if (old_master)
 		drm_master_put(&old_master);
 
 	return 0;
-
-out_err:
-	/* drop references and restore old master on failure */
-	drm_master_put(&fpriv->master);
-	fpriv->master = old_master;
-	fpriv->is_master = 0;
-
-	return ret;
 }
 
 /*

drivers/gpu/drm/drm_auth.c int drm_setmaster_ioctl(struct drm_device *dev, void *data, · line 250

Quoted 5 lines
drivers/gpu/drm/drm_auth.c +1 -1
@@ -265,7 +247,8 @@ int drm_setmaster_ioctl(struct drm_device *dev, void *data,
 		goto out_unlock;
 	}
 
-	ret = drm_set_master(dev, file_priv, false);
+	ret = 0;

This assignment is redundant.
ret is assigned a value here:

	ret = drm_master_check_perm(dev, file_priv);
	if (ret)
		goto out_unlock;

And all other places it is assigned and then goto out_unlock The assignment when declared is btw. also redundant but that I think is outside the scope of this patch.

If you remove the redundant assignment to ret then the patch is:

Quoted 52 lines
drivers/gpu/drm/drm_auth.c +1 -0
+	drm_set_master(dev, file_priv, false);
 out_unlock:
 	mutex_unlock(&dev->master_mutex);
 	return ret;
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +3 -5
index c2247a893ed4..470428387878 100644
@@ -1129,9 +1129,9 @@ static long vmw_compat_ioctl(struct file *filp, unsigned int cmd,
 }
 #endif
 
-static int vmw_master_set(struct drm_device *dev,
-			  struct drm_file *file_priv,
-			  bool from_open)
+static void vmw_master_set(struct drm_device *dev,
+			   struct drm_file *file_priv,
+			   bool from_open)
 {
 	/*
 	 * Inform a new master that the layout may have changed while
@@ -1139,8 +1139,6 @@ static int vmw_master_set(struct drm_device *dev,
 	 */
 	if (!from_open)
 		drm_sysfs_hotplug_event(dev);
-
-	return 0;
 }
 
 static void vmw_master_drop(struct drm_device *dev,
include/drm/drm_drv.h +2 -2
index bb924cddc09c..835c38a76ef6 100644
@@ -311,8 +311,8 @@ struct drm_driver {
 	 *
 	 * Called whenever the minor master is set. Only used by vmwgfx.
 	 */
-	int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
-			  bool from_open);
+	void (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
+			   bool from_open);
 	/**
 	 * @master_drop:
 	 *
Signature · 6 lines
2.25.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel