All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vga_switcheroo: no need to check return value of debugfs_create functions
@ 2019-06-13 11:44 Greg Kroah-Hartman
  2019-06-13 13:08 ` Daniel Vetter
  0 siblings, 1 reply; 2+ messages in thread
From: Greg Kroah-Hartman @ 2019-06-13 11:44 UTC (permalink / raw)
  To: Lukas Wunner, David Airlie, Daniel Vetter, Maarten Lankhorst,
	Maxime Ripard, Sean Paul
  Cc: dri-devel

When calling debugfs functions, there is no need to ever check the
return value.  The function can work or not, but the code logic should
never do something different based on this.

Also, because there is no need to save the file dentry, remove the local
variable and just recursively delete the whole directory when shutting
down.

Cc: Lukas Wunner <lukas@wunner.de>
Cc: David Airlie <airlied@linux.ie>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <maxime.ripard@bootlin.com>
Cc: Sean Paul <sean@poorly.run>
Cc: dri-devel@lists.freedesktop.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/gpu/vga/vga_switcheroo.c | 34 +++++++-------------------------
 1 file changed, 7 insertions(+), 27 deletions(-)

diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
index a132c37d7334..a48d810d6ccb 100644
--- a/drivers/gpu/vga/vga_switcheroo.c
+++ b/drivers/gpu/vga/vga_switcheroo.c
@@ -133,7 +133,6 @@ static DEFINE_MUTEX(vgasr_mutex);
  * @delayed_switch_active: whether a delayed switch is pending
  * @delayed_client_id: client to which a delayed switch is pending
  * @debugfs_root: directory for vga_switcheroo debugfs interface
- * @switch_file: file for vga_switcheroo debugfs interface
  * @registered_clients: number of registered GPUs
  *	(counting only vga clients, not audio clients)
  * @clients: list of registered clients
@@ -152,7 +151,6 @@ struct vgasr_priv {
 	enum vga_switcheroo_client_id delayed_client_id;
 
 	struct dentry *debugfs_root;
-	struct dentry *switch_file;
 
 	int registered_clients;
 	struct list_head clients;
@@ -168,7 +166,7 @@ struct vgasr_priv {
 #define client_is_vga(c)		(!client_is_audio(c))
 #define client_id(c)		((c)->id & ~ID_BIT_AUDIO)
 
-static int vga_switcheroo_debugfs_init(struct vgasr_priv *priv);
+static void vga_switcheroo_debugfs_init(struct vgasr_priv *priv);
 static void vga_switcheroo_debugfs_fini(struct vgasr_priv *priv);
 
 /* only one switcheroo per system */
@@ -914,38 +912,20 @@ static const struct file_operations vga_switcheroo_debugfs_fops = {
 
 static void vga_switcheroo_debugfs_fini(struct vgasr_priv *priv)
 {
-	debugfs_remove(priv->switch_file);
-	priv->switch_file = NULL;
-
-	debugfs_remove(priv->debugfs_root);
+	debugfs_remove_recursive(priv->debugfs_root);
 	priv->debugfs_root = NULL;
 }
 
-static int vga_switcheroo_debugfs_init(struct vgasr_priv *priv)
+static void vga_switcheroo_debugfs_init(struct vgasr_priv *priv)
 {
-	static const char mp[] = "/sys/kernel/debug";
-
 	/* already initialised */
 	if (priv->debugfs_root)
-		return 0;
-	priv->debugfs_root = debugfs_create_dir("vgaswitcheroo", NULL);
+		return;
 
-	if (!priv->debugfs_root) {
-		pr_err("Cannot create %s/vgaswitcheroo\n", mp);
-		goto fail;
-	}
+	priv->debugfs_root = debugfs_create_dir("vgaswitcheroo", NULL);
 
-	priv->switch_file = debugfs_create_file("switch", 0644,
-						priv->debugfs_root, NULL,
-						&vga_switcheroo_debugfs_fops);
-	if (!priv->switch_file) {
-		pr_err("cannot create %s/vgaswitcheroo/switch\n", mp);
-		goto fail;
-	}
-	return 0;
-fail:
-	vga_switcheroo_debugfs_fini(priv);
-	return -1;
+	debugfs_create_file("switch", 0644, priv->debugfs_root, NULL,
+			    &vga_switcheroo_debugfs_fops);
 }
 
 /**
-- 
2.22.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] vga_switcheroo: no need to check return value of debugfs_create functions
  2019-06-13 11:44 [PATCH] vga_switcheroo: no need to check return value of debugfs_create functions Greg Kroah-Hartman
@ 2019-06-13 13:08 ` Daniel Vetter
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Vetter @ 2019-06-13 13:08 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: David Airlie, dri-devel, Maxime Ripard, Sean Paul

On Thu, Jun 13, 2019 at 01:44:55PM +0200, Greg Kroah-Hartman wrote:
> When calling debugfs functions, there is no need to ever check the
> return value.  The function can work or not, but the code logic should
> never do something different based on this.
> 
> Also, because there is no need to save the file dentry, remove the local
> variable and just recursively delete the whole directory when shutting
> down.
> 
> Cc: Lukas Wunner <lukas@wunner.de>
> Cc: David Airlie <airlied@linux.ie>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <maxime.ripard@bootlin.com>
> Cc: Sean Paul <sean@poorly.run>
> Cc: dri-devel@lists.freedesktop.org
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Applied to drm-misc-next, thanks.
-Daniel

> ---
>  drivers/gpu/vga/vga_switcheroo.c | 34 +++++++-------------------------
>  1 file changed, 7 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
> index a132c37d7334..a48d810d6ccb 100644
> --- a/drivers/gpu/vga/vga_switcheroo.c
> +++ b/drivers/gpu/vga/vga_switcheroo.c
> @@ -133,7 +133,6 @@ static DEFINE_MUTEX(vgasr_mutex);
>   * @delayed_switch_active: whether a delayed switch is pending
>   * @delayed_client_id: client to which a delayed switch is pending
>   * @debugfs_root: directory for vga_switcheroo debugfs interface
> - * @switch_file: file for vga_switcheroo debugfs interface
>   * @registered_clients: number of registered GPUs
>   *	(counting only vga clients, not audio clients)
>   * @clients: list of registered clients
> @@ -152,7 +151,6 @@ struct vgasr_priv {
>  	enum vga_switcheroo_client_id delayed_client_id;
>  
>  	struct dentry *debugfs_root;
> -	struct dentry *switch_file;
>  
>  	int registered_clients;
>  	struct list_head clients;
> @@ -168,7 +166,7 @@ struct vgasr_priv {
>  #define client_is_vga(c)		(!client_is_audio(c))
>  #define client_id(c)		((c)->id & ~ID_BIT_AUDIO)
>  
> -static int vga_switcheroo_debugfs_init(struct vgasr_priv *priv);
> +static void vga_switcheroo_debugfs_init(struct vgasr_priv *priv);
>  static void vga_switcheroo_debugfs_fini(struct vgasr_priv *priv);
>  
>  /* only one switcheroo per system */
> @@ -914,38 +912,20 @@ static const struct file_operations vga_switcheroo_debugfs_fops = {
>  
>  static void vga_switcheroo_debugfs_fini(struct vgasr_priv *priv)
>  {
> -	debugfs_remove(priv->switch_file);
> -	priv->switch_file = NULL;
> -
> -	debugfs_remove(priv->debugfs_root);
> +	debugfs_remove_recursive(priv->debugfs_root);
>  	priv->debugfs_root = NULL;
>  }
>  
> -static int vga_switcheroo_debugfs_init(struct vgasr_priv *priv)
> +static void vga_switcheroo_debugfs_init(struct vgasr_priv *priv)
>  {
> -	static const char mp[] = "/sys/kernel/debug";
> -
>  	/* already initialised */
>  	if (priv->debugfs_root)
> -		return 0;
> -	priv->debugfs_root = debugfs_create_dir("vgaswitcheroo", NULL);
> +		return;
>  
> -	if (!priv->debugfs_root) {
> -		pr_err("Cannot create %s/vgaswitcheroo\n", mp);
> -		goto fail;
> -	}
> +	priv->debugfs_root = debugfs_create_dir("vgaswitcheroo", NULL);
>  
> -	priv->switch_file = debugfs_create_file("switch", 0644,
> -						priv->debugfs_root, NULL,
> -						&vga_switcheroo_debugfs_fops);
> -	if (!priv->switch_file) {
> -		pr_err("cannot create %s/vgaswitcheroo/switch\n", mp);
> -		goto fail;
> -	}
> -	return 0;
> -fail:
> -	vga_switcheroo_debugfs_fini(priv);
> -	return -1;
> +	debugfs_create_file("switch", 0644, priv->debugfs_root, NULL,
> +			    &vga_switcheroo_debugfs_fops);
>  }
>  
>  /**
> -- 
> 2.22.0
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-06-13 13:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-13 11:44 [PATCH] vga_switcheroo: no need to check return value of debugfs_create functions Greg Kroah-Hartman
2019-06-13 13:08 ` Daniel Vetter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.