linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: "Dave Jiang" <dave.jiang@intel.com>,
	"Marek Behún" <kabel@kernel.org>,
	linux-kernel@vger.kernel.org,
	"Hans de Goede" <hdegoede@redhat.com>,
	"Matti Vaittinen" <mazziesaccount@gmail.com>
Cc: "Horia Geantă" <horia.geanta@nxp.com>,
	"Pankaj Gupta" <pankaj.gupta@nxp.com>,
	"Gaurav Jain" <gaurav.jain@nxp.com>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	"Davidlohr Bueso" <dave@stgolabs.net>,
	"Jonathan Cameron" <jonathan.cameron@huawei.com>,
	"Alison Schofield" <alison.schofield@intel.com>,
	"Vishal Verma" <vishal.l.verma@intel.com>,
	"Ira Weiny" <ira.weiny@intel.com>,
	"Dan Williams" <dan.j.williams@intel.com>,
	"Bamvor Jian Zhang" <bamv2005@gmail.com>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Bartosz Golaszewski" <brgl@bgdev.pl>,
	"Douglas Anderson" <dianders@chromium.org>,
	"Andrzej Hajda" <andrzej.hajda@intel.com>,
	"Neil Armstrong" <neil.armstrong@linaro.org>,
	"Robert Foss" <rfoss@kernel.org>,
	"Laurent Pinchart" <Laurent.pinchart@ideasonboard.com>,
	"Jonas Karlman" <jonas@kwiboo.se>,
	"Jernej Skrabec" <jernej.skrabec@gmail.com>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"David Airlie" <airlied@gmail.com>,
	"Daniel Vetter" <daniel@ffwll.ch>, "James Seo" <james@equiv.tech>,
	"Jean Delvare" <jdelvare@suse.com>,
	"Guenter Roeck" <linux@roeck-us.net>,
	linux-crypto@vger.kernel.org, linux-cxl@vger.kernel.org,
	linux-gpio@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-hwmon@vger.kernel.org
Subject: Re: [PATCH 2/2] devm-helpers: Add resource managed version of debugfs directory create function
Date: Thu, 22 Feb 2024 10:11:33 -0800	[thread overview]
Message-ID: <65d78e55844c1_1ee312946a@dwillia2-mobl3.amr.corp.intel.com.notmuch> (raw)
In-Reply-To: <23c50406-7ebd-4cc3-a978-1b8a5fc71ff0@intel.com>

Dave Jiang wrote:
> 
> 
> On 2/22/24 7:58 AM, Marek Behún wrote:
> > A few drivers register a devm action to remove a debugfs directory,
> > implementing a one-liner function that calls debufs_remove_recursive().
> > Help drivers avoid this repeated implementations by adding managed
> > version of debugfs directory create function.
> > 
> > Use the new function devm_debugfs_create_dir() in the following
> > drivers:
> >   drivers/crypto/caam/ctrl.c
> >   drivers/gpu/drm/bridge/ti-sn65dsi86.c
> >   drivers/hwmon/hp-wmi-sensors.c
> >   drivers/hwmon/mr75203.c
> >   drivers/hwmon/pmbus/pmbus_core.c
> > 
> > Also use the action function devm_debugfs_dir_recursive_drop() in
> > drivers
> >   drivers/cxl/mem.c
> >   drivers/gpio/gpio-mockup.c
> > 
> > Signed-off-by: Marek Behún <kabel@kernel.org>
> > ---
> >  drivers/crypto/caam/ctrl.c            | 16 +++------
> >  drivers/cxl/mem.c                     |  9 ++---
> >  drivers/gpio/gpio-mockup.c            | 11 ++----
> >  drivers/gpu/drm/bridge/ti-sn65dsi86.c | 13 ++------
> >  drivers/hwmon/hp-wmi-sensors.c        | 15 ++-------
> >  drivers/hwmon/mr75203.c               | 15 +++------
> >  drivers/hwmon/pmbus/pmbus_core.c      | 16 +++------
> >  include/linux/devm-helpers.h          | 48 +++++++++++++++++++++++++++
> >  8 files changed, 72 insertions(+), 71 deletions(-)
> > 
> > diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
> > index bdf367f3f679..ea3ed9a17f1a 100644
> > --- a/drivers/crypto/caam/ctrl.c
> > +++ b/drivers/crypto/caam/ctrl.c
> > @@ -7,6 +7,7 @@
> >   */
> >  
> >  #include <linux/device.h>
> > +#include <linux/devm-helpers.h>
> >  #include <linux/of_address.h>
> >  #include <linux/of_irq.h>
> >  #include <linux/platform_device.h>
> > @@ -604,11 +605,6 @@ static int init_clocks(struct device *dev, const struct caam_imx_data *data)
> >  	return devm_add_action_or_reset(dev, disable_clocks, ctrlpriv);
> >  }
> >  
> > -static void caam_remove_debugfs(void *root)
> > -{
> > -	debugfs_remove_recursive(root);
> > -}
> > -
> >  #ifdef CONFIG_FSL_MC_BUS
> >  static bool check_version(struct fsl_mc_version *mc_version, u32 major,
> >  			  u32 minor, u32 revision)
> > @@ -1058,13 +1054,9 @@ static int caam_probe(struct platform_device *pdev)
> >  	ctrlpriv->era = caam_get_era(perfmon);
> >  	ctrlpriv->domain = iommu_get_domain_for_dev(dev);
> >  
> > -	dfs_root = debugfs_create_dir(dev_name(dev), NULL);
> > -	if (IS_ENABLED(CONFIG_DEBUG_FS)) {
> > -		ret = devm_add_action_or_reset(dev, caam_remove_debugfs,
> > -					       dfs_root);
> > -		if (ret)
> > -			return ret;
> > -	}
> > +	dfs_root = devm_debugfs_create_dir(dev, dev_name(dev), NULL);
> > +	if (IS_ERR(dfs_root))
> > +		return PTR_ERR(dfs_root);
> >  
> >  	caam_debugfs_init(ctrlpriv, perfmon, dfs_root);
> >  
> > diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c
> > index c5c9d8e0d88d..4b38514887a4 100644
> > --- a/drivers/cxl/mem.c
> > +++ b/drivers/cxl/mem.c
> > @@ -2,6 +2,7 @@
> >  /* Copyright(c) 2022 Intel Corporation. All rights reserved. */
> >  #include <linux/debugfs.h>
> >  #include <linux/device.h>
> > +#include <linux/devm-helpers.h>
> >  #include <linux/module.h>
> >  #include <linux/pci.h>
> >  
> > @@ -30,11 +31,6 @@ static void enable_suspend(void *data)
> >  	cxl_mem_active_dec();
> >  }
> >  
> > -static void remove_debugfs(void *dentry)
> > -{
> > -	debugfs_remove_recursive(dentry);
> > -}
> > -
> >  static int cxl_mem_dpa_show(struct seq_file *file, void *data)
> >  {
> >  	struct device *dev = file->private;
> > @@ -138,7 +134,8 @@ static int cxl_mem_probe(struct device *dev)
> >  		debugfs_create_file("clear_poison", 0200, dentry, cxlmd,
> >  				    &cxl_poison_clear_fops);
> >  
> > -	rc = devm_add_action_or_reset(dev, remove_debugfs, dentry);
> > +	rc = devm_add_action_or_reset(dev, devm_debugfs_dir_recursive_drop,
> > +				      dentry);
> 
> This is probably the better fix for cxl:
> 
> diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h
> index 3b64fb1b9ed0..3258427af032 100644
> --- a/drivers/cxl/core/core.h
> +++ b/drivers/cxl/core/core.h
> @@ -57,7 +57,6 @@ int cxl_send_cmd(struct cxl_memdev *cxlmd, struct cxl_send_command __user *s);
>  void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr,
>  				   resource_size_t length);
>  
> -struct dentry *cxl_debugfs_create_dir(const char *dir);
>  int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,
>  		     enum cxl_decoder_mode mode);
>  int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size);
> diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
> index 27166a411705..5c2db4791b8b 100644
> --- a/drivers/cxl/core/mbox.c
> +++ b/drivers/cxl/core/mbox.c
> @@ -1402,7 +1402,7 @@ void __init cxl_mbox_init(void)
>  {
>  	struct dentry *mbox_debugfs;
>  
> -	mbox_debugfs = cxl_debugfs_create_dir("mbox");
> +	mbox_debugfs = debugfs_create_dir("mbox", NULL);
>  	debugfs_create_bool("raw_allow_all", 0600, mbox_debugfs,
>  			    &cxl_raw_allow_all);
>  }
> diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c
> index e59d9d37aa65..82c6a1c6aff4 100644
> --- a/drivers/cxl/core/port.c
> +++ b/drivers/cxl/core/port.c
> @@ -10,6 +10,7 @@
>  #include <linux/slab.h>
>  #include <linux/idr.h>
>  #include <linux/node.h>
> +#include <linux/devm-helpers.h>
>  #include <cxlmem.h>
>  #include <cxlpci.h>
>  #include <cxl.h>
> @@ -2207,13 +2208,7 @@ struct bus_type cxl_bus_type = {
>  };
>  EXPORT_SYMBOL_NS_GPL(cxl_bus_type, CXL);
>  
> -static struct dentry *cxl_debugfs;
> -
> -struct dentry *cxl_debugfs_create_dir(const char *dir)
> -{
> -	return debugfs_create_dir(dir, cxl_debugfs);
> -}
> -EXPORT_SYMBOL_NS_GPL(cxl_debugfs_create_dir, CXL);
> +struct dentry *cxl_debugfs;
>  
>  static __init int cxl_core_init(void)
>  {
> diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
> index b6017c0c57b4..ca8399b24955 100644
> --- a/drivers/cxl/cxl.h
> +++ b/drivers/cxl/cxl.h
> @@ -880,6 +880,8 @@ void cxl_switch_parse_cdat(struct cxl_port *port);
>  int cxl_endpoint_get_perf_coordinates(struct cxl_port *port,
>  				      struct access_coordinate *coord);
>  
> +extern struct dentry *cxl_debugfs;
> +
>  /*
>   * Unit test builds overrides this to __weak, find the 'strong' version
>   * of these symbols in tools/testing/cxl/.
> diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h
> index 5303d6942b88..b6f13ba87927 100644
> --- a/drivers/cxl/cxlmem.h
> +++ b/drivers/cxl/cxlmem.h
> @@ -859,6 +859,5 @@ struct cxl_hdm {
>  };
>  
>  struct seq_file;
> -struct dentry *cxl_debugfs_create_dir(const char *dir);
>  void cxl_dpa_debug(struct seq_file *file, struct cxl_dev_state *cxlds);
>  #endif /* __CXL_MEM_H__ */
> diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c
> index c5c9d8e0d88d..494abe7a54c5 100644
> --- a/drivers/cxl/mem.c
> +++ b/drivers/cxl/mem.c
> @@ -4,6 +4,7 @@
>  #include <linux/device.h>
>  #include <linux/module.h>
>  #include <linux/pci.h>
> +#include <linux/devm-helpers.h>
>  
>  #include "cxlmem.h"
>  #include "cxlpci.h"
> @@ -30,11 +31,6 @@ static void enable_suspend(void *data)
>  	cxl_mem_active_dec();
>  }
>  
> -static void remove_debugfs(void *dentry)
> -{
> -	debugfs_remove_recursive(dentry);
> -}
> -
>  static int cxl_mem_dpa_show(struct seq_file *file, void *data)
>  {
>  	struct device *dev = file->private;
> @@ -128,7 +124,10 @@ static int cxl_mem_probe(struct device *dev)
>  	if (work_pending(&cxlmd->detach_work))
>  		return -EBUSY;
>  
> -	dentry = cxl_debugfs_create_dir(dev_name(dev));
> +	dentry = devm_debugfs_create_dir(dev, dev_name(dev), NULL);
> +	if (IS_ERR(dentry))
> +		return PTR_ERR(dentry);
> +

No that loses the "cxl" prefix.

  reply	other threads:[~2024-02-22 18:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-22 14:58 [PATCH 1/2] devm-helpers: Add resource managed version of mutex init Marek Behún
2024-02-22 14:58 ` [PATCH 2/2] devm-helpers: Add resource managed version of debugfs directory create function Marek Behún
2024-02-22 15:23   ` Guenter Roeck
2024-02-22 17:23   ` Dave Jiang
2024-02-22 18:11     ` Dan Williams [this message]
2024-02-22 18:25       ` Dan Williams
2024-02-22 15:11 ` [PATCH 1/2] devm-helpers: Add resource managed version of mutex init Bartosz Golaszewski
2024-02-22 15:24 ` Guenter Roeck
2024-02-22 16:03   ` Guenter Roeck
2024-02-22 16:44 ` Matthew Auld
2024-02-22 18:33   ` Hans de Goede
2024-02-22 21:42 ` andy.shevchenko
2024-02-23 12:26   ` Marek Behún
2024-02-28  0:27     ` George Stark

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=65d78e55844c1_1ee312946a@dwillia2-mobl3.amr.corp.intel.com.notmuch \
    --to=dan.j.williams@intel.com \
    --cc=Laurent.pinchart@ideasonboard.com \
    --cc=airlied@gmail.com \
    --cc=alison.schofield@intel.com \
    --cc=andrzej.hajda@intel.com \
    --cc=bamv2005@gmail.com \
    --cc=brgl@bgdev.pl \
    --cc=daniel@ffwll.ch \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=davem@davemloft.net \
    --cc=dianders@chromium.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gaurav.jain@nxp.com \
    --cc=hdegoede@redhat.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=horia.geanta@nxp.com \
    --cc=ira.weiny@intel.com \
    --cc=james@equiv.tech \
    --cc=jdelvare@suse.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=jonas@kwiboo.se \
    --cc=jonathan.cameron@huawei.com \
    --cc=kabel@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mazziesaccount@gmail.com \
    --cc=mripard@kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=pankaj.gupta@nxp.com \
    --cc=rfoss@kernel.org \
    --cc=tzimmermann@suse.de \
    --cc=vishal.l.verma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).