[v2,2/2] drm/auth: make drm_{set,drop]master_ioctl symmetrical
diff mbox series

Message ID 20200530124640.4176323-2-emil.l.velikov@gmail.com
State New
Headers show
Series
  • [v2,1/2] drm: vmwgfx: remove drm_driver::master_set() return typ
Related show

Commit Message

Emil Velikov May 30, 2020, 12:46 p.m. UTC
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 <airlied@linux.ie>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
---
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(-)

Comments

Sam Ravnborg May 30, 2020, 1:18 p.m. UTC | #1
Hi Emil.
On Sat, May 30, 2020 at 01:46:40PM +0100, Emil Velikov wrote:
> 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 :-)

> 
> Cc: David Airlie <airlied@linux.ie>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: Sam Ravnborg <sam@ravnborg.org>
> Cc: Colin Ian King <colin.king@canonical.com>
> Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
> ---
> 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(-)
> 
> diff --git a/drivers/gpu/drm/drm_auth.c b/drivers/gpu/drm/drm_auth.c
> index 4c723e3a689c..f2d46b7ac6f9 100644
> --- a/drivers/gpu/drm/drm_auth.c
> +++ b/drivers/gpu/drm/drm_auth.c
> @@ -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);
> -- 
> 2.25.1
Emil Velikov May 30, 2020, 1:34 p.m. UTC | #2
On Sat, 30 May 2020 at 14:18, Sam Ravnborg <sam@ravnborg.org> wrote:
>
> Hi Emil.
> On Sat, May 30, 2020 at 01:46:40PM +0100, Emil Velikov wrote:
> > 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

> >
> > Cc: David Airlie <airlied@linux.ie>
> > Cc: Daniel Vetter <daniel@ffwll.ch>
> > Cc: Sam Ravnborg <sam@ravnborg.org>
> > Cc: Colin Ian King <colin.king@canonical.com>
> > Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
> Reviewed-by: Sam Ravnborg <sam@ravnborg.org>

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

-Emil

[1] https://patchwork.freedesktop.org/series/76967/
Sam Ravnborg May 30, 2020, 1:43 p.m. UTC | #3
On Sat, May 30, 2020 at 02:34:10PM +0100, Emil Velikov wrote:
> On Sat, 30 May 2020 at 14:18, Sam Ravnborg <sam@ravnborg.org> wrote:
> >
> > Hi Emil.
> > On Sat, May 30, 2020 at 01:46:40PM +0100, Emil Velikov wrote:
> > > 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
> 
> > >
> > > Cc: David Airlie <airlied@linux.ie>
> > > Cc: Daniel Vetter <daniel@ffwll.ch>
> > > Cc: Sam Ravnborg <sam@ravnborg.org>
> > > Cc: Colin Ian King <colin.king@canonical.com>
> > > Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
> > Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
> 
> 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

Patch
diff mbox series

diff --git a/drivers/gpu/drm/drm_auth.c b/drivers/gpu/drm/drm_auth.c
index 4c723e3a689c..f2d46b7ac6f9 100644
--- a/drivers/gpu/drm/drm_auth.c
+++ b/drivers/gpu/drm/drm_auth.c
@@ -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);