Skip to contentSkip to conversation

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

PATCH In review Emil Velikov 3 participants 8 messages May 30, 2020 – Jun 15, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

v2: remove redundant assignment (Sam)

Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc VMware Graphics <[email protected]>
Cc Roland Scheidegger <[email protected]>
Cc Sam Ravnborg <[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          | 32 +++++++----------------------
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c |  8 +++-----
 include/drm/drm_drv.h               |  4 ++--
 3 files changed, 12 insertions(+), 32 deletions(-)
drivers/gpu/drm/drm_auth.c +7 -25
index 74ce0c29c960..4c723e3a689c 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,7 @@ int drm_setmaster_ioctl(struct drm_device *dev, void *data,
 		goto out_unlock;
 	}
 
-	ret = drm_set_master(dev, file_priv, false);
+	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 v2 2/2 drm/auth: make drm_{set,drop]master_ioctl symmetrical

Currently the ret handling is all over the place - with two redundant assignments and another one addressed earlier.

Use the exact same flow in both functions.

v2: straighten the code flow, instead of just removing the assignments

Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Colin Ian King <[email protected]>

---
Colin, pretty sure that this should address couple of Coverity warnings. Yet I didn't check their web UI thingy.

---
 drivers/gpu/drm/drm_auth.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/gpu/drm/drm_auth.c +7 -5
index 4c723e3a689c..f2d46b7ac6f9 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);
 
@@ -272,12 +272,15 @@ int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
 	if (ret)
 		goto out_unlock;
 
-	ret = -EINVAL;
-	if (!drm_is_current_master(file_priv))
+	if (!drm_is_current_master(file_priv)) {
+		ret = -EINVAL;
 		goto out_unlock;
+	}
 
-	if (!dev->master)
+	if (!dev->master) {
+		ret = -EINVAL;
 		goto out_unlock;
+	}
 
 	if (file_priv->master->lessor != NULL) {
 		DRM_DEBUG_LEASE("Attempt to drop lessee %d as master\n", file_priv->master->lessee_id);
@@ -285,7 +288,6 @@ int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
 		goto out_unlock;
 	}
 
-	ret = 0;
 	drm_drop_master(dev, file_priv);
 out_unlock:
 	mutex_unlock(&dev->master_mutex);
Signature · 6 lines
2.25.1

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

Re: [PATCH v2 2/2] drm/auth: make drm_{set,drop]master_ioctl symmetrical

Hi Emil.

Quoted 6 lines · Emil Velikov

Currently the ret handling is all over the place - with two redundant assignments and another one addressed earlier.

Use the exact same flow in both functions.

v2: straighten the code flow, instead of just removing the assignments

Now even I should be able to follow the flow - thanks :-)

Quoted 6 lines
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Colin Ian King <[email protected]>
Quoted 49 lines

---
Colin, pretty sure that this should address couple of Coverity warnings. Yet I didn't check their web UI thingy.

---
 drivers/gpu/drm/drm_auth.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/gpu/drm/drm_auth.c +7 -5
index 4c723e3a689c..f2d46b7ac6f9 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);
 
@@ -272,12 +272,15 @@ int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
 	if (ret)
 		goto out_unlock;
 
-	ret = -EINVAL;
-	if (!drm_is_current_master(file_priv))
+	if (!drm_is_current_master(file_priv)) {
+		ret = -EINVAL;
 		goto out_unlock;
+	}
 
-	if (!dev->master)
+	if (!dev->master) {
+		ret = -EINVAL;
 		goto out_unlock;
+	}
 
 	if (file_priv->master->lessor != NULL) {
 		DRM_DEBUG_LEASE("Attempt to drop lessee %d as master\n", file_priv->master->lessee_id);
@@ -285,7 +288,6 @@ int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
 		goto out_unlock;
 	}
 
-	ret = 0;
 	drm_drop_master(dev, file_priv);
 out_unlock:
 	mutex_unlock(&dev->master_mutex);
Signature · 1 line
2.25.1

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

#3 lore raw

Re: [PATCH v2 2/2] drm/auth: make drm_{set, drop]master_ioctl symmetrical

Quoted 11 lines · Sam Ravnborg

Hi Emil.

Quoted 6 lines · Emil Velikov

Currently the ret handling is all over the place - with two redundant assignments and another one addressed earlier.

Use the exact same flow in both functions.

v2: straighten the code flow, instead of just removing the assignments

Now even I should be able to follow the flow - thanks :-)

Fwiw reading at the code the first couple of times, did confuse the hell out of me.
So "there is nothing wrong with your television set" :-P

Quoted 7 lines
Quoted 6 lines
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Colin Ian King <[email protected]>

Thanks. If you're up for a few more neat patches - check these out [1].

-Emil

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

#4 lore raw

Re: [PATCH v2 2/2] drm/auth: make drm_{set,drop]master_ioctl symmetrical

Quoted 22 lines · Emil Velikov
Quoted 11 lines · Sam Ravnborg

Hi Emil.

Quoted 6 lines · Emil Velikov

Currently the ret handling is all over the place - with two redundant assignments and another one addressed earlier.

Use the exact same flow in both functions.

v2: straighten the code flow, instead of just removing the assignments

Now even I should be able to follow the flow - thanks :-)

Fwiw reading at the code the first couple of times, did confuse the hell out of me.
So "there is nothing wrong with your television set" :-P

Quoted 6 lines
Quoted 6 lines
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Colin Ian King <[email protected]>
Quoted 7 lines
Quoted 1 line

Thanks. If you're up for a few more neat patches - check these out [1].

-Emil

[1] https://patchwork.freedesktop.org/series/76967/

On my backlog. They require, I think, a bit more time. backlog atm is way too big - but thats a common issue for everyone.

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

Reviewed-by on v2 1/2
#5 lore raw
In reply to Emil Velikov

Looks like a nice cleanup to me. (No idea if at some point there actually was a reason for a return value...)

Am 30.05.20 um 14:46 schrieb Emil Velikov:

Quoted 126 lines

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.

v2: remove redundant assignment (Sam)

Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc VMware Graphics <[email protected]>
Cc Roland Scheidegger <[email protected]>
Cc Sam Ravnborg <[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          | 32 +++++++----------------------
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c |  8 +++-----
 include/drm/drm_drv.h               |  4 ++--
 3 files changed, 12 insertions(+), 32 deletions(-)
drivers/gpu/drm/drm_auth.c +7 -25
index 74ce0c29c960..4c723e3a689c 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,7 @@ int drm_setmaster_ioctl(struct drm_device *dev, void *data,
 		goto out_unlock;
 	}
 
-	ret = drm_set_master(dev, file_priv, false);
+	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 +0 -0
index bb924cddc09c..835c38a76ef6 100644

include/drm/drm_drv.h struct drm_driver { · line 318

Quoted 10 lines
include/drm/drm_drv.h +2 -2
@@ -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:
 	 *

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

#6 lore raw
Quoted 4 lines · Roland Scheidegger

Looks like a nice cleanup to me. (No idea if at some point there actually was a reason for a return value...)

It was required up-to quite recently actually:

commit 9c84aeba67cce6514374f134c9ce2c5f35ac3831
Author: Thomas Hellstrom <[email protected]>
AuthorDate: Tue May 28 08:08:55 2019 +0200
Commit: Thomas Hellstrom <[email protected]>
CommitDate: Thu Aug 15 08:39:27 2019 +0200

drm/vmwgfx: Kill unneeded legacy security features

Quoted 2 lines

Thank you. Will push to drm-misc in a moment.

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

#7 lore raw
Quoted 14 lines · Emil Velikov
Quoted 4 lines · Roland Scheidegger

Looks like a nice cleanup to me. (No idea if at some point there actually was a reason for a return value...)

It was required up-to quite recently actually:

commit 9c84aeba67cce6514374f134c9ce2c5f35ac3831
Author: Thomas Hellstrom <[email protected]>
AuthorDate: Tue May 28 08:08:55 2019 +0200
Commit: Thomas Hellstrom <[email protected]>
CommitDate: Thu Aug 15 08:39:27 2019 +0200

Quoted 6 lines

drm/vmwgfx: Kill unneeded legacy security features

Quoted 2 lines

Thank you. Will push to drm-misc in a moment.

... and finally pushed to drm-misc/next.

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