Skip to contentSkip to conversation

iio: adc: Improve include relevance for some ADCs.

PATCH In review Jonathan Cameron 3 participants 21 messages Jan 19 – Jan 21

Subsystems (4)
lore
Share & tools
lore

Jonathan Cameron

author maintainer
#0 lore raw

cover iio: adc: Improve include relevance for some ADCs.

From: Jonathan Cameron <[email protected]>

So this is a continuation of experimenting with IWYU to ensure that we follow what I consider best practice in driver by including all headers that are used (subject to some slightly fuzzy rules for some of them standard kernel headers).

I was focusing on cases where kernel.h was included and moving from that to the more specific headers. That partly explains why there were so many headers to add. However, it is also clear that many standard headers (mutex.h for example) were missing from these drivers.

There are a few notes and questions in the individual patch descriptions, typically where I have either decided to ignore a recommendation or conversely have broken things down more finely than IWYU was doing with my config files.

All comments welcome. Whilst I don't consider this particular high priority (much of it was done in a train where I couldn't access my email)m I would like to provide more examples in tree of what I consider to the right way to do things!

Thanks,

Jonathan

Jonathan Cameron (11):
iio: adc: ltc2471: Improve include relevance
iio: adc: ltc2309: Improve include relevance
iio: adc: max1027: Reorder headers into alphabetical order
iio: adc: max1027: Improve include relevance
iio: adc: max11100: Improve include relevance
iio: adc: max11410: Improve relevance of includes
iio: adc: ad4130: Improve include relevance
iio: adc: ad7124: Improve include relevance
iio: adc: ad7124: Replace device.h with more specific includes
iio: adc: ad7192: Put headers in alphabetical order
iio: adc: ad7192: Improve include relevance

 drivers/iio/adc/ad4130.c   | 22 ++++++++++++++++++----
 drivers/iio/adc/ad7124.c   | 17 +++++++++++++----
 drivers/iio/adc/ad7192.c   | 32 +++++++++++++++++++-------------
 drivers/iio/adc/ltc2309.c  |  9 ++++++++-
 drivers/iio/adc/ltc2471.c  |  8 ++++++--
 drivers/iio/adc/max1027.c  | 18 ++++++++++++++++--
 drivers/iio/adc/max11100.c | 11 ++++++++---
 drivers/iio/adc/max11410.c | 22 ++++++++++++++++++++--
 8 files changed, 108 insertions(+), 31 deletions(-)
Signature · 1 line
2.52.0
author maintainer
#1 lore raw

PATCH 1/11 iio: adc: ltc2471: Improve include relevance

From: Jonathan Cameron <[email protected]>

Based on output of iwyu drop unused iio/sysfs.h and replace kernel.h with more appropriate includes. Add some other includes that were relying on being indirectly included from other headers.

Justification for added includes:

  #include <asm/byteorder.h>          // for be16_to_cpu
  #include <linux/bits.h>             // for BIT
  #include <linux/dev_printk.h>       // for dev_err
  #include <linux/mod_devicetable.h>  // for i2c_device_id
  #include <linux/types.h>            // for __be16
---
 drivers/iio/adc/ltc2471.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/iio/adc/ltc2471.c +6 -2
index a579107fd5c9..d0ba1b3a6ca1 100644
@@ -7,12 +7,16 @@
  * Author: Mike Looijmans <[email protected]>
  */
 
+#include <linux/bits.h>
+#include <linux/dev_printk.h>
 #include <linux/err.h>
 #include <linux/i2c.h>
-#include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/types.h>
 #include <linux/iio/iio.h>
-#include <linux/iio/sysfs.h>
+
+#include <asm/byteorder.h>
 
 enum ltc2471_chips {
 	ltc2471,
Signature · 1 line
2.52.0
author maintainer
#3 lore raw

PATCH 2/11 iio: adc: ltc2309: Improve include relevance

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Based on output of iwyu, drop kernel.h in favor of more specific includes
+ add some others that are only indirectly included from other headers.

Justification for additions:

  #include <asm/byteorder.h>         // for be16_to_cpu
  #include <linux/array_size.h>      // for ARRAY_SIZE
  #include <linux/bits.h>            // for BIT, GENMASK
  #include <linux/dev_printk.h>      // for dev_err, dev_err_probe
  #include <linux/err.h>             // for ERR_PTR, EINVAL, ENODEV, ENOMEM

#include <linux/mod_devicetable.h> // for i2c_device_id, of_device_id
#include <linux/types.h> // for __be16, u8

---
 drivers/iio/adc/ltc2309.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/iio/adc/ltc2309.c +8 -1
index 5f0d947d0615..2838e0a9858c 100644
@@ -7,13 +7,20 @@
  *
  * Copyright (c) 2023, Liam Beguin <[email protected]>
  */
+#include <linux/array_size.h>
+#include <linux/bits.h>
 #include <linux/bitfield.h>
+#include <linux/dev_printk.h>
+#include <linux/err.h>
 #include <linux/i2c.h>
 #include <linux/iio/iio.h>
-#include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
 #include <linux/mutex.h>
 #include <linux/regulator/consumer.h>
+#include <linux/types.h>
+
+#include <asm/byteorder.h>
 
 #define LTC2309_ADC_RESOLUTION	12
 #define LTC2309_INTERNAL_REF_MV 4096
Signature · 1 line
2.52.0
author maintainer
#5 lore raw

PATCH 3/11 iio: adc: max1027: Reorder headers into alphabetical order

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Only delay.h was out of place. Move that before adding missing headers highlighted by iwyu.

---
 drivers/iio/adc/max1027.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/max1027.c +1 -1
index 7e736e77d8bb..913665b52cea 100644
@@ -12,11 +12,11 @@
   * Partial support for max1027 and similar chips.
   */
 
+#include <linux/delay.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/mod_devicetable.h>
 #include <linux/spi/spi.h>
-#include <linux/delay.h>
 
 #include <linux/iio/iio.h>
 #include <linux/iio/buffer.h>
Signature · 1 line
2.52.0
author maintainer
#7 lore raw

PATCH 4/11 iio: adc: max1027: Improve include relevance

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Drop kernel.h in favor of more specific headers and add includes that were previously relying on other headers including them.

Whether to include device.h or the relevant sub headers is non obvious. In this case, there is an access to struct device for spi->dev.driver->name which is used to name the irq.

The justification from iwyu for the additional includes is:

  #include <asm/byteorder.h>           // for be16_to_cpu
  #include <linux/array_size.h>        // for ARRAY_SIZE
  #include <linux/bitops.h>            // for BIT, GENMASK, fls, hweight32
  #include <linux/cleanup.h>           // for guard
  #include <linux/compiler.h>          // for __aligned
  #include <linux/completion.h>        // for complete, init_completion
  #include <linux/device.h>            // for dev_err, dev_name, devm_kmal. ..
  #include <linux/errno.h>             // for ENOMEM, EINVAL, EBUSY, ETIME...
  #include <linux/interrupt.h>         // for devm_request_irq, irqreturn
  #include <linux/jiffies.h>           // for msecs_to_jiffies
  #include <linux/minmax.h>            // for __cmp_op_max
  #include <linux/mutex.h>             // for class_mutex_constructor, cla...
  #include <linux/stddef.h>            // for NULL, false
  #include <linux/types.h>             // for u8, bool, __be16

stddef.h not directly included as few drivers do this.

---
 drivers/iio/adc/max1027.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/iio/adc/max1027.c +15 -1
index 913665b52cea..22d90efc9ab6 100644
@@ -12,11 +12,23 @@
   * Partial support for max1027 and similar chips.
   */
 
+#include <linux/array_size.h>
+#include <linux/bitops.h>
+#include <linux/cleanup.h>
+#include <linux/compiler.h>
+#include <linux/completion.h>
 #include <linux/delay.h>
-#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/errno.h>
+#include <linux/interrupt.h>
+#include <linux/jiffies.h>
+#include <linux/minmax.h>
 #include <linux/module.h>
 #include <linux/mod_devicetable.h>
+#include <linux/mutex.h>
+#include <linux/printk.h>
 #include <linux/spi/spi.h>
+#include <linux/types.h>
 
 #include <linux/iio/iio.h>
 #include <linux/iio/buffer.h>
@@ -24,6 +36,8 @@
 #include <linux/iio/trigger_consumer.h>
 #include <linux/iio/triggered_buffer.h>
 
+#include <asm/byteorder.h>
+
 #define MAX1027_CONV_REG  BIT(7)
 #define MAX1027_SETUP_REG BIT(6)
 #define MAX1027_AVG_REG   BIT(5)
Signature · 1 line
2.52.0
author maintainer
#12 lore raw

PATCH 5/11 iio: adc: max11100: Improve include relevance

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Using the iwyu tool to help, drop kernel.h in favor of more specific headers.
Also drop a delay.h and iio/driver.h as neither was used. Add other headers that were relying on indirect includes.

Justification for additions:

  #include <linux/array_size.h>      // for ARRAY_SIZE
  #include <linux/bits.h>            // for BIT
  #include <linux/compiler.h>        // for __aligned
  #include <linux/dev_printk.h>      // for dev_err
  #include <linux/device/devres.h>   // for devm_add_action_or_reset
  #include <linux/err.h>             // for EINVAL, IS_ERR, PTR_ERR, ENOMEM
  #include <linux/minmax.h>          // for __cmp_op_max
  #include <linux/types.h>           // for u8
---
 drivers/iio/adc/max11100.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/iio/adc/max11100.c +8 -3
index 520e37f75aac..f5adf7dba700 100644
@@ -6,16 +6,21 @@
  * Copyright (C) 2016-17 Renesas Electronics Corporation
  * Copyright (C) 2016-17 Jacopo Mondi
  */
-#include <linux/delay.h>
-#include <linux/kernel.h>
+#include <linux/array_size.h>
+#include <linux/bits.h>
+#include <linux/compiler.h>
+#include <linux/dev_printk.h>
+#include <linux/device/devres.h>
+#include <linux/err.h>
+#include <linux/minmax.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/regulator/consumer.h>
 #include <linux/spi/spi.h>
+#include <linux/types.h>
 #include <linux/unaligned.h>
 
 #include <linux/iio/iio.h>
-#include <linux/iio/driver.h>
 
 /*
  * LSB is the ADC single digital step
Signature · 1 line
2.52.0
author maintainer
#13 lore raw

PATCH 6/11 iio: adc: max11410: Improve relevance of includes

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Drop kernel.h in favor of more specific headers and add other headers that were previously only indirectly included. Also add a forwards definition of struct regulator as it is only used as an opaque pointer type in this file.

Justification for new headers from iwyu:

  #include <linux/array_size.h>        // for ARRAY_SIZE
  #include <linux/bitops.h>            // for BIT, GENMASK, __clear_bit
  #include <linux/cleanup.h>           // for guard
  #include <linux/compiler.h>          // for __aligned
  #include <linux/completion.h>        // for complete, init_completion
  #include <linux/iio/iio.h>           // for iio_chan_spec, iio_chan_info...
  #include <linux/iopoll.h>            // for read_poll_timeout
  #include <linux/jiffies.h>           // for msecs_to_jiffies
  #include <linux/kstrtox.h>           // for kstrtobool
  #include <linux/log2.h>              // for order_base_2
  #include <linux/math.h>              // for DIV_ROUND_CLOSEST
  #include <linux/minmax.h>            // for clamp_val, __cmp_op_max
  #include <linux/mod_devicetable.h>   // for of_device_id, spi_device_id
  #include <linux/mutex.h>             // for class_mutex_constructor, mut...
  #include <linux/property.h>          // for fwnode_property_read_u32
  #include <linux/stddef.h>            // for NULL, true
  #include <linux/sysfs.h>             // for sysfs_emit, attribute_group
  #include <linux/types.h>             // for u32, u8, bool, ssize_t, alig...

struct regulator;

---
 drivers/iio/adc/max11410.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
drivers/iio/adc/max11410.c +20 -2
index 511b2f14dfaf..c8a9718c4e4b 100644
@@ -4,20 +4,36 @@
  *
  * Copyright 2022 Analog Devices Inc.
  */
+#include <linux/array_size.h>
+#include <linux/bitops.h>
 #include <linux/bitfield.h>
+#include <linux/cleanup.h>
+#include <linux/compiler.h>
+#include <linux/completion.h>
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/err.h>
 #include <linux/interrupt.h>
-#include <linux/kernel.h>
+#include <linux/iopoll.h>
+#include <linux/jiffies.h>
+#include <linux/kstrtox.h>
+#include <linux/log2.h>
+#include <linux/math.h>
+#include <linux/minmax.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/mutex.h>
+#include <linux/property.h>
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
 #include <linux/spi/spi.h>
-
+#include <linux/stddef.h>
+#include <linux/sysfs.h>
+#include <linux/types.h>
 #include <linux/unaligned.h>
 
 #include <linux/iio/buffer.h>
+#include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
 #include <linux/iio/trigger.h>
 #include <linux/iio/trigger_consumer.h>
@@ -130,6 +146,8 @@ struct max11410_channel_config {
 	bool buffered_vrefn;
 };
 
+struct regulator;
+
 struct max11410_state {
 	struct spi_device *spi_dev;
 	struct iio_trigger *trig;
Signature · 1 line
2.52.0
author maintainer
#14 lore raw

PATCH 7/11 iio: adc: ad4130: Improve include relevance

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Replace asm/div64.h with linux/math64.h and drop kernel.h in favor of more specific includes. Also add some others that should be directly included to follow approximate include what you use.

Justification for new headers from iwyu with a couple of comments where this deviates from recommendations.

  #include <linux/array_size.h>      // for ARRAY_SIZE
  #include <linux/bitmap.h>          // for for_each_set_bit
  #include <linux/build_bug.h>       // for static_assert
  #include <linux/compiler.h>        // for __aligned
  #include <linux/completion.h>      // for complete, init_completion, rei...
  #include <linux/container_of.h>    // for container_of

#include <linux/init.h> // for THIS_MODULE
Ignored this one as seems reasonable to assume module.h will always include whereever that is!

  #include <linux/jiffies.h>         // for msecs_to_jiffies
  #include <linux/math.h>            // for rounddown
  #include <linux/math64.h>          // for div_u64, div_u64_rem, DIV64_U6...
  #include <linux/minmax.h>          // for __cmp_op_max
  #include <linux/mod_devicetable.h> // for of_device_id
  #include <linux/mutex.h>           // for class_mutex_constructor, class...
  #include <linux/of.h>              // for of_property_read_string, devic...
  #include <linux/stddef.h>          // for false, true, NULL
  #include <linux/string.h>          // for memcpy, memset
  #include <linux/stringify.h>       // for __stringify
  #include <linux/sysfs.h>           // for sysfs_emit
  #include <linux/types.h>           // for u32, bool, u64, u8, ssize_t

struct fwnode_handle;
Ignored this last recomendation because I think property.h can reasonably be expected to always include whereever this is.

---
 drivers/iio/adc/ad4130.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/iio/adc/ad4130.c +18 -4
index 5567ae5dee88..745efefb7f35 100644
@@ -4,8 +4,14 @@
  * Author: Cosmin Tanislav <[email protected]>
  */
 
+#include <linux/array_size.h>
+#include <linux/bitmap.h>
 #include <linux/bitfield.h>
 #include <linux/bitops.h>
+#include <linux/build_bug.h>
+#include <linux/compiler.h>
+#include <linux/completion.h>
+#include <linux/container_of.h>
 #include <linux/cleanup.h>
 #include <linux/clk.h>
 #include <linux/clk-provider.h>
@@ -15,16 +21,24 @@
 #include <linux/gpio/driver.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
-#include <linux/kernel.h>
+#include <linux/jiffies.h>
+#include <linux/math.h>
+#include <linux/math64.h>
+#include <linux/minmax.h>
+#include <linux/mod_devicetable.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
 #include <linux/property.h>
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
 #include <linux/spi/spi.h>
-#include <linux/units.h>
-
-#include <asm/div64.h>
+#include <linux/stddef.h>
+#include <linux/stringify.h>
+#include <linux/sysfs.h>
+#include <linux/types.h>
 #include <linux/unaligned.h>
+#include <linux/units.h>
 
 #include <linux/iio/buffer.h>
 #include <linux/iio/iio.h>
Signature · 1 line
2.52.0
author maintainer
#15 lore raw

PATCH 8/11 iio: adc: ad7124: Improve include relevance

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Drop unused linux/kfifo.h and linux/iio/sysfs.h.
Replace kernel.h with more specific headers and add other missing headers that should be directly included to follow approximate include what you use principles.

Justification for new headers from iwyu:

  #include <linux/array_size.h>          // for ARRAY_SIZE
  #include <linux/container_of.h>        // for container_of
  #include <linux/kstrtox.h>             // for kstrtobool
  #include <linux/limits.h>              // for U32_MAX
  #include <linux/math.h>                // for DIV_ROUND_CLOSEST, abs
  #include <linux/mutex.h>               // for class_mutex_constructor
  #include <linux/slab.h>                // for __free_kfree
  #include <linux/stddef.h>              // for true, NULL, false, struct_...
  #include <linux/types.h>               // for bool, u32, u8, size_t, ssi...
---
 drivers/iio/adc/ad7124.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/iio/adc/ad7124.c +9 -3
index 5c1a8f886bcc..5d3be891fa7e 100644
@@ -5,30 +5,36 @@
  * Copyright 2018 Analog Devices Inc.
  * Copyright 2025 BayLibre, SAS
  */
+#include <linux/array_size.h>
 #include <linux/bitfield.h>
 #include <linux/bitops.h>
 #include <linux/cleanup.h>
 #include <linux/clk.h>
 #include <linux/clk-provider.h>
+#include <linux/container_of.h>
 #include <linux/debugfs.h>
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/err.h>
 #include <linux/interrupt.h>
-#include <linux/kernel.h>
-#include <linux/kfifo.h>
+#include <linux/kstrtox.h>
+#include <linux/limits.h>
+#include <linux/math.h>
 #include <linux/minmax.h>
 #include <linux/module.h>
 #include <linux/mod_devicetable.h>
+#include <linux/mutex.h>
 #include <linux/property.h>
 #include <linux/regulator/consumer.h>
+#include <linux/slab.h>
 #include <linux/spi/spi.h>
 #include <linux/sprintf.h>
+#include <linux/stddef.h>
+#include <linux/types.h>
 #include <linux/units.h>
 
 #include <linux/iio/iio.h>
 #include <linux/iio/adc/ad_sigma_delta.h>
-#include <linux/iio/sysfs.h>
 
 /* AD7124 registers */
 #define AD7124_COMMS			0x00
Signature · 1 line
2.52.0
author maintainer
#16 lore raw

PATCH 9/11 iio: adc: ad7124: Replace device.h with more specific includes

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Separate patch to make this change more obvious.
This driver makes no direct use of anything in device.h but uses both include/linux/device/devres.h and include/linux/dev_printk.h as well as needing a forwards def for struct device.
So replace device.h with those headers and the struct device forwards definition.

---
I'm still tweaking my iwyu config, so currently it doesn't suggest this one automatically. I'm interested to hear opinions on whether it is a good way to go or not!

---
 drivers/iio/adc/ad7124.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/iio/adc/ad7124.c +4 -1
index 5d3be891fa7e..84da872fab6f 100644
@@ -14,7 +14,8 @@
 #include <linux/container_of.h>
 #include <linux/debugfs.h>
 #include <linux/delay.h>
-#include <linux/device.h>
+#include <linux/dev_printk.h>
+#include <linux/device/devres.h>
 #include <linux/err.h>
 #include <linux/interrupt.h>
 #include <linux/kstrtox.h>
@@ -36,6 +37,8 @@
 #include <linux/iio/iio.h>
 #include <linux/iio/adc/ad_sigma_delta.h>
 
+struct device;
+
 /* AD7124 registers */
 #define AD7124_COMMS			0x00
 #define AD7124_STATUS			0x00
Signature · 1 line
2.52.0
author maintainer
#17 lore raw

PATCH 10/11 iio: adc: ad7192: Put headers in alphabetical order

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Precusor to cleaning them up that makes it easier to see what is being done. Leave the iio/ ones alone as many of those will be dropped.

Cc Alisa-Dariana Roman <[email protected]>
---
 drivers/iio/adc/ad7192.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/iio/adc/ad7192.c +9 -9
index 530e1d307860..6b48581d7606 100644
@@ -5,23 +5,23 @@
  * Copyright 2011-2015 Analog Devices Inc.
  */
 
-#include <linux/interrupt.h>
 #include <linux/bitfield.h>
 #include <linux/cleanup.h>
 #include <linux/clk.h>
 #include <linux/clk-provider.h>
+#include <linux/delay.h>
 #include <linux/device.h>
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/sysfs.h>
-#include <linux/spi/spi.h>
-#include <linux/regulator/consumer.h>
 #include <linux/err.h>
-#include <linux/sched.h>
-#include <linux/delay.h>
-#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
 #include <linux/mod_devicetable.h>
+#include <linux/module.h>
 #include <linux/property.h>
+#include <linux/regulator/consumer.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+#include <linux/spi/spi.h>
+#include <linux/sysfs.h>
 #include <linux/units.h>
 
 #include <linux/iio/iio.h>
Signature · 1 line
2.52.0
author maintainer
#18 lore raw

PATCH 11/11 iio: adc: ad7192: Improve include relevance

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Drop unused:
#include <linux/iio/buffer.h> // lines 29-29 #include <linux/iio/trigger.h> // lines 30-30 #include <linux/iio/trigger_consumer.h> // lines 31-31 #include <linux/iio/triggered_buffer.h> // lines 32-32 #include <linux/sched.h> // lines 20-20 #include <linux/slab.h> // lines 15-15

Replace kernel.h with more specific headers and add missing headers.

Justification from iwyu for added headers:

  #include <linux/array_size.h>          // for ARRAY_SIZE
  #include <linux/bitmap.h>              // for for_each_set_bit
  #include <linux/bits.h>                // for BIT, GENMASK
  #include <linux/compiler.h>            // for inline
  #include <linux/container_of.h>        // for container_of
  #include <linux/kstrtox.h>             // for kstrtobool
  #include <linux/limits.h>              // for U32_MAX
  #include <linux/math.h>                // for DIV_ROUND_CLOSEST, DIV_ROU...
  #include <linux/math64.h>              // for do_div
  #include <linux/minmax.h>              // for in_range
  #include <linux/mutex.h>               // for class_mutex_constructor
  #include <linux/stddef.h>              // for true, NULL, false
  #include <linux/types.h>               // for bool, u32, u8, ssize_t
Cc Alisa-Dariana Roman <[email protected]>
---
 drivers/iio/adc/ad7192.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/iio/adc/ad7192.c +13 -7
index 6b48581d7606..24e1fa796829 100644
@@ -5,31 +5,37 @@
  * Copyright 2011-2015 Analog Devices Inc.
  */
 
+#include <linux/array_size.h>
 #include <linux/bitfield.h>
+#include <linux/bitmap.h>
+#include <linux/bits.h>
 #include <linux/cleanup.h>
 #include <linux/clk.h>
 #include <linux/clk-provider.h>
+#include <linux/compiler.h>
+#include <linux/container_of.h>
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/err.h>
 #include <linux/interrupt.h>
-#include <linux/kernel.h>
+#include <linux/kstrtox.h>
+#include <linux/limits.h>
+#include <linux/math.h>
+#include <linux/math64.h>
+#include <linux/minmax.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/property.h>
 #include <linux/regulator/consumer.h>
-#include <linux/sched.h>
-#include <linux/slab.h>
 #include <linux/spi/spi.h>
 #include <linux/sysfs.h>
+#include <linux/stddef.h>
+#include <linux/types.h>
 #include <linux/units.h>
 
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
-#include <linux/iio/buffer.h>
-#include <linux/iio/trigger.h>
-#include <linux/iio/trigger_consumer.h>
-#include <linux/iio/triggered_buffer.h>
 #include <linux/iio/adc/ad_sigma_delta.h>
 
 /* Registers */
Signature · 1 line
2.52.0
Reviewed-by on v1 1/11
#2 lore raw

Re: [PATCH 01/11] iio: adc: ltc2471: Improve include relevance

In reply to Jonathan Cameron
Quoted 10 lines · Jonathan Cameron

Based on output of iwyu drop unused iio/sysfs.h and replace kernel.h with more appropriate includes. Add some other includes that were relying on being indirectly included from other headers.

Justification for added includes:

  #include <asm/byteorder.h>          // for be16_to_cpu
  #include <linux/bits.h>             // for BIT
  #include <linux/dev_printk.h>       // for dev_err
  #include <linux/mod_devicetable.h>  // for i2c_device_id
  #include <linux/types.h>            // for __be16

with below comments to be considered.

Quoted 3 lines
Cc Mike Looijmans <[email protected]>

Move Cc below '---'

drivers/iio/adc/ltc2471.c line 16

Quoted 12 lines
---
 drivers/iio/adc/ltc2471.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/iio/adc/ltc2471.c +4 -1
+#include <linux/bits.h>
+#include <linux/dev_printk.h>
 #include <linux/err.h>
 #include <linux/i2c.h>
-#include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/types.h>

+ blank line here, otherwise it might be recognised as unordered piece.

Quoted 2 lines

#include <linux/iio/iio.h>
-#include <linux/iio/sysfs.h>

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

Re: [PATCH 02/11] iio: adc: ltc2309: Improve include relevance

In reply to Jonathan Cameron
Quoted 4 lines · Jonathan Cameron

Based on output of iwyu, drop kernel.h in favor of more specific includes
+ add some others that are only indirectly included from other headers.

Quoted 8 lines

Justification for additions:

  #include <asm/byteorder.h>         // for be16_to_cpu
  #include <linux/array_size.h>      // for ARRAY_SIZE
  #include <linux/bits.h>            // for BIT, GENMASK
  #include <linux/dev_printk.h>      // for dev_err, dev_err_probe
  #include <linux/err.h>             // for ERR_PTR, EINVAL, ENODEV, ENOMEM

#include <linux/mod_devicetable.h> // for i2c_device_id, of_device_id
#include <linux/types.h> // for __be16, u8

Similar comments and one Q here. Should we establish IIO header grouping in all (touched) drivers? If so, move it outside of linux/*.

Quoted 3 lines

---

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw

Re: [PATCH 03/11] iio: adc: max1027: Reorder headers into alphabetical order

In reply to Jonathan Cameron
Quoted 2 lines · Jonathan Cameron

Only delay.h was out of place. Move that before adding missing headers highlighted by iwyu.

Hmm... What's the justification for kernel.h? might_*()?

Quoted 3 lines

---

Cc to be located here...

Quoted 1 line
 drivers/iio/adc/max1027.c | 2 +-
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw

Re: [PATCH 04/11] iio: adc: max1027: Improve include relevance

In reply to Jonathan Cameron
Quoted 8 lines · Jonathan Cameron

Drop kernel.h in favor of more specific headers and add includes that were previously relying on other headers including them.

Whether to include device.h or the relevant sub headers is non obvious. In this case, there is an access to struct device for spi->dev.driver->name which is used to name the irq.

The justification from iwyu for the additional includes is:

Quoted 8 lines
  #include <asm/byteorder.h>           // for be16_to_cpu
  #include <linux/array_size.h>        // for ARRAY_SIZE
  #include <linux/bitops.h>            // for BIT, GENMASK, fls, hweight32
  #include <linux/cleanup.h>           // for guard
  #include <linux/compiler.h>          // for __aligned
  #include <linux/completion.h>        // for complete, init_completion

#include <linux/device.h> // for dev_err, dev_name, devm_kmal. ..

Not good, we also should treat device.h as "include everything" and try to avoid that, above comment hints like

dev_printk.h
device/devres.h

Quoted 9 lines
  #include <linux/errno.h>             // for ENOMEM, EINVAL, EBUSY, ETIME...
  #include <linux/interrupt.h>         // for devm_request_irq, irqreturn
  #include <linux/jiffies.h>           // for msecs_to_jiffies
  #include <linux/minmax.h>            // for __cmp_op_max
  #include <linux/mutex.h>             // for class_mutex_constructor, cla...
  #include <linux/stddef.h>            // for NULL, false
  #include <linux/types.h>             // for u8, bool, __be16

stddef.h not directly included as few drivers do this.

Yes, we assume that types guarantees stddef.h to be provided.

Quoted 3 lines

---

Cc here...

Quoted 2 lines
 drivers/iio/adc/max1027.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

...

drivers/iio/adc/max1027.c

Quoted 5 lines
drivers/iio/adc/max1027.c +4 -0
+#include <linux/array_size.h>
+#include <linux/bitops.h>
+#include <linux/cleanup.h>
 
+#include <linux/compiler.h>

Same as stddef. types.h will bring this.

drivers/iio/adc/max1027.c

Quoted 5 lines
drivers/iio/adc/max1027.c +2 -1
+#include <linux/completion.h>
 #include <linux/delay.h>
-#include <linux/kernel.h>
 
+#include <linux/device.h>

See above.

Quoted 10 lines
drivers/iio/adc/max1027.c +7 -0
+#include <linux/errno.h>
+#include <linux/interrupt.h>
+#include <linux/jiffies.h>
+#include <linux/minmax.h>
 #include <linux/module.h>
 #include <linux/mod_devicetable.h>
+#include <linux/mutex.h>
+#include <linux/printk.h>
 #include <linux/spi/spi.h>
+#include <linux/types.h>
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#19 lore raw
In reply to Jonathan Cameron
Quoted 10 lines · Jonathan Cameron

So this is a continuation of experimenting with IWYU to ensure that we follow what I consider best practice in driver by including all headers that are used (subject to some slightly fuzzy rules for some of them standard kernel headers).

I was focusing on cases where kernel.h was included and moving from that to the more specific headers. That partly explains why there were so many headers to add. However, it is also clear that many standard headers (mutex.h for example) were missing from these drivers.

Quoted 8 lines

There are a few notes and questions in the individual patch descriptions, typically where I have either decided to ignore a recommendation or conversely have broken things down more finely than IWYU was doing with my config files.

All comments welcome. Whilst I don't consider this particular high priority (much of it was done in a train where I couldn't access my email)m I would like to provide more examples in tree of what I consider

"m"? Bump on the rail that makes your finger slip over keyboard? :-)

Quoted 1 line

to the right way to do things!

I commented 4 patches, but seems the set of issues I found is repetitive, So, please address those in all patches and I will look into v2.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#9 lore raw

Re: [PATCH 04/11] iio: adc: max1027: Improve include relevance

In reply to Andy Shevchenko
Quoted 17 lines · On Tue, 20 Jan 2026 09:56:59 +0200 Andy Shevchenko…
Quoted 14 lines · Jonathan Cameron

Drop kernel.h in favor of more specific headers and add includes that were previously relying on other headers including them.

Whether to include device.h or the relevant sub headers is non obvious. In this case, there is an access to struct device for spi->dev.driver->name which is used to name the irq.

The justification from iwyu for the additional includes is:

  #include <asm/byteorder.h>           // for be16_to_cpu
  #include <linux/array_size.h>        // for ARRAY_SIZE
  #include <linux/bitops.h>            // for BIT, GENMASK, fls, hweight32
  #include <linux/cleanup.h>           // for guard
  #include <linux/compiler.h>          // for __aligned
  #include <linux/completion.h>        // for complete, init_completion  
Quoted 7 lines
Quoted 1 line

#include <linux/device.h> // for dev_err, dev_name, devm_kmal. ..

Not good, we also should treat device.h as "include everything" and try to avoid that, above comment hints like

dev_printk.h
device/devres.h

It's there for
spi->dev.driver->name used for some reason as the irq name.

I considered fixing that but felt it was out of scope for this series. I'll add a comment as iwyu forgot to mention use of struct device ;)

Thanks,

Jonathan

Quoted 2 lines
Quoted 2 lines

#include <linux/errno.h> // for ENOMEM, EINVAL, EBUSY, ETIME...

#10 lore raw

Re: [PATCH 04/11] iio: adc: max1027: Improve include relevance

Quoted 3 lines · Jonathan Cameron
Quoted 1 line · On Tue, 20 Jan 2026 09:56:59 +0200 Andy Shevchenko…

On Mon, Jan 19, 2026 at 09:21:03PM +0000, Jonathan Cameron wrote:

...

Quoted 10 lines
Quoted 7 lines
Quoted 1 line

#include <linux/device.h> // for dev_err, dev_name, devm_kmal. ..

Not good, we also should treat device.h as "include everything" and try to avoid that, above comment hints like

dev_printk.h
device/devres.h

It's there for
spi->dev.driver->name used for some reason as the irq name.

Ah, I see...

Quoted 1 line

I considered fixing that but felt it was out of scope for this series.

Sure thing!

Quoted 1 line

I'll add a comment as iwyu forgot to mention use of struct device ;)

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#11 lore raw

Re: [PATCH 04/11] iio: adc: max1027: Improve include relevance

In reply to Jonathan Cameron
Quoted 55 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Drop kernel.h in favor of more specific headers and add includes that were previously relying on other headers including them.

Whether to include device.h or the relevant sub headers is non obvious. In this case, there is an access to struct device for spi->dev.driver->name which is used to name the irq.

The justification from iwyu for the additional includes is:
  #include <asm/byteorder.h>           // for be16_to_cpu #include <linux/array_size.h>        // for ARRAY_SIZE
  #include <linux/bitops.h>            // for BIT, GENMASK, fls, hweight32 #include <linux/cleanup.h>           // for guard
  #include <linux/compiler.h>          // for __aligned
  #include <linux/completion.h>        // for complete, init_completion #include <linux/device.h>            // for dev_err, dev_name, devm_kmal. .. #include <linux/errno.h>             // for ENOMEM, EINVAL, EBUSY, ETIME... #include <linux/interrupt.h>         // for devm_request_irq, irqreturn #include <linux/jiffies.h>           // for msecs_to_jiffies #include <linux/minmax.h>            // for __cmp_op_max #include <linux/mutex.h>             // for class_mutex_constructor, cla... #include <linux/stddef.h>            // for NULL, false #include <linux/types.h>             // for u8, bool, __be16

stddef.h not directly included as few drivers do this.

---
 drivers/iio/adc/max1027.c | 16 +++++++++++++++-

 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/iio/adc/max1027.c +0 -0
index 913665b52cea..22d90efc9ab6 100644
@@ -12,11 +12,23 @@
    * Partial support for max1027 and similar chips.
    */

drivers/iio/adc/max1027.c +5 -0
+#include <linux/array_size.h>
+#include <linux/bitops.h>
+#include <linux/cleanup.h>
+#include <linux/compiler.h>
+#include <linux/completion.h>

 #include <linux/delay.h>

drivers/iio/adc/max1027.c +5 -1
-#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/errno.h>
+#include <linux/interrupt.h>
+#include <linux/jiffies.h>
+#include <linux/minmax.h>

 #include <linux/module.h>
 #include <linux/mod_devicetable.h>

drivers/iio/adc/max1027.c line 29

Quoted 2 lines
drivers/iio/adc/max1027.c +2 -0
+#include <linux/mutex.h>
+#include <linux/printk.h>

To be consistent, the above should also be in the commit message.

- Nuno Sá

Quoted 14 lines

 #include <linux/spi/spi.h>
+#include <linux/types.h>

 #include <linux/iio/iio.h>
 #include <linux/iio/buffer.h>

drivers/iio/adc/max1027.c +0 -0
@@ -24,6 +36,8 @@
  #include <linux/iio/trigger_consumer.h>
  #include <linux/iio/triggered_buffer.h>

drivers/iio/adc/max1027.c +2 -0
+#include <asm/byteorder.h>
+

 #define MAX1027_CONV_REG  BIT(7)
 #define MAX1027_SETUP_REG BIT(6)
 #define MAX1027_AVG_REG   BIT(5)

Reviewed-by on the v1 series
#20 lore raw
In reply to Jonathan Cameron
Quoted 39 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

So this is a continuation of experimenting with IWYU to ensure that we follow what I consider best practice in driver by including all headers that are used (subject to some slightly fuzzy rules for some of them standard kernel headers).

I was focusing on cases where kernel.h was included and moving from that to the more specific headers. That partly explains why there were so many headers to add. However, it is also clear that many standard headers (mutex.h for example) were missing from these drivers.

There are a few notes and questions in the individual patch descriptions, typically where I have either decided to ignore a recommendation or conversely have broken things down more finely than IWYU was doing with my config files.

All comments welcome.  Whilst I don't consider this particular high priority (much of it was done in a train where I couldn't access my email)m I would like to provide more examples in tree of what I consider to the right way to do things!

Thanks,

Jonathan

Jonathan Cameron (11):
  iio: adc: ltc2471: Improve include relevance
  iio: adc: ltc2309: Improve include relevance
  iio: adc: max1027: Reorder headers into alphabetical order
  iio: adc: max1027: Improve include relevance
  iio: adc: max11100: Improve include relevance
  iio: adc: max11410: Improve relevance of includes
  iio: adc: ad4130: Improve include relevance
  iio: adc: ad7124: Improve include relevance
  iio: adc: ad7124: Replace device.h with more specific includes
  iio: adc: ad7192: Put headers in alphabetical order
  iio: adc: ad7192: Improve include relevance

Quoted 9 lines
 drivers/iio/adc/ad4130.c   | 22 ++++++++++++++++++----
 drivers/iio/adc/ad7124.c   | 17 +++++++++++++----
 drivers/iio/adc/ad7192.c   | 32 +++++++++++++++++++-------------
 drivers/iio/adc/ltc2309.c  |  9 ++++++++-
 drivers/iio/adc/ltc2471.c  |  8 ++++++--
 drivers/iio/adc/max1027.c  | 18 ++++++++++++++++--
 drivers/iio/adc/max11100.c | 11 ++++++++---
 drivers/iio/adc/max11410.c | 22 ++++++++++++++++++++--
 8 files changed, 108 insertions(+), 31 deletions(-)

Just one minor comment. LGTM