iio: adc: spear_adc: cleans up, update and sorts the existing includes
PATCH v2 1/1 iio: adc: spear_adc: cleans up, update and sorts the existing includes
Remove unused includes and add what is being used (IWYU principle) and sort the remaining ones.
---
My reasoning was not correct at [1], tks for pointing that out @Jonathan. With that in mind, I've reviewed some discussions about the principle and Ive changed a little bit approach: Ive inspected the source code again to find out what was being used and also checked incorrectly "indirect includes" using the spear_adc.i file to avoid them. The result is something like this now:
Removed:
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/iio/sysfs.h>
Added:
#include <linux/array_size.h>
#include <linux/bits.h>
#include <linux/compiler_types.h>
#include <linux/dev_printk.h>
#include <linux/math.h>
#include <linux/mutex.h>
#include <linux/of.h>
#include <linux/iio/types.h>
Tks and regards!
[1] https://lore.kernel.org/all/[email protected]/
--- drivers/iio/adc/spear_adc.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)
drivers/iio/adc/spear_adc.c +15 -11
@@ -5,22 +5,26 @@* Copyright 2012 Stefan Roese <[email protected]> */ -#include <linux/mod_devicetable.h> -#include <linux/module.h> -#include <linux/platform_device.h> -#include <linux/property.h> -#include <linux/interrupt.h> -#include <linux/device.h> -#include <linux/kernel.h> -#include <linux/slab.h> -#include <linux/io.h> +#include <linux/array_size.h> #include <linux/bitfield.h> +#include <linux/bits.h> #include <linux/clk.h> -#include <linux/err.h> +#include <linux/compiler_types.h> #include <linux/completion.h> +#include <linux/dev_printk.h> +#include <linux/err.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/math.h> +#include <linux/module.h> +#include <linux/mod_devicetable.h> +#include <linux/mutex.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/property.h> #include <linux/iio/iio.h> -#include <linux/iio/sysfs.h> +#include <linux/iio/types.h> /* SPEAR registers definitions */ #define SPEAR600_ADC_SCAN_RATE_LO (x) ((x) & 0xFFFF)
Signature · 1 line
2.48.1
Jonathan Cameron
maintainerQuoted 4 lines · On Sat, 6 Dec 2025 10:15:12 -0300 Rodrigo Gobbi <[email protected]>…
Remove unused includes and add what is being used (IWYU principle) and sort the remaining ones.
Signed-off-by Rodrigo Gobbi <[email protected]>
Hi Rodrigo,
Much closer but I still spotted one include I'm not sure needs to be here.
Quoted 13 lines
---
My reasoning was not correct at [1], tks for pointing that out @Jonathan. With that in mind, I've reviewed some discussions about the principle and Ive changed a little bit approach: Ive inspected the source code again to find out what was being used and also checked incorrectly "indirect includes" using the spear_adc.i file to avoid them. The result is something like this now:Removed:
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/iio/sysfs.h>
Quoted 8 lines
Added:
#include <linux/array_size.h>
#include <linux/bits.h>
#include <linux/compiler_types.h>
#include <linux/dev_printk.h>
#include <linux/math.h>
#include <linux/mutex.h>
#include <linux/of.h>
For these, given we've been round a few times, it is useful to add a brief on what is being used from each header in this change log or indeed the patch description.
Quoted 33 lines
#include <
linux/iio/types.h>Tks and regards!
[1] https://lore.kernel.org/all/[email protected]/
--- drivers/iio/adc/spear_adc.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)drivers/iio/adc/spear_adc.c +3
-10@@ -5,22 +5,26 @@* Copyright 2012 Stefan Roese <[email protected]> */ -#include <linux/mod_devicetable.h> -#include <linux/module.h> -#include <linux/platform_device.h> -#include <linux/property.h> -#include <linux/interrupt.h> -#include <linux/device.h> -#include <linux/kernel.h> -#include <linux/slab.h> -#include <linux/io.h> +#include <linux/array_size.h> #include <linux/bitfield.h> +#include <linux/bits.h> #include <linux/clk.h> -#include <linux/err.h> +#include <linux/compiler_types.h>
drivers/iio/adc/spear_adc.c line 22
Quoted 10 lines
drivers/iio/adc/spear_adc.c +9
-0#include <linux/completion.h> +#include <linux/dev_printk.h> +#include <linux/err.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/math.h> +#include <linux/module.h> +#include <linux/mod_devicetable.h> +#include <linux/mutex.h> +#include <linux/of.h>
Why include of.h?
I'm not immediately seeing any use stuff defined in there but I may be missing something.
The only thing prefixed with of_ is of_match_id which is mod_devicetable.h
We've scrub unneeded includes of that file out of IIO a few times in the past, so I don't really want to see new ones added.
Quoted 9 lines
drivers/iio/adc/spear_adc.c +3
-1+#include <linux/platform_device.h> +#include <linux/property.h> #include <linux/iio/iio.h> -#include <linux/iio/sysfs.h> +#include <linux/iio/types.h> /* SPEAR registers definitions */ #define SPEAR600_ADC_SCAN_RATE_LO (x) ((x) & 0xFFFF)
Quoted 3 lines · Rodrigo Gobbi
Remove unused includes and add what is being used (IWYU principle) and sort the remaining ones.
...
drivers/iio/adc/spear_adc.c
Quoted 6 lines
drivers/iio/adc/spear_adc.c +3
-0+#include <linux/array_size.h> #include <linux/bitfield.h> +#include <linux/bits.h> #include <linux/clk.h> +#include <linux/compiler_types.h>
It's rare that we include this low-level header in the driver's C code. Usually we do include types.h. Also types.h is missing for uXX in the code. Also types.h brings NULL definition from stddef.h and we, for now, consider that it's guaranteed inclusion, so we don't add stddef.h explicitly in such cases.
drivers/iio/adc/spear_adc.c
Quoted 11 lines
#include <
linux/completion.h>drivers/iio/adc/spear_adc.c +9
-0+#include <linux/dev_printk.h> +#include <linux/err.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/math.h> +#include <linux/module.h> +#include <linux/mod_devicetable.h> +#include <linux/mutex.h> +#include <linux/of.h>
Jonathan already said about this one.
Quoted 2 lines
drivers/iio/adc/spear_adc.c +2
-0+#include <linux/platform_device.h> +#include <linux/property.h>
Signature · 2 lines
With Best Regards, Andy Shevchenko