iio: accel: kionix-kx022a: Apply approximate iwyu principles to includes
Subsystems (2)
Jonathan Cameron
maintainerPATCH 1/1 iio: accel: kionix-kx022a: Apply approximate iwyu principles to includes
From: Jonathan Cameron <[email protected]>
Motivated by the W=1 warning about export.h that was introduced this cycle this is an attempt to apply an approximation of the principles of including whatever is used in the file directly.
Helped by the include-what-you-use tool.
Reasoning:
- Drop linux/moduleparam.h as completely unused.
- linux/array_size.h for ARRAY_SIZE()
- linux/bitmap.h for for_each_set_bit
- linux/errno.h for error codes.
- linux/export.h for EXPORT_SYMBOL*()
- linux/math64.h for do_div - alternative would be asm/div64.h
- linux/minmax.h for min()
- linux/sysfs.h for sysfs_emit()
- linux/time64.h for USEC_PER_MSEC
- linux/iio/buffer.h for iio_push_to_buffers_with_timestamp()
- asm/byteorder.h for le16_to_cpu()
---
I picked this one fairly randomly as an example but longer term I'd like to look through at least all new drivers with this in mind + all the ones that are currently messing up my W=1 build logs.
Note I've been very descriptive in this patch to allow people to suggest better alternatives for some of the ones that aren't entirely obvious.
--- drivers/iio/accel/kionix-kx022a.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/iio/accel/kionix-kx022a.c +11 -1
@@ -5,27 +5,37 @@* ROHM/KIONIX accelerometer driver */ +#include <linux/array_size.h> +#include <linux/bitmap.h> #include <linux/cleanup.h> #include <linux/delay.h> #include <linux/device.h> +#include <linux/errno.h> +#include <linux/export.h> #include <linux/interrupt.h> +#include <linux/math64.h> +#include <linux/minmax.h> #include <linux/module.h> -#include <linux/moduleparam.h> #include <linux/mutex.h> #include <linux/property.h> #include <linux/regmap.h> #include <linux/regulator/consumer.h> #include <linux/slab.h> #include <linux/string_choices.h> +#include <linux/sysfs.h> +#include <linux/time64.h> #include <linux/types.h> #include <linux/units.h> #include <linux/iio/iio.h> +#include <linux/iio/buffer.h> #include <linux/iio/sysfs.h> #include <linux/iio/trigger.h> #include <linux/iio/trigger_consumer.h> #include <linux/iio/triggered_buffer.h> +#include <asm/byteorder.h> +#include "kionix-kx022a.h" /*
Signature · 1 line
2.50.0
Jonathan Cameron
maintainerQuoted 22 lines · On Sun, 29 Jun 2025 19:36:49 +0100 Jonathan Cameron <[email protected]> wrote:
From: Jonathan Cameron <[email protected]>
Motivated by the W=1 warning about
export.hthat was introduced this cycle this is an attempt to apply an approximation of the principles of including whatever is used in the file directly.Helped by the include-what-you-use tool.
Reasoning:
- Droplinux/moduleparam.has completely unused.
-linux/array_size.hforARRAY_SIZE()
-linux/bitmap.hforfor_each_set_bit
-linux/errno.hfor error codes.
-linux/export.hfor EXPORT_SYMBOL*()
-linux/math64.hfordo_div- alternative would beasm/div64.h
-linux/minmax.hformin()
-linux/sysfs.hforsysfs_emit()
-linux/time64.hforUSEC_PER_MSEC
-linux/iio/buffer.hforiio_push_to_buffers_with_timestamp()
-asm/byteorder.hforle16_to_cpu()Signed-off-by Jonathan Cameron <[email protected]>
Quoted 9 lines
---
I picked this one fairly randomly as an example but longer term I'd like to look through at least all new drivers with this in mind + all the ones that are currently messing up my W=1 build logs.
Note I've been very descriptive in this patch to allow people to suggest better alternatives for some of the ones that aren't entirely obvious.
Helpfully I had a script lying around from 2021:
https://lore.kernel.org/all/[email protected]/
Just for reference I used iwyu with:
make LLVM=1 LOCALVERSION= W=1 -j12 C=1 CHECK=include-what-you-use CHECKFLAGS="-Xiwyu --no_default_mappings -Xiwyu --mapping_file=iio.imp"
where iio.imp is from a few years ago and contains:
{ include: ["\"linux/sizes.h\"", "private", <linux/sizes.h>, "public"] },
{ include: ["\"linux/slab.h\"", "private", <linux/slab.h>, "public"] },
{ include: ["\"linux/spinlock.h\"", "private", <linux/spinlock.h>, "public"] },
{ include: ["\"linux/spinlock_types.h\"", "private", <linux/spinlock.h>, "public"] },
{ include: ["\"linux/spi/spi.h\"", "private", <linux/spi/spi.h>, "public"] },
{ include: ["\"linux/stat.h\"", "private", <linux/stat.h>, "public"] },
{ include: ["\"linux/stdarg.h\"", "private", <linux/stdarg.h>, "public"] },
{ include: ["\"linux/stddef.h\"", "private", <linux/stddef.h>, "public"] },
{ include: ["\"linux/string.h\"", "private", <linux/string.h>, "public"] },
{ include: ["\"linux/stringify.h\"", "private", <linux/stringify.h>, "public"] },
{ include: ["\"linux/sysfs.h\"", "private", <linux/sysfs.h>, "public"] },
{ include: ["\"linux/types.h\"", "private", <linux/types.h>, "public"] },
{ include: ["\"linux/uuid.h\"", "private", <linux/uuid.h>, "public"] },
{ include: ["\"linux/sched.h\"", "private", <linux/sched.h>, "public"] },
{ include: ["\"linux/wait.h\"", "private", <linux/wait.h>, "public"] },
{ include: ["\"linux/workqueue.h\"", "private", <linux/workqueue.h>, "public"] },
{ include: ["\"asm-generic/int-ll64.h\"", "private", <linux/types.h>, "public"] },
{ include: ["\"linux/device.h\"", "private", <linux/device.h>, "public"] },
{ include: ["\"linux/dev_printk.h\"", "private", <linux/device.h>, "public"] },
{ include: ["\"linux/device/bus.h\"", "private", <linux/device.h>, "public"] },
{ include: ["\"linux/device/driver.h\"", "private", <linux/device.h>, "public"] },
{ include: ["\"linux/bits.h\"", "private", <linux/bits.h>, "public"] },
{ include: ["\"vdso/bits.h\"", "private", <linux/bits.h>, "public"] },
{ include: ["\"vdso/limits.h\"", "private", <linux/limits.h>, "public"] },
{ include: ["\"linux/limits.h\"", "private", <linux/limits.h>, "public"] },
{ include: ["\"vdso/ktime.h\"", "private", <linux/ktime.h>, "public"] },
{ include: ["\"linux/ktime.h\"", "private", <linux/ktime.h>, "public"] },
{ include: ["\"vdso/time64.h\"", "private", <linux/time64.h>, "public"] },
{ include: ["\"linux/time.h\"", "private", <linux/time.h>, "public"] },
{ include: ["\"linux/timer.h\"", "private", <linux/timer.h>, "public"] }]
Clear this needs a few upates, like mutex_types.h -> mutex.h and probably devres.h->device.h
output was:
drivers/iio/accel/kionix-kx022a.c should add these lines:
#include <asm/byteorder.h> // for le16_to_cpu #include <asm/div64.h> // for do_div #include <linux/bitmap.h> // for for_each_set_bit #include <linux/compiler.h> // for __aligned #include <linux/errno.h> // for EINVAL, EBUSY, ENOMEM, ENODEV #include <linux/export.h> // for EXPORT_SYMBOL_NS_GPL #include <linux/iio/buffer.h> // for iio_push_to_buffers_with_tim... #include <linux/minmax.h> // for __cmp_op_min, min, __cmp_op_max #include <linux/stddef.h> // for false, true, NULL #include <linux/sysfs.h> // for sysfs_emit #include <linux/time64.h> // for USEC_PER_MSEC, NSEC_PER_MSEC #include "linux/array_size.h" // for ARRAY_SIZE #include "linux/device/devres.h" // for devm_kasprintf #include "linux/gfp_types.h" // for GFP_KERNEL #include "linux/mutex_types.h" // for mutex
drivers/iio/accel/kionix-kx022a.c should remove these lines:
- #include <linux/moduleparam.h> // lines 13-13
The full include-list for drivers/iio/accel/kionix-kx022a.c:
#include "kionix-kx022a.h"
#include <asm/byteorder.h> // for le16_to_cpu #include <asm/div64.h> // for do_div #include <linux/bitmap.h> // for for_each_set_bit #include <linux/cleanup.h> // for guard #include <linux/compiler.h> // for __aligned #include <linux/delay.h> // for msleep #include <linux/device.h> // for dev_err_probe, dev_err, dev_... #include <linux/errno.h> // for EINVAL, EBUSY, ENOMEM, ENODEV #include <linux/export.h> // for EXPORT_SYMBOL_NS_GPL #include <linux/iio/buffer.h> // for iio_push_to_buffers_with_tim... #include <linux/iio/iio.h> // for iio_chan_info_enum, iio_endian #include <linux/iio/sysfs.h> // for IIO_DEVICE_ATTR_RO #include <linux/iio/trigger.h> // for devm_iio_trigger_register #include <linux/iio/trigger_consumer.h> // for iio_trigger_notify_done, iio... #include <linux/iio/triggered_buffer.h> // for devm_iio_triggered_buffer_se... #include <linux/interrupt.h> // for irqreturn, irqreturn_t, devm... #include <linux/minmax.h> // for __cmp_op_min, min, __cmp_op_max #include <linux/module.h> // for MODULE_AUTHOR, MODULE_DESCRI... #include <linux/mutex.h> // for mutex_unlock, mutex_lock #include <linux/property.h> // for fwnode_irq_get_byname, dev_f... #include <linux/regmap.h> // for regmap_range, regmap_set_bits #include <linux/regulator/consumer.h> // for devm_regulator_bulk_get_enable #include <linux/slab.h> // for kfree, kmalloc_array #include <linux/stddef.h> // for false, true, NULL #include <linux/string_choices.h> // for str_on_off #include <linux/sysfs.h> // for sysfs_emit #include <linux/time64.h> // for USEC_PER_MSEC, NSEC_PER_MSEC #include <linux/types.h> // for __le16, bool, int64_t, ssize_t #include <linux/units.h> // for MEGA #include "linux/array_size.h" // for ARRAY_SIZE #include "linux/device/devres.h" // for devm_kasprintf #include "linux/gfp_types.h" // for GFP_KERNEL #include "linux/mutex_types.h" // for mutex
Quoted 47 lines
--- drivers/iio/accel/kionix-kx022a.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)drivers/iio/accel/kionix-kx022a.c +11
-1@@ -5,27 +5,37 @@* ROHM/KIONIX accelerometer driver */ +#include <linux/array_size.h> +#include <linux/bitmap.h> #include <linux/cleanup.h> #include <linux/delay.h> #include <linux/device.h> +#include <linux/errno.h> +#include <linux/export.h> #include <linux/interrupt.h> +#include <linux/math64.h> +#include <linux/minmax.h> #include <linux/module.h> -#include <linux/moduleparam.h> #include <linux/mutex.h> #include <linux/property.h> #include <linux/regmap.h> #include <linux/regulator/consumer.h> #include <linux/slab.h> #include <linux/string_choices.h> +#include <linux/sysfs.h> +#include <linux/time64.h> #include <linux/types.h> #include <linux/units.h> #include <linux/iio/iio.h> +#include <linux/iio/buffer.h> #include <linux/iio/sysfs.h> #include <linux/iio/trigger.h> #include <linux/iio/trigger_consumer.h> #include <linux/iio/triggered_buffer.h> +#include <asm/byteorder.h> +#include "kionix-kx022a.h" /*
Quoted 72 lines · Jonathan Cameron
Quoted 22 lines · On Sun, 29 Jun 2025 19:36:49 +0100 Jonathan Cameron <[email protected]> wrote:
From: Jonathan Cameron <[email protected]>
Motivated by the W=1 warning about
export.hthat was introduced this cycle this is an attempt to apply an approximation of the principles of including whatever is used in the file directly.Helped by the include-what-you-use tool.
Reasoning:
- Droplinux/moduleparam.has completely unused.
-linux/array_size.hforARRAY_SIZE()
-linux/bitmap.hforfor_each_set_bit
-linux/errno.hfor error codes.
-linux/export.hfor EXPORT_SYMBOL*()
-linux/math64.hfordo_div- alternative would beasm/div64.h
-linux/minmax.hformin()
-linux/sysfs.hforsysfs_emit()
-linux/time64.hforUSEC_PER_MSEC
-linux/iio/buffer.hforiio_push_to_buffers_with_timestamp()
-asm/byteorder.hforle16_to_cpu()Signed-off-by Jonathan Cameron <[email protected]>Quoted 9 lines
---
I picked this one fairly randomly as an example but longer term I'd like to look through at least all new drivers with this in mind + all the ones that are currently messing up my W=1 build logs.
Note I've been very descriptive in this patch to allow people to suggest better alternatives for some of the ones that aren't entirely obvious.
Helpfully I had a script lying around from 2021:
https://lore.kernel.org/all/[email protected]/Just for reference I used iwyu with:
make LLVM=1 LOCALVERSION= W=1 -j12 C=1 CHECK=include-what-you-use CHECKFLAGS="-Xiwyu --no_default_mappings -Xiwyu --mapping_file=iio.imp"
where iio.imp is from a few years ago and contains:
{ include: ["\"linux/sizes.h\"", "private", <linux/sizes.h>, "public"] }, { include: ["\"linux/slab.h\"", "private", <linux/slab.h>, "public"] }, { include: ["\"linux/spinlock.h\"", "private", <linux/spinlock.h>, "public"] }, { include: ["\"linux/spinlock_types.h\"", "private", <linux/spinlock.h>, "public"] }, { include: ["\"linux/spi/spi.h\"", "private", <linux/spi/spi.h>, "public"] }, { include: ["\"linux/stat.h\"", "private", <linux/stat.h>, "public"] }, { include: ["\"linux/stdarg.h\"", "private", <linux/stdarg.h>, "public"] }, { include: ["\"linux/stddef.h\"", "private", <linux/stddef.h>, "public"] }, { include: ["\"linux/string.h\"", "private", <linux/string.h>, "public"] }, { include: ["\"linux/stringify.h\"", "private", <linux/stringify.h>, "public"] }, { include: ["\"linux/sysfs.h\"", "private", <linux/sysfs.h>, "public"] }, { include: ["\"linux/types.h\"", "private", <linux/types.h>, "public"] }, { include: ["\"linux/uuid.h\"", "private", <linux/uuid.h>, "public"] }, { include: ["\"linux/sched.h\"", "private", <linux/sched.h>, "public"] }, { include: ["\"linux/wait.h\"", "private", <linux/wait.h>, "public"] }, { include: ["\"linux/workqueue.h\"", "private", <linux/workqueue.h>, "public"] }, { include: ["\"asm-generic/int-ll64.h\"", "private", <linux/types.h>, "public"] }, { include: ["\"linux/device.h\"", "private", <linux/device.h>, "public"] }, { include: ["\"linux/dev_printk.h\"", "private", <linux/device.h>, "public"] }, { include: ["\"linux/device/bus.h\"", "private", <linux/device.h>, "public"] }, { include: ["\"linux/device/driver.h\"", "private", <linux/device.h>, "public"] }, { include: ["\"linux/bits.h\"", "private", <linux/bits.h>, "public"] }, { include: ["\"vdso/bits.h\"", "private", <linux/bits.h>, "public"] }, { include: ["\"vdso/limits.h\"", "private", <linux/limits.h>, "public"] }, { include: ["\"linux/limits.h\"", "private", <linux/limits.h>, "public"] }, { include: ["\"vdso/ktime.h\"", "private", <linux/ktime.h>, "public"] }, { include: ["\"linux/ktime.h\"", "private", <linux/ktime.h>, "public"] }, { include: ["\"vdso/time64.h\"", "private", <linux/time64.h>, "public"] }, { include: ["\"linux/time.h\"", "private", <linux/time.h>, "public"] }, { include: ["\"linux/timer.h\"", "private", <linux/timer.h>, "public"] }
Quoted 4 lines
]
Clear this needs a few upates, like
mutex_types.h->mutex.hand probablydevres.h->device.h
Right, we got a lot of new *_types.h headers.
This is a database (kind of) I was talking about in previous reply. Can we actually start it as .iwyu or so in the kernel source tree?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 75 lines · On Mon, 30 Jun 2025 13:42:00 +0300 Andy Shevchenko…
Quoted 74 lines · Jonathan Cameron
Quoted 22 lines · On Sun, 29 Jun 2025 19:36:49 +0100 Jonathan Cameron <[email protected]> wrote:
From: Jonathan Cameron <[email protected]>
Motivated by the W=1 warning about
export.hthat was introduced this cycle this is an attempt to apply an approximation of the principles of including whatever is used in the file directly.Helped by the include-what-you-use tool.
Reasoning:
- Droplinux/moduleparam.has completely unused.
-linux/array_size.hforARRAY_SIZE()
-linux/bitmap.hforfor_each_set_bit
-linux/errno.hfor error codes.
-linux/export.hfor EXPORT_SYMBOL*()
-linux/math64.hfordo_div- alternative would beasm/div64.h
-linux/minmax.hformin()
-linux/sysfs.hforsysfs_emit()
-linux/time64.hforUSEC_PER_MSEC
-linux/iio/buffer.hforiio_push_to_buffers_with_timestamp()
-asm/byteorder.hforle16_to_cpu()Signed-off-by Jonathan Cameron <[email protected]>Quoted 9 lines
---
I picked this one fairly randomly as an example but longer term I'd like to look through at least all new drivers with this in mind + all the ones that are currently messing up my W=1 build logs.
Note I've been very descriptive in this patch to allow people to suggest better alternatives for some of the ones that aren't entirely obvious.
Helpfully I had a script lying around from 2021:
https://lore.kernel.org/all/[email protected]/Just for reference I used iwyu with:
make LLVM=1 LOCALVERSION= W=1 -j12 C=1 CHECK=include-what-you-use CHECKFLAGS="-Xiwyu --no_default_mappings -Xiwyu --mapping_file=iio.imp"
where iio.imp is from a few years ago and contains:
{ include: ["\"linux/sizes.h\"", "private", <linux/sizes.h>, "public"] }, { include: ["\"linux/slab.h\"", "private", <linux/slab.h>, "public"] }, { include: ["\"linux/spinlock.h\"", "private", <linux/spinlock.h>, "public"] }, { include: ["\"linux/spinlock_types.h\"", "private", <linux/spinlock.h>, "public"] }, { include: ["\"linux/spi/spi.h\"", "private", <linux/spi/spi.h>, "public"] }, { include: ["\"linux/stat.h\"", "private", <linux/stat.h>, "public"] }, { include: ["\"linux/stdarg.h\"", "private", <linux/stdarg.h>, "public"] }, { include: ["\"linux/stddef.h\"", "private", <linux/stddef.h>, "public"] }, { include: ["\"linux/string.h\"", "private", <linux/string.h>, "public"] }, { include: ["\"linux/stringify.h\"", "private", <linux/stringify.h>, "public"] }, { include: ["\"linux/sysfs.h\"", "private", <linux/sysfs.h>, "public"] }, { include: ["\"linux/types.h\"", "private", <linux/types.h>, "public"] }, { include: ["\"linux/uuid.h\"", "private", <linux/uuid.h>, "public"] }, { include: ["\"linux/sched.h\"", "private", <linux/sched.h>, "public"] }, { include: ["\"linux/wait.h\"", "private", <linux/wait.h>, "public"] }, { include: ["\"linux/workqueue.h\"", "private", <linux/workqueue.h>, "public"] }, { include: ["\"asm-generic/int-ll64.h\"", "private", <linux/types.h>, "public"] }, { include: ["\"linux/device.h\"", "private", <linux/device.h>, "public"] }, { include: ["\"linux/dev_printk.h\"", "private", <linux/device.h>, "public"] }, { include: ["\"linux/device/bus.h\"", "private", <linux/device.h>, "public"] }, { include: ["\"linux/device/driver.h\"", "private", <linux/device.h>, "public"] }, { include: ["\"linux/bits.h\"", "private", <linux/bits.h>, "public"] }, { include: ["\"vdso/bits.h\"", "private", <linux/bits.h>, "public"] }, { include: ["\"vdso/limits.h\"", "private", <linux/limits.h>, "public"] }, { include: ["\"linux/limits.h\"", "private", <linux/limits.h>, "public"] }, { include: ["\"vdso/ktime.h\"", "private", <linux/ktime.h>, "public"] }, { include: ["\"linux/ktime.h\"", "private", <linux/ktime.h>, "public"] }, { include: ["\"vdso/time64.h\"", "private", <linux/time64.h>, "public"] }, { include: ["\"linux/time.h\"", "private", <linux/time.h>, "public"] }, { include: ["\"linux/timer.h\"", "private", <linux/timer.h>, "public"] }]
Quoted 6 lines
Quoted 2 lines
Clear this needs a few upates, like
mutex_types.h->mutex.hand probablydevres.h->device.hRight, we got a lot of new *_types.h headers.
This is a database (kind of) I was talking about in previous reply. Can we actually start it as .iwyu or so in the kernel source tree?
Nick and Tanzir talked about using iwyu at Plumbers 2023 and probably have a much better starting point that this (even more) ancient version. I missed the talk completely at the time, but came across it more recently.
+CC them both
Jonathan
Quoted 86 lines · Jonathan Cameron
Quoted 75 lines · On Mon, 30 Jun 2025 13:42:00 +0300 Andy Shevchenko…
Quoted 74 lines · Jonathan Cameron
Quoted 22 lines · On Sun, 29 Jun 2025 19:36:49 +0100 Jonathan Cameron <[email protected]> wrote:
From: Jonathan Cameron <[email protected]>
Motivated by the W=1 warning about
export.hthat was introduced this cycle this is an attempt to apply an approximation of the principles of including whatever is used in the file directly.Helped by the include-what-you-use tool.
Reasoning:
- Droplinux/moduleparam.has completely unused.
-linux/array_size.hforARRAY_SIZE()
-linux/bitmap.hforfor_each_set_bit
-linux/errno.hfor error codes.
-linux/export.hfor EXPORT_SYMBOL*()
-linux/math64.hfordo_div- alternative would beasm/div64.h
-linux/minmax.hformin()
-linux/sysfs.hforsysfs_emit()
-linux/time64.hforUSEC_PER_MSEC
-linux/iio/buffer.hforiio_push_to_buffers_with_timestamp()
-asm/byteorder.hforle16_to_cpu()Signed-off-by Jonathan Cameron <[email protected]>Quoted 9 lines
---
I picked this one fairly randomly as an example but longer term I'd like to look through at least all new drivers with this in mind + all the ones that are currently messing up my W=1 build logs.
Note I've been very descriptive in this patch to allow people to suggest better alternatives for some of the ones that aren't entirely obvious.
Helpfully I had a script lying around from 2021:
https://lore.kernel.org/all/[email protected]/Just for reference I used iwyu with:
make LLVM=1 LOCALVERSION= W=1 -j12 C=1 CHECK=include-what-you-use CHECKFLAGS="-Xiwyu --no_default_mappings -Xiwyu --mapping_file=iio.imp"
where iio.imp is from a few years ago and contains:
{ include: ["\"linux/sizes.h\"", "private", <linux/sizes.h>, "public"] }, { include: ["\"linux/slab.h\"", "private", <linux/slab.h>, "public"] }, { include: ["\"linux/spinlock.h\"", "private", <linux/spinlock.h>, "public"] }, { include: ["\"linux/spinlock_types.h\"", "private", <linux/spinlock.h>, "public"] }, { include: ["\"linux/spi/spi.h\"", "private", <linux/spi/spi.h>, "public"] }, { include: ["\"linux/stat.h\"", "private", <linux/stat.h>, "public"] }, { include: ["\"linux/stdarg.h\"", "private", <linux/stdarg.h>, "public"] }, { include: ["\"linux/stddef.h\"", "private", <linux/stddef.h>, "public"] }, { include: ["\"linux/string.h\"", "private", <linux/string.h>, "public"] }, { include: ["\"linux/stringify.h\"", "private", <linux/stringify.h>, "public"] }, { include: ["\"linux/sysfs.h\"", "private", <linux/sysfs.h>, "public"] }, { include: ["\"linux/types.h\"", "private", <linux/types.h>, "public"] }, { include: ["\"linux/uuid.h\"", "private", <linux/uuid.h>, "public"] }, { include: ["\"linux/sched.h\"", "private", <linux/sched.h>, "public"] }, { include: ["\"linux/wait.h\"", "private", <linux/wait.h>, "public"] }, { include: ["\"linux/workqueue.h\"", "private", <linux/workqueue.h>, "public"] }, { include: ["\"asm-generic/int-ll64.h\"", "private", <linux/types.h>, "public"] }, { include: ["\"linux/device.h\"", "private", <linux/device.h>, "public"] }, { include: ["\"linux/dev_printk.h\"", "private", <linux/device.h>, "public"] }, { include: ["\"linux/device/bus.h\"", "private", <linux/device.h>, "public"] }, { include: ["\"linux/device/driver.h\"", "private", <linux/device.h>, "public"] }, { include: ["\"linux/bits.h\"", "private", <linux/bits.h>, "public"] }, { include: ["\"vdso/bits.h\"", "private", <linux/bits.h>, "public"] }, { include: ["\"vdso/limits.h\"", "private", <linux/limits.h>, "public"] }, { include: ["\"linux/limits.h\"", "private", <linux/limits.h>, "public"] }, { include: ["\"vdso/ktime.h\"", "private", <linux/ktime.h>, "public"] }, { include: ["\"linux/ktime.h\"", "private", <linux/ktime.h>, "public"] }, { include: ["\"vdso/time64.h\"", "private", <linux/time64.h>, "public"] }, { include: ["\"linux/time.h\"", "private", <linux/time.h>, "public"] }, { include: ["\"linux/timer.h\"", "private", <linux/timer.h>, "public"] }]
Quoted 6 lines
Quoted 2 lines
Clear this needs a few upates, like
mutex_types.h->mutex.hand probablydevres.h->device.hRight, we got a lot of new *_types.h headers.
This is a database (kind of) I was talking about in previous reply. Can we actually start it as .iwyu or so in the kernel source tree?
Quoted 8 lines
Nick and Tanzir talked about using iwyu at Plumbers 2023 and probably have a much better starting point that this (even more) ancient version. I missed the talk completely at the time, but came across it more recently.
+CC them both
Jonathan
Thanks for pinging. Here is a repository with some useful scripts.
https://github.com/ClangBuiltLinux/IWYUScripts. Forgive the code quality, I was an intern at the time.
Quoted 22 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Motivated by the W=1 warning about
export.hthat was introduced this cycle this is an attempt to apply an approximation of the principles of including whatever is used in the file directly.Helped by the include-what-you-use tool.
Reasoning:
- Droplinux/moduleparam.has completely unused.
-linux/array_size.hforARRAY_SIZE()
-linux/bitmap.hforfor_each_set_bit
-linux/errno.hfor error codes.
-linux/export.hfor EXPORT_SYMBOL*()
-linux/math64.hfordo_div- alternative would beasm/div64.h
-linux/minmax.hformin()
-linux/sysfs.hforsysfs_emit()
-linux/time64.hforUSEC_PER_MSEC
-linux/iio/buffer.hforiio_push_to_buffers_with_timestamp()
-asm/byteorder.hforle16_to_cpu()Signed-off-by Jonathan Cameron <[email protected]>
Quoted 8 lines
---
I picked this one fairly randomly as an example but longer term I'd like to look through at least all new drivers with this in mind + all the ones that are currently messing up my W=1 build logs.
Note I've been very descriptive in this patch to allow people to suggest better alternatives for some of the ones that aren't entirely obvious.
Thanks for trying it again, very much appreciated!
What we actually miss is the database (in any text-based format, even *.d would work I suppose) for the guarantees. For example, if code uses ERR_PTR() and at the same time (very likely) uses something like -EINVAL, the errno.h is implied (and guaranteed!) by err.h. Explicit errno.h is in two cases: 1) nothing is used from err.h, but errno.h; 2) Linux special error codes are in use, e.g. EPROBE_DEFER.
Next, what I would really start with is the kernel.h. this is the beast that is happening in many files and old snippets all over the internet, it would be nice to clean it sooner than later. Especially if it's in the headers (should not be as written at the top of that file). So, hence just a priority for these cleanups first.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerQuoted 40 lines · On Mon, 30 Jun 2025 13:40:32 +0300 Andy Shevchenko…
Quoted 22 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Motivated by the W=1 warning about
export.hthat was introduced this cycle this is an attempt to apply an approximation of the principles of including whatever is used in the file directly.Helped by the include-what-you-use tool.
Reasoning:
- Droplinux/moduleparam.has completely unused.
-linux/array_size.hforARRAY_SIZE()
-linux/bitmap.hforfor_each_set_bit
-linux/errno.hfor error codes.
-linux/export.hfor EXPORT_SYMBOL*()
-linux/math64.hfordo_div- alternative would beasm/div64.h
-linux/minmax.hformin()
-linux/sysfs.hforsysfs_emit()
-linux/time64.hforUSEC_PER_MSEC
-linux/iio/buffer.hforiio_push_to_buffers_with_timestamp()
-asm/byteorder.hforle16_to_cpu()Signed-off-by Jonathan Cameron <[email protected]>Quoted 8 lines
---
I picked this one fairly randomly as an example but longer term I'd like to look through at least all new drivers with this in mind + all the ones that are currently messing up my W=1 build logs.
Note I've been very descriptive in this patch to allow people to suggest better alternatives for some of the ones that aren't entirely obvious.
Thanks for trying it again, very much appreciated!
What we actually miss is the database (in any text-based format, even *.d would work I suppose) for the guarantees. For example, if code uses
ERR_PTR()and at the same time (very likely) uses something like-EINVAL, theerrno.his implied (and guaranteed!) byerr.h. Expliciterrno.his in two cases: 1) nothing is used fromerr.h, buterrno.h; 2) Linux special error codes are in use, e.g.EPROBE_DEFER.
Quoted 6 lines
Next, what I would really start with is the
kernel.h. this is the beast that is happening in many files and old snippets all over the internet, it would be nice to clean it sooner than later. Especially if it's in the headers (should not be as written at the top of that file). So, hence just a priority for these cleanups first.
Those W=1 warnings are driving me mad, so I'll drive this from point of view of cleaning those up. Will sweep around doing others later.
Speaking of which lots of discussion about how to do this - anyone fancy giving me a review for this actual patch? :)
Matti Vaittinen
maintainerQuoted 49 lines · Jonathan Cameron
Quoted 40 lines · On Mon, 30 Jun 2025 13:40:32 +0300 Andy Shevchenko…
Quoted 22 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Motivated by the W=1 warning about
export.hthat was introduced this cycle this is an attempt to apply an approximation of the principles of including whatever is used in the file directly.Helped by the include-what-you-use tool.
Reasoning:
- Droplinux/moduleparam.has completely unused.
-linux/array_size.hforARRAY_SIZE()
-linux/bitmap.hforfor_each_set_bit
-linux/errno.hfor error codes.
-linux/export.hfor EXPORT_SYMBOL*()
-linux/math64.hfordo_div- alternative would beasm/div64.h
-linux/minmax.hformin()
-linux/sysfs.hforsysfs_emit()
-linux/time64.hforUSEC_PER_MSEC
-linux/iio/buffer.hforiio_push_to_buffers_with_timestamp()
-asm/byteorder.hforle16_to_cpu()Signed-off-by Jonathan Cameron <[email protected]>Quoted 8 lines
---
I picked this one fairly randomly as an example but longer term I'd like to look through at least all new drivers with this in mind + all the ones that are currently messing up my W=1 build logs.
Note I've been very descriptive in this patch to allow people to suggest better alternatives for some of the ones that aren't entirely obvious.
Thanks for trying it again, very much appreciated!
What we actually miss is the database (in any text-based format, even *.d would work I suppose) for the guarantees. For example, if code uses
ERR_PTR()and at the same time (very likely) uses something like-EINVAL, theerrno.his implied (and guaranteed!) byerr.h. Expliciterrno.his in two cases: 1) nothing is used fromerr.h, buterrno.h; 2) Linux special error codes are in use, e.g.EPROBE_DEFER.Quoted 6 lines
Next, what I would really start with is the
kernel.h. this is the beast that is happening in many files and old snippets all over the internet, it would be nice to clean it sooner than later. Especially if it's in the headers (should not be as written at the top of that file). So, hence just a priority for these cleanups first.
Quoted 6 lines
Those W=1 warnings are driving me mad, so I'll drive this from point of view of cleaning those up. Will sweep around doing others later.
Speaking of which lots of discussion about how to do this - anyone fancy giving me a review for this actual patch? :)
Sorry, it has been the holiday season for me ;) And still is - until August. Well, it's already applied - but still wanted to say it looks very good to me!
Yours,
-- Matti
Quoted 8 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Motivated by the W=1 warning about
export.hthat was introduced this cycle this is an attempt to apply an approximation of the principles of including whatever is used in the file directly.Helped by the include-what-you-use tool.
Quoted 12 lines
Reasoning:
- Droplinux/moduleparam.has completely unused.
-linux/array_size.hforARRAY_SIZE()
-linux/bitmap.hforfor_each_set_bit
-linux/errno.hfor error codes.
-linux/export.hfor EXPORT_SYMBOL*()
-linux/math64.hfordo_div- alternative would beasm/div64.h
-linux/minmax.hformin()
-linux/sysfs.hforsysfs_emit()
-linux/time64.hforUSEC_PER_MSEC
-linux/iio/buffer.hforiio_push_to_buffers_with_timestamp()
-asm/byteorder.hforle16_to_cpu()
Change LGTM,
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 22 lines · On Mon, 7 Jul 2025 22:53:43 +0300 Andy Shevchenko…
Quoted 8 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
Motivated by the W=1 warning about
export.hthat was introduced this cycle this is an attempt to apply an approximation of the principles of including whatever is used in the file directly.Helped by the include-what-you-use tool.
Quoted 12 lines
Reasoning:
- Droplinux/moduleparam.has completely unused.
-linux/array_size.hforARRAY_SIZE()
-linux/bitmap.hforfor_each_set_bit
-linux/errno.hfor error codes.
-linux/export.hfor EXPORT_SYMBOL*()
-linux/math64.hfordo_div- alternative would beasm/div64.h
-linux/minmax.hformin()
-linux/sysfs.hforsysfs_emit()
-linux/time64.hforUSEC_PER_MSEC
-linux/iio/buffer.hforiio_push_to_buffers_with_timestamp()
-asm/byteorder.hforle16_to_cpu()
Quoted 3 lines
Change LGTM,
Reviewed-by Andy Shevchenko <[email protected]>
Applied.
Thanks,
Jonathan