iio: adc: Improve include relevance for some ADCs.
Subsystems (4)
Jonathan Cameron
maintainercover 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
Jonathan Cameron
maintainerPATCH 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
@@ -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
Re: [PATCH 01/11] iio: adc: ltc2471: Improve include relevance
Quoted 10 lines · Jonathan Cameron
Based on output of iwyu drop unused
iio/sysfs.hand replacekernel.hwith 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
Signed-off-by Jonathan Cameron <[email protected]>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
Jonathan Cameron
maintainerPATCH 2/11 iio: adc: ltc2309: Improve include relevance
In reply to Jonathan CameronFrom: 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
@@ -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
Re: [PATCH 02/11] iio: adc: ltc2309: Improve include relevance
Quoted 4 lines · Jonathan Cameron
Based on output of iwyu, drop
kernel.hin 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> // fori2c_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
Signed-off-by Jonathan Cameron <[email protected]>Cc Liam Beguin <[email protected]>---
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerPATCH 3/11 iio: adc: max1027: Reorder headers into alphabetical order
In reply to Jonathan CameronFrom: 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
@@ -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
Re: [PATCH 03/11] iio: adc: max1027: Reorder headers into alphabetical order
Quoted 2 lines · Jonathan Cameron
Only
delay.hwas out of place. Move that before adding missing headers highlighted by iwyu.
Hmm... What's the justification for kernel.h? might_*()?
Quoted 3 lines
Signed-off-by Jonathan Cameron <[email protected]>Cc Miquel Raynal <[email protected]>---
Cc to be located here...
Quoted 1 line
drivers/iio/adc/max1027.c | 2 +-
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerPATCH 4/11 iio: adc: max1027: Improve include relevance
In reply to Jonathan CameronFrom: 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
@@ -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
Re: [PATCH 04/11] iio: adc: max1027: Improve include relevance
Quoted 8 lines · Jonathan Cameron
Drop
kernel.hin favor of more specific headers and add includes that were previously relying on other headers including them.Whether to include
device.hor the relevant sub headers is non obvious. In this case, there is an access to struct device forspi->dev.driver->namewhich 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> // fordev_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.hdevice/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.hnot directly included as few drivers do this.
Yes, we assume that types guarantees stddef.h to be provided.
Quoted 3 lines
Signed-off-by Jonathan Cameron <[email protected]>Cc Miquel Raynal <[email protected]>---
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
Jonathan Cameron
maintainerRe: [PATCH 04/11] iio: adc: max1027: Improve include relevance
Quoted 17 lines · On Tue, 20 Jan 2026 09:56:59 +0200 Andy Shevchenko…
Quoted 14 lines · Jonathan Cameron
Drop
kernel.hin favor of more specific headers and add includes that were previously relying on other headers including them.Whether to include
device.hor the relevant sub headers is non obvious. In this case, there is an access to struct device forspi->dev.driver->namewhich 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> // fordev_err,dev_name,devm_kmal. ..Not good, we also should treat
device.has "include everything" and try to avoid that, above comment hints like
dev_printk.hdevice/devres.h
It's there forspi->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...
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> // fordev_err,dev_name,devm_kmal. ..Not good, we also should treat
device.has "include everything" and try to avoid that, above comment hints like
dev_printk.hdevice/devres.hIt's there for
spi->dev.driver->nameused 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
Re: [PATCH 04/11] iio: adc: max1027: Improve include relevance
In reply to Jonathan CameronQuoted 55 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Drop
kernel.hin favor of more specific headers and add includes that were previously relying on other headers including them.Whether to include
device.hor the relevant sub headers is non obvious. In this case, there is an access to struct device forspi->dev.driver->namewhich is used to name the irq.The justification from iwyu for the additional includes is:
#include <asm/byteorder.h> // forbe16_to_cpu#include <linux/array_size.h> // forARRAY_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> // fordev_err,dev_name,devm_kmal. .. #include <linux/errno.h> // for ENOMEM, EINVAL, EBUSY, ETIME... #include <linux/interrupt.h> // fordevm_request_irq, irqreturn #include <linux/jiffies.h> // formsecs_to_jiffies#include <linux/minmax.h> // for__cmp_op_max#include <linux/mutex.h> // forclass_mutex_constructor, cla... #include <linux/stddef.h> // for NULL, false #include <linux/types.h> // for u8, bool,__be16
stddef.hnot directly included as few drivers do this.Signed-off-by Jonathan Cameron <[email protected]>Cc Miquel Raynal <[email protected]>---
drivers/iio/adc/max1027.c | 16 +++++++++++++++-1 file changed, 15 insertions(+), 1 deletion(-)drivers/iio/adc/max1027.c +0
-0@@ -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)
#defineMAX1027_SETUP_REGBIT(6)
#define MAX1027_AVG_REG BIT(5)
Jonathan Cameron
maintainerPATCH 5/11 iio: adc: max11100: Improve include relevance
In reply to Jonathan CameronFrom: 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
@@ -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
Jonathan Cameron
maintainerPATCH 6/11 iio: adc: max11410: Improve relevance of includes
In reply to Jonathan CameronFrom: 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
@@ -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
Jonathan Cameron
maintainerPATCH 7/11 iio: adc: ad4130: Improve include relevance
In reply to Jonathan CameronFrom: 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
@@ -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
Jonathan Cameron
maintainerPATCH 8/11 iio: adc: ad7124: Improve include relevance
In reply to Jonathan CameronFrom: 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
@@ -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
Jonathan Cameron
maintainerPATCH 9/11 iio: adc: ad7124: Replace device.h with more specific includes
In reply to Jonathan CameronFrom: 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
@@ -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
Jonathan Cameron
maintainerPATCH 10/11 iio: adc: ad7192: Put headers in alphabetical order
In reply to Jonathan CameronFrom: 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.
--- drivers/iio/adc/ad7192.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/iio/adc/ad7192.c +9 -9
@@ -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
Jonathan Cameron
maintainerPATCH 11/11 iio: adc: ad7192: Improve include relevance
In reply to Jonathan CameronFrom: 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
--- drivers/iio/adc/ad7192.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/iio/adc/ad7192.c +13 -7
@@ -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
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.hwas 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.hfor 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
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.hwas 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.hfor 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: Replacedevice.hwith 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