Skip to contentSkip to conversation

iio: imu: drop #ifdef around CONFIG_DEBUG_FS

PATCH Applied Nuno Sa 2 participants 6 messages Aug 9, 2024 – Aug 10, 2024

Subsystems (4)
lore
Share & tools
lore

Nuno Sa

author maintainer
#0 lore raw

cover iio: imu: drop #ifdef around CONFIG_DEBUG_FS

Hi,

Small series to make the IMUs debugfs code a bit neater. As mentioned in the commit message, let's allow the compiler to drop any unused instead of guarding it with #ifdefs.

---
Nuno Sa (4):
iio: imu: adis16475: drop ifdef around CONFIG_DEBUG_FS
iio: imu: adis16480: drop ifdef around CONFIG_DEBUG_FS
iio: imu: adis16400: drop ifdef around CONFIG_DEBUG_FS
iio: imu: adis16460: drop ifdef around CONFIG_DEBUG_FS

 drivers/iio/imu/adis16400.c | 18 ++++--------------
 drivers/iio/imu/adis16460.c | 18 ++++--------------
 drivers/iio/imu/adis16475.c |  9 +++------
 drivers/iio/imu/adis16480.c | 18 ++++--------------
 4 files changed, 15 insertions(+), 48 deletions(-)

---
base-commit: 7cad163c39cb642ed587d3eeb37a5637ee02740f
change-id: 20240809-dev-adis-debugfs-improv-e007579b5262 --

Thanks!
- Nuno Sá

author maintainer
#1 lore raw

PATCH 1/4 iio: imu: adis16475: drop ifdef around CONFIG_DEBUG_FS

Use IS_ENABLED(CONFIG_DEBUG_FS) to return early in case debugfs is not present. Since this is known at compile time, it allows the compiler to drop any unused code. Therefore no need to wrap the code with #ifdef.

---
 drivers/iio/imu/adis16475.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/iio/imu/adis16475.c +3 -6
index c094ae4ffcb2..88efe728b61b 100644
@@ -164,7 +164,6 @@ module_param(low_rate_allow, bool, 0444);
 MODULE_PARM_DESC(low_rate_allow,
 		 "Allow IMU rates below the minimum advisable when external clk is used in SCALED mode (default: N)");
 
-#ifdef CONFIG_DEBUG_FS
 static ssize_t adis16475_show_firmware_revision(struct file *file,
 						char __user *userbuf,
 						size_t count, loff_t *ppos)
@@ -279,6 +278,9 @@ static void adis16475_debugfs_init(struct iio_dev *indio_dev)
 	struct adis16475 *st = iio_priv(indio_dev);
 	struct dentry *d = iio_get_debugfs_dentry(indio_dev);
 
+	if (!IS_ENABLED(CONFIG_DEBUG_FS))
+		return;
+
 	debugfs_create_file_unsafe("serial_number", 0400,
 				   d, st, &adis16475_serial_number_fops);
 	debugfs_create_file_unsafe("product_id", 0400,
@@ -290,11 +292,6 @@ static void adis16475_debugfs_init(struct iio_dev *indio_dev)
 	debugfs_create_file("firmware_date", 0400, d,
 			    st, &adis16475_firmware_date_fops);
 }
-#else
-static void adis16475_debugfs_init(struct iio_dev *indio_dev)
-{
-}
-#endif
 
 static int adis16475_get_freq(struct adis16475 *st, u32 *freq)
 {
Signature · 1 line
2.45.2
author maintainer
#2 lore raw

PATCH 2/4 iio: imu: adis16480: drop ifdef around CONFIG_DEBUG_FS

In reply to Nuno Sa

Use IS_ENABLED(CONFIG_DEBUG_FS) to return in case debugfs is not present. Since this is known at compile time, it allows the compiler to drop any unused code. Therefore no need to wrap the code with #ifdef.

While at it make adis16480_debugfs_init() void as the return code is ignored.

---
 drivers/iio/imu/adis16480.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/iio/imu/adis16480.c +4 -14
index 4e31503d512e..294181f2fcb3 100644
@@ -193,8 +193,6 @@ module_param(low_rate_allow, bool, 0444);
 MODULE_PARM_DESC(low_rate_allow,
 		 "Allow IMU rates below the minimum advisable when external clk is used in PPS mode (default: N)");
 
-#ifdef CONFIG_DEBUG_FS
-
 static ssize_t adis16480_show_firmware_revision(struct file *file,
 		char __user *userbuf, size_t count, loff_t *ppos)
 {
@@ -304,11 +302,14 @@ static int adis16480_show_flash_count(void *arg, u64 *val)
 DEFINE_DEBUGFS_ATTRIBUTE(adis16480_flash_count_fops,
 	adis16480_show_flash_count, NULL, "%lld\n");
 
-static int adis16480_debugfs_init(struct iio_dev *indio_dev)
+static void adis16480_debugfs_init(struct iio_dev *indio_dev)
 {
 	struct adis16480 *adis16480 = iio_priv(indio_dev);
 	struct dentry *d = iio_get_debugfs_dentry(indio_dev);
 
+	if (!IS_ENABLED(CONFIG_DEBUG_FS))
+		return;
+
 	debugfs_create_file_unsafe("firmware_revision", 0400,
 		d, adis16480, &adis16480_firmware_revision_fops);
 	debugfs_create_file_unsafe("firmware_date", 0400,
@@ -319,19 +320,8 @@ static int adis16480_debugfs_init(struct iio_dev *indio_dev)
 		d, adis16480, &adis16480_product_id_fops);
 	debugfs_create_file_unsafe("flash_count", 0400,
 		d, adis16480, &adis16480_flash_count_fops);
-
-	return 0;
 }
 
-#else
-
-static int adis16480_debugfs_init(struct iio_dev *indio_dev)
-{
-	return 0;
-}
-
-#endif
-
 static int adis16480_set_freq(struct iio_dev *indio_dev, int val, int val2)
 {
 	struct adis16480 *st = iio_priv(indio_dev);
Signature · 1 line
2.45.2
author maintainer
#3 lore raw

PATCH 3/4 iio: imu: adis16400: drop ifdef around CONFIG_DEBUG_FS

In reply to Nuno Sa

Use IS_ENABLED(CONFIG_DEBUG_FS) to return in case debugfs is not present. Since this is known at compile time, it allows the compiler to drop any unused code. Therefore no need to wrap the code with #ifdef.

While at it make adis16400_debugfs_init() void as the return code is ignored.

---
 drivers/iio/imu/adis16400.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/iio/imu/adis16400.c +4 -14
index 0bfd6205f5f6..6484ab8aff55 100644
@@ -202,8 +202,6 @@ enum {
 	ADIS16400_SCAN_TIMESTAMP,
 };
 
-#ifdef CONFIG_DEBUG_FS
-
 static ssize_t adis16400_show_serial_number(struct file *file,
 		char __user *userbuf, size_t count, loff_t *ppos)
 {
@@ -273,11 +271,14 @@ static int adis16400_show_flash_count(void *arg, u64 *val)
 DEFINE_DEBUGFS_ATTRIBUTE(adis16400_flash_count_fops,
 	adis16400_show_flash_count, NULL, "%lld\n");
 
-static int adis16400_debugfs_init(struct iio_dev *indio_dev)
+static void adis16400_debugfs_init(struct iio_dev *indio_dev)
 {
 	struct adis16400_state *st = iio_priv(indio_dev);
 	struct dentry *d = iio_get_debugfs_dentry(indio_dev);
 
+	if (!IS_ENABLED(CONFIG_DEBUG_FS))
+		return;
+
 	if (st->variant->flags & ADIS16400_HAS_SERIAL_NUMBER)
 		debugfs_create_file_unsafe("serial_number", 0400,
 				d, st, &adis16400_serial_number_fops);
@@ -286,19 +287,8 @@ static int adis16400_debugfs_init(struct iio_dev *indio_dev)
 				d, st, &adis16400_product_id_fops);
 	debugfs_create_file_unsafe("flash_count", 0400,
 			d, st, &adis16400_flash_count_fops);
-
-	return 0;
 }
 
-#else
-
-static int adis16400_debugfs_init(struct iio_dev *indio_dev)
-{
-	return 0;
-}
-
-#endif
-
 enum adis16400_chip_variant {
 	ADIS16300,
 	ADIS16334,
Signature · 1 line
2.45.2
author maintainer
#4 lore raw

PATCH 4/4 iio: imu: adis16460: drop ifdef around CONFIG_DEBUG_FS

In reply to Nuno Sa

Use IS_ENABLED(CONFIG_DEBUG_FS) to return in case debugfs is not present. Since this is known at compile time, it allows the compiler to drop any unused code. Therefore no need to wrap the code with #ifdef.

While at it make adis16460_debugfs_init() void as the return code is ignored.

---
 drivers/iio/imu/adis16460.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/iio/imu/adis16460.c +4 -14
index 69facd72bd7d..eaa38dd6201f 100644
@@ -69,8 +69,6 @@ struct adis16460 {
 	struct adis adis;
 };
 
-#ifdef CONFIG_DEBUG_FS
-
 static int adis16460_show_serial_number(void *arg, u64 *val)
 {
 	struct adis16460 *adis16460 = arg;
@@ -125,30 +123,22 @@ static int adis16460_show_flash_count(void *arg, u64 *val)
 DEFINE_DEBUGFS_ATTRIBUTE(adis16460_flash_count_fops,
 		adis16460_show_flash_count, NULL, "%lld\n");
 
-static int adis16460_debugfs_init(struct iio_dev *indio_dev)
+static void adis16460_debugfs_init(struct iio_dev *indio_dev)
 {
 	struct adis16460 *adis16460 = iio_priv(indio_dev);
 	struct dentry *d = iio_get_debugfs_dentry(indio_dev);
 
+	if (!IS_ENABLED(CONFIG_DEBUG_FS))
+		return;
+
 	debugfs_create_file_unsafe("serial_number", 0400,
 			d, adis16460, &adis16460_serial_number_fops);
 	debugfs_create_file_unsafe("product_id", 0400,
 			d, adis16460, &adis16460_product_id_fops);
 	debugfs_create_file_unsafe("flash_count", 0400,
 			d, adis16460, &adis16460_flash_count_fops);
-
-	return 0;
 }
 
-#else
-
-static int adis16460_debugfs_init(struct iio_dev *indio_dev)
-{
-	return 0;
-}
-
-#endif
-
 static int adis16460_set_freq(struct iio_dev *indio_dev, int val, int val2)
 {
 	struct adis16460 *st = iio_priv(indio_dev);
Signature · 1 line
2.45.2
maintainer Applied
#5 lore raw
In reply to Nuno Sa
Quoted 5 lines · On Fri, 09 Aug 2024 11:17:05 +0200 Nuno Sa via B4 Relay…

Hi,

Small series to make the IMUs debugfs code a bit neater. As mentioned in the commit message, let's allow the compiler to drop any unused instead of guarding it with #ifdefs.

Applied.

Quoted 22 lines

---
Nuno Sa (4):
iio: imu: adis16475: drop ifdef around CONFIG_DEBUG_FS
iio: imu: adis16480: drop ifdef around CONFIG_DEBUG_FS
iio: imu: adis16400: drop ifdef around CONFIG_DEBUG_FS
iio: imu: adis16460: drop ifdef around CONFIG_DEBUG_FS

 drivers/iio/imu/adis16400.c | 18 ++++--------------
 drivers/iio/imu/adis16460.c | 18 ++++--------------
 drivers/iio/imu/adis16475.c |  9 +++------
 drivers/iio/imu/adis16480.c | 18 ++++--------------
 4 files changed, 15 insertions(+), 48 deletions(-)

---
base-commit: 7cad163c39cb642ed587d3eeb37a5637ee02740f
change-id: 20240809-dev-adis-debugfs-improv-e007579b5262 --

Thanks!
- Nuno Sá