diff mbox series

[v4,10/27] drm/bridge: ti-sn65dsi86: Clean debugfs code

Message ID 20210416153909.v4.10.I5fe072753290c6a77eda736ebd5778e17b7cb0fb@changeid (mailing list archive)
State New, archived
Headers show
Series drm: Fix EDID reading on ti-sn65dsi86; solve some chicken-and-egg problems | expand

Commit Message

Doug Anderson April 16, 2021, 10:39 p.m. UTC
Let's cleanup the debugfs code to:
- Check for errors.
- Use devm to manage freeing, which also means we don't need to store
  a pointer in our structure.

Signed-off-by: Douglas Anderson <dianders@chromium.org>
---

(no changes since v1)

 drivers/gpu/drm/bridge/ti-sn65dsi86.c | 32 +++++++++++++++++----------
 1 file changed, 20 insertions(+), 12 deletions(-)

Comments

Bjorn Andersson April 23, 2021, 2:35 p.m. UTC | #1
On Fri 16 Apr 17:39 CDT 2021, Douglas Anderson wrote:

> Let's cleanup the debugfs code to:
> - Check for errors.
> - Use devm to manage freeing, which also means we don't need to store
>   a pointer in our structure.
> 
> Signed-off-by: Douglas Anderson <dianders@chromium.org>
> ---
> 
> (no changes since v1)
> 
>  drivers/gpu/drm/bridge/ti-sn65dsi86.c | 32 +++++++++++++++++----------
>  1 file changed, 20 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> index 57574132e200..0c6aa99ddc99 100644
> --- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> +++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> @@ -118,7 +118,6 @@
>   * @aux:          Our aux channel.
>   * @bridge:       Our bridge.
>   * @connector:    Our connector.
> - * @debugfs:      Used for managing our debugfs.
>   * @host_node:    Remote DSI node.
>   * @dsi:          Our MIPI DSI source.
>   * @edid:         Detected EDID of eDP panel.
> @@ -146,7 +145,6 @@ struct ti_sn65dsi86 {
>  	struct drm_dp_aux		aux;
>  	struct drm_bridge		bridge;
>  	struct drm_connector		connector;
> -	struct dentry			*debugfs;
>  	struct edid			*edid;
>  	struct device_node		*host_node;
>  	struct mipi_dsi_device		*dsi;
> @@ -245,18 +243,30 @@ static int status_show(struct seq_file *s, void *data)
>  
>  DEFINE_SHOW_ATTRIBUTE(status);
>  
> -static void ti_sn65dsi86_debugfs_init(struct ti_sn65dsi86 *pdata)
> +static void ti_sn65dsi86_debugfs_remove(void *data)
>  {
> -	pdata->debugfs = debugfs_create_dir(dev_name(pdata->dev), NULL);
> -
> -	debugfs_create_file("status", 0600, pdata->debugfs, pdata,
> -			&status_fops);
> +	debugfs_remove_recursive(data);
>  }
>  
> -static void ti_sn65dsi86_debugfs_remove(struct ti_sn65dsi86 *pdata)
> +static void ti_sn65dsi86_debugfs_init(struct ti_sn65dsi86 *pdata)
>  {
> -	debugfs_remove_recursive(pdata->debugfs);
> -	pdata->debugfs = NULL;
> +	struct device *dev = pdata->dev;
> +	struct dentry *debugfs;
> +	int ret;
> +
> +	debugfs = debugfs_create_dir(dev_name(dev), NULL);
> +	if (IS_ERR(debugfs))
> +		ret = PTR_ERR(debugfs);
> +	else
> +		ret = devm_add_action_or_reset(dev, ti_sn65dsi86_debugfs_remove,
> +					       debugfs);
> +
> +	if (ret) {

You're not supposed to handle errors from debugfs_create_dir(), but I
like what you're doing with devm here and that needs a check.

Also worth mentioning is that at this point in the patch stack the
debugfs "status" file will outlive the activation of pm_runtime, this is
however taken care of in a later patch. Given that it's unlikely to
cause a problem I don't mind this transient issue - but wanted to
mention that I reviewed the end result in this regard.


Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Regards,
Bjorn

> +		dev_warn(dev, "Failed to create debugfs (%d), skipping\n", ret);
> +		return;
> +	}
> +
> +	debugfs_create_file("status", 0600, debugfs, pdata, &status_fops);
>  }
>  
>  /* Connector funcs */
> @@ -1310,8 +1320,6 @@ static int ti_sn65dsi86_remove(struct i2c_client *client)
>  
>  	kfree(pdata->edid);
>  
> -	ti_sn65dsi86_debugfs_remove(pdata);
> -
>  	drm_bridge_remove(&pdata->bridge);
>  
>  	pm_runtime_disable(pdata->dev);
> -- 
> 2.31.1.368.gbe11c130af-goog
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
index 57574132e200..0c6aa99ddc99 100644
--- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c
+++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
@@ -118,7 +118,6 @@ 
  * @aux:          Our aux channel.
  * @bridge:       Our bridge.
  * @connector:    Our connector.
- * @debugfs:      Used for managing our debugfs.
  * @host_node:    Remote DSI node.
  * @dsi:          Our MIPI DSI source.
  * @edid:         Detected EDID of eDP panel.
@@ -146,7 +145,6 @@  struct ti_sn65dsi86 {
 	struct drm_dp_aux		aux;
 	struct drm_bridge		bridge;
 	struct drm_connector		connector;
-	struct dentry			*debugfs;
 	struct edid			*edid;
 	struct device_node		*host_node;
 	struct mipi_dsi_device		*dsi;
@@ -245,18 +243,30 @@  static int status_show(struct seq_file *s, void *data)
 
 DEFINE_SHOW_ATTRIBUTE(status);
 
-static void ti_sn65dsi86_debugfs_init(struct ti_sn65dsi86 *pdata)
+static void ti_sn65dsi86_debugfs_remove(void *data)
 {
-	pdata->debugfs = debugfs_create_dir(dev_name(pdata->dev), NULL);
-
-	debugfs_create_file("status", 0600, pdata->debugfs, pdata,
-			&status_fops);
+	debugfs_remove_recursive(data);
 }
 
-static void ti_sn65dsi86_debugfs_remove(struct ti_sn65dsi86 *pdata)
+static void ti_sn65dsi86_debugfs_init(struct ti_sn65dsi86 *pdata)
 {
-	debugfs_remove_recursive(pdata->debugfs);
-	pdata->debugfs = NULL;
+	struct device *dev = pdata->dev;
+	struct dentry *debugfs;
+	int ret;
+
+	debugfs = debugfs_create_dir(dev_name(dev), NULL);
+	if (IS_ERR(debugfs))
+		ret = PTR_ERR(debugfs);
+	else
+		ret = devm_add_action_or_reset(dev, ti_sn65dsi86_debugfs_remove,
+					       debugfs);
+
+	if (ret) {
+		dev_warn(dev, "Failed to create debugfs (%d), skipping\n", ret);
+		return;
+	}
+
+	debugfs_create_file("status", 0600, debugfs, pdata, &status_fops);
 }
 
 /* Connector funcs */
@@ -1310,8 +1320,6 @@  static int ti_sn65dsi86_remove(struct i2c_client *client)
 
 	kfree(pdata->edid);
 
-	ti_sn65dsi86_debugfs_remove(pdata);
-
 	drm_bridge_remove(&pdata->bridge);
 
 	pm_runtime_disable(pdata->dev);