The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Nuno Sá" <nuno.sa@analog.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>,
	linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
	Jonathan Cameron <jic23@kernel.org>,
	David Lechner <dlechner@baylibre.com>,
	Andy Shevchenko <andy@kernel.org>,
	Rupesh Majhi <zoone.rupert@gmail.com>
Subject: Re: [PATCH v1 1/1] iio: core: Split debugfs routines
Date: Tue, 24 Nov 2026 11:26:10 +0000	[thread overview]
Message-ID: <awVz_NIDb01OZL3y@nsa> (raw)
In-Reply-To: <20261124094502.557175-1-andriy.shevchenko@linux.intel.com>

On Tue, Nov 24, 2026 at 10:44:10AM +0100, Andy Shevchenko wrote:
> Split debugfs routines into a separate file for easier maintenance.
> No functional changes intended.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---

Looks good! With the compilation fix in v2:

Reviewed-by: Nuno Sá <nuno.sa@analog.com>

> 
> Rupesh, feel free to include this patch into your series as the first one.
> 
> Fun fact: This patch was written with zero AI assistance.
> 
>  drivers/iio/Makefile               |   1 +
>  drivers/iio/iio_core.h             |  14 +++
>  drivers/iio/industrialio-core.c    | 152 +-------------------------
>  drivers/iio/industrialio-debugfs.c | 165 +++++++++++++++++++++++++++++
>  4 files changed, 182 insertions(+), 150 deletions(-)
>  create mode 100644 drivers/iio/industrialio-debugfs.c
> 
> diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
> index 8a897b6729d2..5fd81b20da22 100644
> --- a/drivers/iio/Makefile
> +++ b/drivers/iio/Makefile
> @@ -8,6 +8,7 @@ industrialio-y := industrialio-core.o industrialio-event.o inkern.o
>  industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o
>  industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o
>  industrialio-$(CONFIG_ACPI) += industrialio-acpi.o
> +industrialio-$(CONFIG_DEBUG_FS) += industrialio-debugfs.o
>  
>  obj-$(CONFIG_IIO_CONFIGFS) += industrialio-configfs.o
>  obj-$(CONFIG_IIO_GTS_HELPER) += industrialio-gts-helper.o
> diff --git a/drivers/iio/iio_core.h b/drivers/iio/iio_core.h
> index 59fa1bd9924b..985ac82a37f9 100644
> --- a/drivers/iio/iio_core.h
> +++ b/drivers/iio/iio_core.h
> @@ -16,6 +16,20 @@ struct iio_buffer;
>  struct iio_chan_spec;
>  struct iio_dev;
>  
> +#if defined(CONFIG_DEBUG_FS)
> +void iio_debugfs_create(void);
> +void iio_debugfs_remove(void);
> +
> +void iio_device_unregister_debugfs(struct iio_dev *indio_dev);
> +void iio_device_register_debugfs(struct iio_dev *indio_dev);
> +#else
> +static inline void iio_debugfs_create(void) {}
> +static inline void iio_debugfs_remove(void) {}
> +
> +static void iio_device_register_debugfs(struct iio_dev *indio_dev) {}
> +static void iio_device_unregister_debugfs(struct iio_dev *indio_dev) {}
> +#endif /* CONFIG_DEBUG_FS */
> +
>  extern const struct device_type iio_device_type;
>  
>  struct iio_dev_buffer_pair {
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 792c2d28835b..3b66d7b765d5 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -14,7 +14,6 @@
>  #include <linux/anon_inodes.h>
>  #include <linux/cdev.h>
>  #include <linux/cleanup.h>
> -#include <linux/debugfs.h>
>  #include <linux/device.h>
>  #include <linux/err.h>
>  #include <linux/export.h>
> @@ -54,8 +53,6 @@ const struct bus_type iio_bus_type = {
>  };
>  EXPORT_SYMBOL(iio_bus_type);
>  
> -static struct dentry *iio_debugfs_dentry;
> -
>  static const char * const iio_direction[] = {
>  	[0] = "in",
>  	[1] = "out",
> @@ -293,20 +290,6 @@ bool iio_buffer_enabled(struct iio_dev *indio_dev)
>  }
>  EXPORT_SYMBOL_GPL(iio_buffer_enabled);
>  
> -#if defined(CONFIG_DEBUG_FS)
> -/*
> - * There's also a CONFIG_DEBUG_FS guard in include/linux/iio/iio.h for
> - * iio_get_debugfs_dentry() to make it inline if CONFIG_DEBUG_FS is undefined
> - */
> -struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
> -{
> -	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> -
> -	return iio_dev_opaque->debugfs_dentry;
> -}
> -EXPORT_SYMBOL_GPL(iio_get_debugfs_dentry);
> -#endif
> -
>  /**
>   * iio_find_channel_from_si() - get channel from its scan index
>   * @indio_dev:		device
> @@ -427,7 +410,7 @@ static int __init iio_init(void)
>  		goto error_unregister_bus_type;
>  	}
>  
> -	iio_debugfs_dentry = debugfs_create_dir("iio", NULL);
> +	iio_debugfs_create();
>  
>  	return 0;
>  
> @@ -442,140 +425,9 @@ static void __exit iio_exit(void)
>  	if (iio_devt)
>  		unregister_chrdev_region(iio_devt, IIO_DEV_MAX);
>  	bus_unregister(&iio_bus_type);
> -	debugfs_remove(iio_debugfs_dentry);
> +	iio_debugfs_remove();
>  }
>  
> -#if defined(CONFIG_DEBUG_FS)
> -static ssize_t iio_debugfs_read_reg(struct file *file, char __user *userbuf,
> -			      size_t count, loff_t *ppos)
> -{
> -	struct iio_dev *indio_dev = file->private_data;
> -	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> -	unsigned int val = 0;
> -	u64 val64 = 0;
> -	int ret;
> -
> -	if (*ppos > 0)
> -		return simple_read_from_buffer(userbuf, count, ppos,
> -					       iio_dev_opaque->read_buf,
> -					       iio_dev_opaque->read_buf_len);
> -
> -	if (indio_dev->info->debugfs_reg64_access) {
> -		ret = indio_dev->info->debugfs_reg64_access(indio_dev,
> -							    iio_dev_opaque->cached_reg_addr,
> -							    0, &val64);
> -	} else {
> -		ret = indio_dev->info->debugfs_reg_access(indio_dev,
> -							  iio_dev_opaque->cached_reg_addr,
> -							  0, &val);
> -		val64 = val;
> -	}
> -
> -	if (ret) {
> -		dev_err(indio_dev->dev.parent, "%s: read failed\n", __func__);
> -		return ret;
> -	}
> -
> -	iio_dev_opaque->read_buf_len = snprintf(iio_dev_opaque->read_buf,
> -						sizeof(iio_dev_opaque->read_buf),
> -						"0x%llX\n", val64);
> -
> -	return simple_read_from_buffer(userbuf, count, ppos,
> -				       iio_dev_opaque->read_buf,
> -				       iio_dev_opaque->read_buf_len);
> -}
> -
> -static ssize_t iio_debugfs_write_reg(struct file *file,
> -		     const char __user *userbuf, size_t count, loff_t *ppos)
> -{
> -	struct iio_dev *indio_dev = file->private_data;
> -	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> -	unsigned int reg;
> -	char buf[80];
> -	u64 val64;
> -	int ret;
> -
> -	if (*ppos != 0 || count >= sizeof(buf))
> -		return -EINVAL;
> -
> -	ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, userbuf,
> -				     count);
> -	if (ret < 0)
> -		return ret;
> -
> -	buf[ret] = '\0';
> -
> -	ret = sscanf(buf, "%i %lli", &reg, &val64);
> -
> -	switch (ret) {
> -	case 1:
> -		iio_dev_opaque->cached_reg_addr = reg;
> -		break;
> -	case 2:
> -		iio_dev_opaque->cached_reg_addr = reg;
> -		if (indio_dev->info->debugfs_reg64_access)
> -			ret = indio_dev->info->debugfs_reg64_access(indio_dev, reg,
> -								    val64, NULL);
> -		else
> -			ret = indio_dev->info->debugfs_reg_access(indio_dev, reg,
> -								  val64, NULL);
> -		if (ret) {
> -			dev_err(indio_dev->dev.parent, "%s: write failed\n",
> -				__func__);
> -			return ret;
> -		}
> -		break;
> -	default:
> -		return -EINVAL;
> -	}
> -
> -	return count;
> -}
> -
> -static const struct file_operations iio_debugfs_reg_fops = {
> -	.open = simple_open,
> -	.read = iio_debugfs_read_reg,
> -	.write = iio_debugfs_write_reg,
> -};
> -
> -static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)
> -{
> -	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> -
> -	debugfs_remove_recursive(iio_dev_opaque->debugfs_dentry);
> -}
> -
> -static void iio_device_register_debugfs(struct iio_dev *indio_dev)
> -{
> -	struct iio_dev_opaque *iio_dev_opaque;
> -
> -	if (!indio_dev->info->debugfs_reg_access &&
> -	    !indio_dev->info->debugfs_reg64_access)
> -		return;
> -
> -	if (!iio_debugfs_dentry)
> -		return;
> -
> -	iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> -
> -	iio_dev_opaque->debugfs_dentry =
> -		debugfs_create_dir(dev_name(&indio_dev->dev),
> -				   iio_debugfs_dentry);
> -
> -	debugfs_create_file("direct_reg_access", 0644,
> -			    iio_dev_opaque->debugfs_dentry, indio_dev,
> -			    &iio_debugfs_reg_fops);
> -}
> -#else
> -static void iio_device_register_debugfs(struct iio_dev *indio_dev)
> -{
> -}
> -
> -static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)
> -{
> -}
> -#endif /* CONFIG_DEBUG_FS */
> -
>  static ssize_t iio_read_channel_ext_info(struct device *dev,
>  				     struct device_attribute *attr,
>  				     char *buf)
> diff --git a/drivers/iio/industrialio-debugfs.c b/drivers/iio/industrialio-debugfs.c
> new file mode 100644
> index 000000000000..7ceeb88f9276
> --- /dev/null
> +++ b/drivers/iio/industrialio-debugfs.c
> @@ -0,0 +1,165 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Industrial I/O debugfs bits
> + */
> +
> +#include <linux/cdev.h>
> +#include <linux/debugfs.h>
> +#include <linux/dev_printk.h>
> +#include <linux/errno.h>
> +#include <linux/export.h>
> +#include <linux/fs.h>
> +#include <linux/init.h>
> +#include <linux/sprintf.h>
> +#include <linux/sysfs.h>
> +#include <linux/types.h>
> +
> +#include <linux/iio/iio.h>
> +#include <linux/iio/iio-opaque.h>
> +
> +#include "iio_core.h"
> +
> +static struct dentry *iio_debugfs_dentry;
> +
> +/*
> + * There's also a CONFIG_DEBUG_FS guard in include/linux/iio/iio.h for
> + * iio_get_debugfs_dentry() to make it inline if CONFIG_DEBUG_FS is undefined
> + */
> +struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
> +{
> +	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> +
> +	return iio_dev_opaque->debugfs_dentry;
> +}
> +EXPORT_SYMBOL_GPL(iio_get_debugfs_dentry);
> +
> +void __init iio_debugfs_create(void)
> +{
> +	iio_debugfs_dentry = debugfs_create_dir("iio", NULL);
> +}
> +
> +void __exit iio_debugfs_remove(void)
> +{
> +	debugfs_remove(iio_debugfs_dentry);
> +}
> +
> +static ssize_t iio_debugfs_read_reg(struct file *file, char __user *userbuf,
> +			      size_t count, loff_t *ppos)
> +{
> +	struct iio_dev *indio_dev = file->private_data;
> +	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> +	unsigned int val = 0;
> +	u64 val64 = 0;
> +	int ret;
> +
> +	if (*ppos > 0)
> +		return simple_read_from_buffer(userbuf, count, ppos,
> +					       iio_dev_opaque->read_buf,
> +					       iio_dev_opaque->read_buf_len);
> +
> +	if (indio_dev->info->debugfs_reg64_access) {
> +		ret = indio_dev->info->debugfs_reg64_access(indio_dev,
> +							    iio_dev_opaque->cached_reg_addr,
> +							    0, &val64);
> +	} else {
> +		ret = indio_dev->info->debugfs_reg_access(indio_dev,
> +							  iio_dev_opaque->cached_reg_addr,
> +							  0, &val);
> +		val64 = val;
> +	}
> +
> +	if (ret) {
> +		dev_err(indio_dev->dev.parent, "%s: read failed\n", __func__);
> +		return ret;
> +	}
> +
> +	iio_dev_opaque->read_buf_len = snprintf(iio_dev_opaque->read_buf,
> +						sizeof(iio_dev_opaque->read_buf),
> +						"0x%llX\n", val64);
> +
> +	return simple_read_from_buffer(userbuf, count, ppos,
> +				       iio_dev_opaque->read_buf,
> +				       iio_dev_opaque->read_buf_len);
> +}
> +
> +static ssize_t iio_debugfs_write_reg(struct file *file,
> +		     const char __user *userbuf, size_t count, loff_t *ppos)
> +{
> +	struct iio_dev *indio_dev = file->private_data;
> +	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> +	unsigned int reg;
> +	char buf[80];
> +	u64 val64;
> +	int ret;
> +
> +	if (*ppos != 0 || count >= sizeof(buf))
> +		return -EINVAL;
> +
> +	ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, userbuf,
> +				     count);
> +	if (ret < 0)
> +		return ret;
> +
> +	buf[ret] = '\0';
> +
> +	ret = sscanf(buf, "%i %lli", &reg, &val64);
> +
> +	switch (ret) {
> +	case 1:
> +		iio_dev_opaque->cached_reg_addr = reg;
> +		break;
> +	case 2:
> +		iio_dev_opaque->cached_reg_addr = reg;
> +		if (indio_dev->info->debugfs_reg64_access)
> +			ret = indio_dev->info->debugfs_reg64_access(indio_dev, reg,
> +								    val64, NULL);
> +		else
> +			ret = indio_dev->info->debugfs_reg_access(indio_dev, reg,
> +								  val64, NULL);
> +		if (ret) {
> +			dev_err(indio_dev->dev.parent, "%s: write failed\n",
> +				__func__);
> +			return ret;
> +		}
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	return count;
> +}
> +
> +static const struct file_operations iio_debugfs_reg_fops = {
> +	.open = simple_open,
> +	.read = iio_debugfs_read_reg,
> +	.write = iio_debugfs_write_reg,
> +};
> +
> +static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)
> +{
> +	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> +
> +	debugfs_remove_recursive(iio_dev_opaque->debugfs_dentry);
> +}
> +
> +static void iio_device_register_debugfs(struct iio_dev *indio_dev)
> +{
> +	struct iio_dev_opaque *iio_dev_opaque;
> +
> +	if (!indio_dev->info->debugfs_reg_access &&
> +	    !indio_dev->info->debugfs_reg64_access)
> +		return;
> +
> +	if (!iio_debugfs_dentry)
> +		return;
> +
> +	iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> +
> +	iio_dev_opaque->debugfs_dentry =
> +		debugfs_create_dir(dev_name(&indio_dev->dev),
> +				   iio_debugfs_dentry);
> +
> +	debugfs_create_file("direct_reg_access", 0644,
> +			    iio_dev_opaque->debugfs_dentry, indio_dev,
> +			    &iio_debugfs_reg_fops);
> +}
> -- 
> 2.50.1
> 

      parent reply	other threads:[~2026-11-24 11:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  9:44 [PATCH v1 1/1] iio: core: Split debugfs routines Andy Shevchenko
2026-11-24 10:17 ` Joshua Crofts
2026-11-24 10:46   ` Andy Shevchenko
2026-11-24 10:51     ` Joshua Crofts
2026-11-24 11:04       ` Andy Shevchenko
2026-11-24 10:51     ` Andy Shevchenko
2026-11-24 10:55       ` Joshua Crofts
2026-11-24 11:07         ` Andy Shevchenko
2026-11-24 11:26 ` Nuno Sá [this message]

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=awVz_NIDb01OZL3y@nsa \
    --to=nuno.sa@analog.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=jonathan.cameron@oss.qualcomm.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zoone.rupert@gmail.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