From: Rodrigo Alencar <rodrigo.alencar@analog.com>
Apply IWYU principle, removing the following headers:
- linux/device.h: no usage of devm_add_action_or_reset, device_attr...
- linux/kernel.h: no usage of container_of, kasprintf, ...
- linux/slab.h: memory management handled by iio
- linux/sysfs.h: sysfs interaction is managed by iio
- linux/iio/sysfs.h: not using iio device attributes in this driver
Being a small patch, the remaining includes are alphabetically sorted.
In gcc, compiling with -H allows for dependency visualization,
which indicates that except for linux/iio/sysfs.h, all removed
headers are indirectly included by the remaining headers.
Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
drivers/iio/amplifiers/ad8366.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c
index d06ac786501c..6382106ee6c7 100644
--- a/drivers/iio/amplifiers/ad8366.c
+++ b/drivers/iio/amplifiers/ad8366.c
@@ -11,19 +11,14 @@
* Copyright 2012-2019 Analog Devices Inc.
*/
-#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/gpio/consumer.h>
-#include <linux/err.h>
-#include <linux/module.h>
#include <linux/bitrev.h>
+#include <linux/err.h>
+#include <linux/gpio/consumer.h>
+#include <linux/module.h>
+#include <linux/regulator/consumer.h>
+#include <linux/spi/spi.h>
#include <linux/iio/iio.h>
-#include <linux/iio/sysfs.h>
enum ad8366_type {
ID_AD8366,
--
2.43.0
On Tue, Feb 10, 2026 at 07:42:03PM +0000, Rodrigo Alencar via B4 Relay wrote: > Apply IWYU principle, removing the following headers: > - linux/device.h: no usage of devm_add_action_or_reset, device_attr... > - linux/kernel.h: no usage of container_of, kasprintf, ... > - linux/slab.h: memory management handled by iio > - linux/sysfs.h: sysfs interaction is managed by iio > - linux/iio/sysfs.h: not using iio device attributes in this driver Yeah, but it also means to add (a lot of) missed headers... array_size,h dev_printk.h mod_devicetable.h mutex.h stddef.h (might be even more, this list was made just at the first glance). > Being a small patch, the remaining includes are alphabetically sorted. > In gcc, compiling with -H allows for dependency visualization, > which indicates that except for linux/iio/sysfs.h, all removed > headers are indirectly included by the remaining headers. -- With Best Regards, Andy Shevchenko
On 26/02/10 09:57PM, Andy Shevchenko wrote: > On Tue, Feb 10, 2026 at 07:42:03PM +0000, Rodrigo Alencar via B4 Relay wrote: > > > Apply IWYU principle, removing the following headers: > > - linux/device.h: no usage of devm_add_action_or_reset, device_attr... > > - linux/kernel.h: no usage of container_of, kasprintf, ... > > - linux/slab.h: memory management handled by iio > > - linux/sysfs.h: sysfs interaction is managed by iio > > - linux/iio/sysfs.h: not using iio device attributes in this driver > > Yeah, but it also means to add (a lot of) missed headers... > > array_size,h > dev_printk.h > mod_devicetable.h > mutex.h > stddef.h Are there proper guidelines for IWYU in the kernel? Include headers end up including a bunch of others, so the build finishes successfully anyways. I understand that the concern is build time, so we better include all small parts that are needed rather than a generic header that includes that and much more. This is the output of the iwyu tool without this patch series: drivers/iio/amplifiers/ad8366.c should add these lines: #include <stddef.h> // for NULL #include "asm-generic/errno-base.h" // for EINVAL, ENOMEM #include "linux/array_size.h" // for ARRAY_SIZE #include "linux/compiler_attributes.h" // for __aligned #include "linux/dev_printk.h" // for dev_err #include "linux/iio/types.h" // for iio_chan_info_enum, iio_chan_... #include "linux/math.h" // for abs #include "linux/minmax.h" // for __cmp_op_max #include "linux/mod_devicetable.h" // for spi_device_id #include "linux/mutex.h" // for mutex_lock, mutex_unlock, mut... #include "linux/mutex_types.h" // for mutex #include "vdso/bits.h" // for BIT drivers/iio/amplifiers/ad8366.c should remove these lines: - #include <linux/device.h> // lines 14-14 - #include <linux/iio/sysfs.h> // lines 26-26 - #include <linux/kernel.h> // lines 15-15 - #include <linux/slab.h> // lines 16-16 - #include <linux/sysfs.h> // lines 17-17 The full include-list for drivers/iio/amplifiers/ad8366.c: #include <linux/bitrev.h> // for bitrev8 #include <linux/err.h> // for IS_ERR, PTR_ERR #include <linux/gpio/consumer.h> // for devm_gpiod_get_optional, gpio... #include <linux/iio/iio.h> // for iio_priv, iio_dev, iio_chan_spec #include <linux/module.h> // for MODULE_AUTHOR, MODULE_DESCRIP... #include <linux/regulator/consumer.h> // for regulator_disable, devm_regul... #include <linux/spi/spi.h> // for spi_device, spi_get_device_id #include <stddef.h> // for NULL #include "asm-generic/errno-base.h" // for EINVAL, ENOMEM #include "linux/array_size.h" // for ARRAY_SIZE #include "linux/compiler_attributes.h" // for __aligned #include "linux/dev_printk.h" // for dev_err #include "linux/iio/types.h" // for iio_chan_info_enum, iio_chan_... #include "linux/math.h" // for abs #include "linux/minmax.h" // for __cmp_op_max #include "linux/mod_devicetable.h" // for spi_device_id #include "linux/mutex.h" // for mutex_lock, mutex_unlock, mut... #include "linux/mutex_types.h" // for mutex #include "vdso/bits.h" // for BIT After all the patches are applied the output is slightly different: drivers/iio/amplifiers/ad8366.c should add these lines: #include <stddef.h> // for size_t, NULL #include "asm-generic/errno-base.h" // for EINVAL, ENOMEM #include "asm-generic/int-ll64.h" // for u8 #include "linux/compiler_attributes.h" // for __aligned #include "linux/dev_printk.h" // for dev_err_probe #include "linux/iio/types.h" // for iio_chan_info_enum, iio_chan_... #include "linux/math.h" // for DIV_ROUND_CLOSEST #include "linux/minmax.h" // for __cmp_op_max #include "linux/mutex_types.h" // for mutex #include "linux/types.h" // for __be16 #include "vdso/bits.h" // for BIT The full include-list for drivers/iio/amplifiers/ad8366.c: #include <linux/bitrev.h> // for bitrev8 #include <linux/err.h> // for IS_ERR, PTR_ERR #include <linux/gpio/consumer.h> // for devm_gpiod_get_optional, gpio... #include <linux/iio/iio.h> // for iio_priv, iio_dev, iio_chan_spec #include <linux/mod_devicetable.h> // for kernel_ulong_t, spi_device_id #include <linux/module.h> // for MODULE_DEVICE_TABLE, MODULE_A... #include <linux/mutex.h> // for mutex_lock, mutex_unlock, dev... #include <linux/regulator/consumer.h> // for devm_regulator_get_enable #include <linux/reset.h> // for devm_reset_control_get_option... #include <linux/spi/spi.h> // for spi_write, spi_get_device_id #include <linux/unaligned.h> // for put_unaligned_be16 #include <stddef.h> // for size_t, NULL #include "asm-generic/errno-base.h" // for EINVAL, ENOMEM #include "asm-generic/int-ll64.h" // for u8 #include "linux/compiler_attributes.h" // for __aligned #include "linux/dev_printk.h" // for dev_err_probe #include "linux/iio/types.h" // for iio_chan_info_enum, iio_chan_... #include "linux/math.h" // for DIV_ROUND_CLOSEST #include "linux/minmax.h" // for __cmp_op_max #include "linux/mutex_types.h" // for mutex #include "linux/types.h" // for __be16 #include "vdso/bits.h" // for BIT -- Kind regards, Rodrigo Alencar
On Wed, Feb 11, 2026 at 12:55:30PM +0000, Rodrigo Alencar wrote: > On 26/02/10 09:57PM, Andy Shevchenko wrote: > > On Tue, Feb 10, 2026 at 07:42:03PM +0000, Rodrigo Alencar via B4 Relay wrote: > > > > > Apply IWYU principle, removing the following headers: > > > - linux/device.h: no usage of devm_add_action_or_reset, device_attr... > > > - linux/kernel.h: no usage of container_of, kasprintf, ... > > > - linux/slab.h: memory management handled by iio > > > - linux/sysfs.h: sysfs interaction is managed by iio > > > - linux/iio/sysfs.h: not using iio device attributes in this driver > > > > Yeah, but it also means to add (a lot of) missed headers... > > > > array_size,h > > dev_printk.h > > mod_devicetable.h > > mutex.h > > stddef.h > > Are there proper guidelines for IWYU in the kernel? > Include headers end up including a bunch of others, so > the build finishes successfully anyways. This is global stuff, no need to repeat this in the kernel documentation. It's the same as asking documentation for KISS principle. > I understand that the concern is build time, so we better > include all small parts that are needed rather than a generic > header that includes that and much more. > This is the output of the iwyu tool without this patch series: Have you applied the configuration Jonathan made for this tool in relation to the Linux kernel project? By default the tool has a lot of noise, indeed. And note, tool != principle. The tool is just an implementation of the helper to enforce the principle in practice, but it may be not always suitable for the certain project "as is". In the below output some are valid, but some are just noise as there are guarantees for the "proxying". -- With Best Regards, Andy Shevchenko
On Wed, 11 Feb 2026 15:35:32 +0200 Andy Shevchenko <andriy.shevchenko@intel.com> wrote: > On Wed, Feb 11, 2026 at 12:55:30PM +0000, Rodrigo Alencar wrote: > > On 26/02/10 09:57PM, Andy Shevchenko wrote: > > > On Tue, Feb 10, 2026 at 07:42:03PM +0000, Rodrigo Alencar via B4 Relay wrote: > > > > > > > Apply IWYU principle, removing the following headers: > > > > - linux/device.h: no usage of devm_add_action_or_reset, device_attr... > > > > - linux/kernel.h: no usage of container_of, kasprintf, ... > > > > - linux/slab.h: memory management handled by iio > > > > - linux/sysfs.h: sysfs interaction is managed by iio > > > > - linux/iio/sysfs.h: not using iio device attributes in this driver > > > > > > Yeah, but it also means to add (a lot of) missed headers... > > > > > > array_size,h > > > dev_printk.h > > > mod_devicetable.h > > > mutex.h > > > stddef.h > > > > Are there proper guidelines for IWYU in the kernel? > > Include headers end up including a bunch of others, so > > the build finishes successfully anyways. > > This is global stuff, no need to repeat this in the kernel documentation. > It's the same as asking documentation for KISS principle. > > > I understand that the concern is build time, so we better > > include all small parts that are needed rather than a generic > > header that includes that and much more. > > > This is the output of the iwyu tool without this patch series: > > Have you applied the configuration Jonathan made for this tool in relation > to the Linux kernel project? By default the tool has a lot of noise, indeed. Worth noting that I'm still evolving my config and suspect there will still be a bit of 'taste' applied to the output even once I conclude what the best combinations are. So to give my view on the following.. > #include <stddef.h> // for NULL Not this one. > #include "asm-generic/errno-base.h" // for EINVAL, ENOMEM Something to get to errnos is good, but not that one. > #include "linux/array_size.h" // for ARRAY_SIZE Yes - this is part of the kernel.h split up work. > #include "linux/compiler_attributes.h" // for __aligned Never that one, but I sometimes feel compiler.h is fine. > #include "linux/dev_printk.h" // for dev_err Yes if device.h doesn't have to be there for other reasons. > #include "linux/iio/types.h" // for iio_chan_info_enum, iio_chan_... No. We always need iio.h which will always include that. > #include "linux/math.h" // for abs yes > #include "linux/minmax.h" // for __cmp_op_max yes > #include "linux/mod_devicetable.h" // for spi_device_id yes > #include "linux/mutex.h" // for mutex_lock, mutex_unlock, mut... yes > #include "linux/mutex_types.h" // for mutex no as mutex.h will alays include that. > #include "vdso/bits.h" // for BIT Usually via bitops.h or similar. But if none of those are there anyway linux/bits.h Jonathan > > And note, tool != principle. The tool is just an implementation of the helper > to enforce the principle in practice, but it may be not always suitable for > the certain project "as is". > > In the below output some are valid, but some are just noise as there are > guarantees for the "proxying". >
On Sat, Feb 14, 2026 at 06:30:51PM +0000, Jonathan Cameron wrote: > On Wed, 11 Feb 2026 15:35:32 +0200 > Andy Shevchenko <andriy.shevchenko@intel.com> wrote: > > On Wed, Feb 11, 2026 at 12:55:30PM +0000, Rodrigo Alencar wrote: > > > On 26/02/10 09:57PM, Andy Shevchenko wrote: > > > > On Tue, Feb 10, 2026 at 07:42:03PM +0000, Rodrigo Alencar via B4 Relay wrote: ... > > > > Yeah, but it also means to add (a lot of) missed headers... > > > > > > > > array_size,h > > > > dev_printk.h > > > > mod_devicetable.h > > > > mutex.h > > > > stddef.h ... > > > This is the output of the iwyu tool without this patch series: > > > > Have you applied the configuration Jonathan made for this tool in relation > > to the Linux kernel project? By default the tool has a lot of noise, indeed. > > Worth noting that I'm still evolving my config and suspect there will still > be a bit of 'taste' applied to the output even once I conclude what the > best combinations are. So to give my view on the following.. > > > #include <stddef.h> // for NULL > Not this one. Why not? Here is the NULL in use, but... > > #include "linux/compiler_attributes.h" // for __aligned > Never that one, but I sometimes feel compiler.h is fine. ...taking into account this one, I would rather include linux/types.h instead of any of them. -- With Best Regards, Andy Shevchenko
On Sun, 15 Feb 2026 09:31:08 +0200 Andy Shevchenko <andriy.shevchenko@intel.com> wrote: > On Sat, Feb 14, 2026 at 06:30:51PM +0000, Jonathan Cameron wrote: > > On Wed, 11 Feb 2026 15:35:32 +0200 > > Andy Shevchenko <andriy.shevchenko@intel.com> wrote: > > > On Wed, Feb 11, 2026 at 12:55:30PM +0000, Rodrigo Alencar wrote: > > > > On 26/02/10 09:57PM, Andy Shevchenko wrote: > > > > > On Tue, Feb 10, 2026 at 07:42:03PM +0000, Rodrigo Alencar via B4 Relay wrote: > > ... > > > > > > Yeah, but it also means to add (a lot of) missed headers... > > > > > > > > > > array_size,h > > > > > dev_printk.h > > > > > mod_devicetable.h > > > > > mutex.h > > > > > stddef.h > > ... > > > > > This is the output of the iwyu tool without this patch series: > > > > > > Have you applied the configuration Jonathan made for this tool in relation > > > to the Linux kernel project? By default the tool has a lot of noise, indeed. > > > > Worth noting that I'm still evolving my config and suspect there will still > > be a bit of 'taste' applied to the output even once I conclude what the > > best combinations are. So to give my view on the following.. > > > > > #include <stddef.h> // for NULL > > Not this one. > > Why not? Here is the NULL in use, but... > > > > #include "linux/compiler_attributes.h" // for __aligned > > Never that one, but I sometimes feel compiler.h is fine. > > ...taking into account this one, I would rather include linux/types.h > instead of any of them. > That's where I'd go as well. I think this might be the first case I've seen where there is no other reason to have linux/types.h (due to the sub 8 bits bit depth and use of unsigned chars rather than u8) so I kind of assumed it was there :(
© 2016 - 2026 Red Hat, Inc.