iio: core: Split debugfs routines
PATCH 1/1 iio: core: Split debugfs routines
Split debugfs routines into a separate file for easier maintenance. No functional changes intended.
---
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
drivers/iio/Makefile +1 -0
@@ -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
drivers/iio/iio_core.h +14 -0
@@ -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 {
drivers/iio/industrialio-core.c +2 -150
184 lines not on this page · raw message
drivers/iio/industrialio-debugfs.c new file +165 -0
165 lines not on this page · raw message
Signature · 1 line
2.50.1
Quoted 9 lines · Andy Shevchenko
Split debugfs routines into a separate file for easier maintenance. No functional changes intended.
Signed-off-by Andy Shevchenko <[email protected]>---
Rupesh, feel free to include this patch into your series as the first one.
Fun fact: This patch was written with zero AI assistance.
:)
Quoted 25 lines
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.cdrivers/iio/Makefile +1
-0@@ -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.odrivers/iio/iio_core.h +0
-0
drivers/iio/iio_core.h struct iio_buffer; · line 19
Quoted 4 lines
drivers/iio/iio_core.h +1
-0@@ -16,6 +16,20 @@ struct iio_buffer;struct iio_chan_spec ;struct iio_dev ; +#if defined(CONFIG_DEBUG_FS )
Veeery small nit, but why not #ifdef CONFIG_DEBUG_FS? It's not as if you're checking for multiple defines.
Quoted 15 lines
drivers/iio/iio_core.h +13
-0+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;
...
drivers/iio/iio_core.h
Quoted 7 lines
drivers/iio/iio_core.h +7
-0+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)
Static here but not in the header file. Same goes for register_debugfs().
Signature · 2 lines
Kind regards, Joshua Crofts
Quoted 1 line · Joshua Crofts
On 24-Nov-26 10:44, Andy Shevchenko wrote:
Thanks for the review, my replies below.
...
Quoted 4 lines
Quoted 1 line
+#if
defined(CONFIG_DEBUG_FS)Veeery small nit, but why not #ifdef
CONFIG_DEBUG_FS? It's not as if you're checking for multiple defines.
Or even IS_ENABLED()? Let me check if we have a precedent in IIO, I will use then the same or most used style.
Quoted 14 lines
Quoted 14 lines
drivers/iio/iio_core.h +13
-0+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;
...
Quoted 9 lines
drivers/iio/industrialio-debugfs.c line 138
Quoted 7 lines
drivers/iio/industrialio-debugfs.c new file +7
-0+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)Static here but not in the header file. Same goes for
register_debugfs().
Oh, how does it compile?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 11 lines · Andy Shevchenko
Quoted 9 lines
drivers/iio/industrialio-debugfs.c line 138
Quoted 7 lines
drivers/iio/industrialio-debugfs.c new file +7
-0+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)Static here but not in the header file. Same goes for
register_debugfs().Oh, how does it compile?
Unfortunately it doesn't :(
drivers/iio/industrialio-debugfs.c:138:13: error: static declaration of ‘iio_device_unregister_debugfs’ follows non-static declaration
138 | static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from drivers/iio/industrialio-debugfs.c:20:
drivers/iio/iio_core.h:23:6: note: previous declaration of ‘iio_device_unregister_debugfs’ with type ‘void(struct iio_dev *)’
23 | void iio_device_unregister_debugfs(struct iio_dev *indio_dev);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/iio/industrialio-debugfs.c:145:13: error: static declaration of ‘iio_device_register_debugfs’ follows non-static declaration
145 | static void iio_device_register_debugfs(struct iio_dev *indio_dev)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/iio/iio_core.h:24:6: note: previous declaration of ‘iio_device_register_debugfs’ with type ‘void(struct iio_dev *)’
24 | void iio_device_register_debugfs(struct iio_dev *indio_dev);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/iio/industrialio-debugfs.c:145:13: warning: ‘iio_device_register_debugfs’ defined but not used [-Wunused-function]
145 | static void iio_device_register_debugfs(struct iio_dev *indio_dev)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/iio/industrialio-debugfs.c:138:13: warning: ‘iio_device_unregister_debugfs’ defined but not used [-Wunused-function]
138 | static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~make[4]: *** [scripts/Makefile.build:290: drivers/iio/industrialio-debugfs.o] Error 1
Signature · 2 lines
Kind regards, Joshua Crofts
Quoted 11 lines · Joshua Crofts
Quoted 10 lines · Andy Shevchenko
Quoted 9 lines
drivers/iio/industrialio-debugfs.c line 138
Quoted 7 lines
drivers/iio/industrialio-debugfs.c new file +7
-0+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)Static here but not in the header file. Same goes for
register_debugfs().
Quoted 2 lines
Quoted 1 line
Oh, how does it compile?
Unfortunately it doesn't :(
It means I have DEBUG_FS disabled (in the configuration I used for compile-test)!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Joshua Crofts
On 24-Nov-26 10:44, Andy Shevchenko wrote:
...
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
+#if
defined(CONFIG_DEBUG_FS)Veeery small nit, but why not #ifdef
CONFIG_DEBUG_FS? It's not as if you're checking for multiple defines.Or even
IS_ENABLED()? Let me check if we have a precedent in IIO, I will use then the same or most used style.
FWIW, iio core uses exactly this form for DEBUG_FS test, so for the consistency I leave it as it, and if required we can fix this later.
$ git grep -n '^#if.*DEBUG' -- drivers/iio/ include/linux/iio/ drivers/iio/gyro/adis16136.c:66:#ifdef CONFIG_DEBUG_FS drivers/iio/humidity/dht11.c:87:#ifdef CONFIG_DYNAMIC_DEBUG drivers/iio/humidity/dht11.c:235:#ifdef CONFIG_DYNAMIC_DEBUG drivers/iio/iio_core.h:19:#if defined(CONFIG_DEBUG_FS) drivers/iio/imu/adis.c:227:#ifdef CONFIG_DEBUG_FS include/linux/iio/iio-opaque.h:73:#if defined(CONFIG_DEBUG_FS) include/linux/iio/iio.h:1010:#if defined(CONFIG_DEBUG_FS) include/linux/iio/imu/adis.h:573:#ifdef CONFIG_DEBUG_FS
...
Quoted 3 lines
Quoted 1 line
Static here but not in the header file. Same goes for
register_debugfs().Oh, how does it compile?
Will be fixed in v2. I'll wait a bit and send an update tomorrow.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 17 lines · Andy Shevchenko
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Joshua Crofts
On 24-Nov-26 10:44, Andy Shevchenko wrote:
...
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
+#if
defined(CONFIG_DEBUG_FS)Veeery small nit, but why not #ifdef
CONFIG_DEBUG_FS? It's not as if you're checking for multiple defines.Or even
IS_ENABLED()? Let me check if we have a precedent in IIO, I will use then the same or most used style.FWIW, iio core uses exactly this form for
DEBUG_FStest, so for the consistency I leave it as it, and if required we can fix this later.
Quoted 9 lines
$ git grep -n '^#if.*DEBUG' -- drivers/iio/ include/linux/iio/ drivers/iio/gyro/adis16136.c:66:#ifdef CONFIG_DEBUG_FS drivers/iio/humidity/dht11.c:87:#ifdef CONFIG_DYNAMIC_DEBUG drivers/iio/humidity/dht11.c:235:#ifdef CONFIG_DYNAMIC_DEBUG drivers/iio/iio_core.h:19:#if defined(CONFIG_DEBUG_FS) drivers/iio/imu/adis.c:227:#ifdef CONFIG_DEBUG_FS include/linux/iio/iio-opaque.h:73:#if defined(CONFIG_DEBUG_FS) include/linux/iio/iio.h:1010:#if defined(CONFIG_DEBUG_FS) include/linux/iio/imu/adis.h:573:#ifdef CONFIG_DEBUG_FS
Fair enough. It's just a style preference I guess, hence the very small nit.
Signature · 2 lines
Kind regards, Joshua Crofts
Quoted 4 lines · Joshua Crofts
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Joshua Crofts
On 24-Nov-26 10:44, Andy Shevchenko wrote:
...
Quoted 21 lines
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
+#if
defined(CONFIG_DEBUG_FS)Veeery small nit, but why not #ifdef
CONFIG_DEBUG_FS? It's not as if you're checking for multiple defines.Or even
IS_ENABLED()? Let me check if we have a precedent in IIO, I will use then the same or most used style.FWIW, iio core uses exactly this form for
DEBUG_FStest, so for the consistency I leave it as it, and if required we can fix this later.Quoted 9 lines
$ git grep -n '^#if.*DEBUG' -- drivers/iio/ include/linux/iio/ drivers/iio/gyro/adis16136.c:66:#ifdef CONFIG_DEBUG_FS drivers/iio/humidity/dht11.c:87:#ifdef CONFIG_DYNAMIC_DEBUG drivers/iio/humidity/dht11.c:235:#ifdef CONFIG_DYNAMIC_DEBUG drivers/iio/iio_core.h:19:#if defined(CONFIG_DEBUG_FS) drivers/iio/imu/adis.c:227:#ifdef CONFIG_DEBUG_FS include/linux/iio/iio-opaque.h:73:#if defined(CONFIG_DEBUG_FS) include/linux/iio/iio.h:1010:#if defined(CONFIG_DEBUG_FS) include/linux/iio/imu/adis.h:573:#ifdef CONFIG_DEBUG_FS
Quoted 1 line
Fair enough. It's just a style preference I guess, hence the very small nit.
Yep, and even if I also think about plain #ifdef the consistency would prevail over the style.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 5 lines · Andy Shevchenko
Split debugfs routines into a separate file for easier maintenance. No functional changes intended.
Signed-off-by Andy Shevchenko <[email protected]>---
Looks good! With the compilation fix in v2:
Quoted 416 lines
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.cdrivers/iio/Makefile +1
-0@@ -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.odrivers/iio/iio_core.h +14
-0@@ -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 {drivers/iio/industrialio-core.c +2
-150@@ -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" , ®, &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)drivers/iio/industrialio-debugfs.c new file +165
-0@@ -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" , ®, &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); +}Signature · 1 line
2.50.1
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Andy,
kernel test robot noticed the following build errors:
[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on linus/master v7.4-rc4 next-20261123] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/iio-core-Split-debugfs-routines/20261124-104410 base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg patch link: https://lore.kernel.org/r/20261124094502.557175-1-andriy.shevchenko%40linux.intel.com patch subject: [PATCH v1 1/1] iio: core: Split debugfs routines config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20261125/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261125/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All error/warnings (new ones prefixed by >>):
>> drivers/iio/industrialio-debugfs.c:138:13: error: static declaration of 'iio_device_unregister_debugfs' follows non-static declaration
138 | static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from drivers/iio/industrialio-debugfs.c:20:
drivers/iio/iio_core.h:23:6: note: previous declaration of 'iio_device_unregister_debugfs' with type 'void(struct iio_dev *)'
23 | void iio_device_unregister_debugfs(struct iio_dev *indio_dev);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/iio/industrialio-debugfs.c:145:13: error: static declaration of 'iio_device_register_debugfs' follows non-static declaration
145 | static void iio_device_register_debugfs(struct iio_dev *indio_dev)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/iio/iio_core.h:24:6: note: previous declaration of 'iio_device_register_debugfs' with type 'void(struct iio_dev *)'
24 | void iio_device_register_debugfs(struct iio_dev *indio_dev);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/iio/industrialio-debugfs.c:145:13: warning: 'iio_device_register_debugfs' defined but not used [-Wunused-function]
145 | static void iio_device_register_debugfs(struct iio_dev *indio_dev)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/iio/industrialio-debugfs.c:138:13: warning: 'iio_device_unregister_debugfs' defined but not used [-Wunused-function] 138 | static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +/iio_device_unregister_debugfs +138 drivers/iio/industrialio-debugfs.c
137
> 138 static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)
139 {
140 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
141
142 debugfs_remove_recursive(iio_dev_opaque->debugfs_dentry);
143 }
144
> 145 static void iio_device_register_debugfs(struct iio_dev *indio_dev)Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Andy,
kernel test robot noticed the following build warnings:
[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on linus/master v7.4-rc4 next-20261123] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/iio-core-Split-debugfs-routines/20261124-104410 base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg patch link: https://lore.kernel.org/r/20261124094502.557175-1-andriy.shevchenko%40linux.intel.com patch subject: [PATCH v1 1/1] iio: core: Split debugfs routines config: arm-s5pv210_defconfig (https://download.01.org/0day-ci/archive/20261125/[email protected]/config) compiler: arm-linux-gnueabi-gcc (GCC) 16.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261125/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from drivers/iio/industrialio-event.c:22:
>> drivers/iio/iio_core.h:30:13: warning: 'iio_device_unregister_debugfs' defined but not used [-Wunused-function]
30 | static void iio_device_unregister_debugfs(struct iio_dev *indio_dev) {}
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/iio/iio_core.h:29:13: warning: 'iio_device_register_debugfs' defined but not used [-Wunused-function]
29 | static void iio_device_register_debugfs(struct iio_dev *indio_dev) {}
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~vim +/iio_device_unregister_debugfs +30 drivers/iio/iio_core.h
28
> 29 static void iio_device_register_debugfs(struct iio_dev *indio_dev) {}
> 30 static void iio_device_unregister_debugfs(struct iio_dev *indio_dev) {}
31 #endif /* CONFIG_DEBUG_FS */
32 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki