diff mbox

[3/4] drm: Reshuffle getfb error returns

Message ID 20180323134553.15993-3-daniels@collabora.com (mailing list archive)
State New, archived
Headers show

Commit Message

Daniel Stone March 23, 2018, 1:45 p.m. UTC
Make it a little more clear what's going on inside of getfb, and also
make it easier to add alternate paths to get a handle in future.

Signed-off-by: Daniel Stone <daniels@collabora.com>
---
 drivers/gpu/drm/drm_framebuffer.c | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)

Comments

Ville Syrjälä March 23, 2018, 2:43 p.m. UTC | #1
On Fri, Mar 23, 2018 at 01:45:51PM +0000, Daniel Stone wrote:
> Make it a little more clear what's going on inside of getfb, and also
> make it easier to add alternate paths to get a handle in future.
> 
> Signed-off-by: Daniel Stone <daniels@collabora.com>

Much better.
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

> ---
>  drivers/gpu/drm/drm_framebuffer.c | 33 +++++++++++++++++----------------
>  1 file changed, 17 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
> index ad67203de715..6d5ff541225a 100644
> --- a/drivers/gpu/drm/drm_framebuffer.c
> +++ b/drivers/gpu/drm/drm_framebuffer.c
> @@ -468,29 +468,30 @@ int drm_mode_getfb(struct drm_device *dev,
>  		goto out;
>  	}
>  
> +	if (!fb->funcs->create_handle) {
> +		ret = -ENODEV;
> +		goto out;
> +	}
> +
>  	r->height = fb->height;
>  	r->width = fb->width;
>  	r->depth = fb->format->depth;
>  	r->bpp = fb->format->cpp[0] * 8;
>  	r->pitch = fb->pitches[0];
> -	if (fb->funcs->create_handle) {
> -		if (drm_is_current_master(file_priv) || capable(CAP_SYS_ADMIN) ||
> -		    drm_is_control_client(file_priv)) {
> -			ret = fb->funcs->create_handle(fb, file_priv,
> -						       &r->handle);
> -		} else {
> -			/* GET_FB() is an unprivileged ioctl so we must not
> -			 * return a buffer-handle to non-master processes! For
> -			 * backwards-compatibility reasons, we cannot make
> -			 * GET_FB() privileged, so just return an invalid handle
> -			 * for non-masters. */
> -			r->handle = 0;
> -			ret = 0;
> -		}
> -	} else {
> -		ret = -ENODEV;
> +
> +	/* GET_FB() is an unprivileged ioctl so we must not return a
> +	 * buffer-handle to non-master processes! For
> +	 * backwards-compatibility reasons, we cannot make GET_FB() privileged,
> +	 * so just return an invalid handle for non-masters. */
> +	if (!drm_is_current_master(file_priv) && !capable(CAP_SYS_ADMIN) &&
> +	    !drm_is_control_client(file_priv)) {
> +		r->handle = 0;
> +		ret = 0;
> +		goto out;
>  	}
>  
> +	ret = fb->funcs->create_handle(fb, file_priv, &r->handle);
> +
>  out:
>  	drm_framebuffer_put(fb);
>  
> -- 
> 2.16.2
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
index ad67203de715..6d5ff541225a 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -468,29 +468,30 @@  int drm_mode_getfb(struct drm_device *dev,
 		goto out;
 	}
 
+	if (!fb->funcs->create_handle) {
+		ret = -ENODEV;
+		goto out;
+	}
+
 	r->height = fb->height;
 	r->width = fb->width;
 	r->depth = fb->format->depth;
 	r->bpp = fb->format->cpp[0] * 8;
 	r->pitch = fb->pitches[0];
-	if (fb->funcs->create_handle) {
-		if (drm_is_current_master(file_priv) || capable(CAP_SYS_ADMIN) ||
-		    drm_is_control_client(file_priv)) {
-			ret = fb->funcs->create_handle(fb, file_priv,
-						       &r->handle);
-		} else {
-			/* GET_FB() is an unprivileged ioctl so we must not
-			 * return a buffer-handle to non-master processes! For
-			 * backwards-compatibility reasons, we cannot make
-			 * GET_FB() privileged, so just return an invalid handle
-			 * for non-masters. */
-			r->handle = 0;
-			ret = 0;
-		}
-	} else {
-		ret = -ENODEV;
+
+	/* GET_FB() is an unprivileged ioctl so we must not return a
+	 * buffer-handle to non-master processes! For
+	 * backwards-compatibility reasons, we cannot make GET_FB() privileged,
+	 * so just return an invalid handle for non-masters. */
+	if (!drm_is_current_master(file_priv) && !capable(CAP_SYS_ADMIN) &&
+	    !drm_is_control_client(file_priv)) {
+		r->handle = 0;
+		ret = 0;
+		goto out;
 	}
 
+	ret = fb->funcs->create_handle(fb, file_priv, &r->handle);
+
 out:
 	drm_framebuffer_put(fb);