* [PATCH] iio: accel: kionix-kx022a: Apply approximate iwyu principles to includes
@ 2025-06-29 18:36 Jonathan Cameron
2025-06-29 18:43 ` Jonathan Cameron
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Jonathan Cameron @ 2025-06-29 18:36 UTC (permalink / raw)
To: linux-iio, Nuno Sá, Andy Shevchenko, David Lechner,
Matti Vaittinen
Cc: Jonathan Cameron
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
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()
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
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(-)
diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c
index 07dcf5f0599f..39485572a76b 100644
--- a/drivers/iio/accel/kionix-kx022a.c
+++ b/drivers/iio/accel/kionix-kx022a.c
@@ -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"
/*
--
2.50.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH] iio: accel: kionix-kx022a: Apply approximate iwyu principles to includes 2025-06-29 18:36 [PATCH] iio: accel: kionix-kx022a: Apply approximate iwyu principles to includes Jonathan Cameron @ 2025-06-29 18:43 ` Jonathan Cameron 2025-06-30 10:42 ` Andy Shevchenko 2025-06-30 10:40 ` Andy Shevchenko 2025-07-07 19:53 ` Andy Shevchenko 2 siblings, 1 reply; 10+ messages in thread From: Jonathan Cameron @ 2025-06-29 18:43 UTC (permalink / raw) To: linux-iio, Nuno Sá, Andy Shevchenko, David Lechner, Matti Vaittinen Cc: Jonathan Cameron On Sun, 29 Jun 2025 19:36:49 +0100 Jonathan Cameron <jic23@kernel.org> wrote: > From: Jonathan Cameron <Jonathan.Cameron@huawei.com> > > 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() > > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> > --- > > 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/20211003153306.391766-1-jic23@kernel.org/ 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 > --- > drivers/iio/accel/kionix-kx022a.c | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c > index 07dcf5f0599f..39485572a76b 100644 > --- a/drivers/iio/accel/kionix-kx022a.c > +++ b/drivers/iio/accel/kionix-kx022a.c > @@ -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" > > /* ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] iio: accel: kionix-kx022a: Apply approximate iwyu principles to includes 2025-06-29 18:43 ` Jonathan Cameron @ 2025-06-30 10:42 ` Andy Shevchenko 2025-06-30 14:06 ` Jonathan Cameron 0 siblings, 1 reply; 10+ messages in thread From: Andy Shevchenko @ 2025-06-30 10:42 UTC (permalink / raw) To: Jonathan Cameron Cc: linux-iio, Nuno Sá, Andy Shevchenko, David Lechner, Matti Vaittinen, Jonathan Cameron On Sun, Jun 29, 2025 at 07:43:36PM +0100, Jonathan Cameron wrote: > On Sun, 29 Jun 2025 19:36:49 +0100 > Jonathan Cameron <jic23@kernel.org> wrote: > > > From: Jonathan Cameron <Jonathan.Cameron@huawei.com> > > > > 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() > > > > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> > > --- > > > > 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/20211003153306.391766-1-jic23@kernel.org/ > > 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 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? -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] iio: accel: kionix-kx022a: Apply approximate iwyu principles to includes 2025-06-30 10:42 ` Andy Shevchenko @ 2025-06-30 14:06 ` Jonathan Cameron 2025-07-12 16:52 ` Tanzir Hasan 0 siblings, 1 reply; 10+ messages in thread From: Jonathan Cameron @ 2025-06-30 14:06 UTC (permalink / raw) To: Andy Shevchenko Cc: Jonathan Cameron, linux-iio, Nuno Sá, Andy Shevchenko, David Lechner, Matti Vaittinen, Nick Desaulniers, Tanzir Hasan On Mon, 30 Jun 2025 13:42:00 +0300 Andy Shevchenko <andriy.shevchenko@intel.com> wrote: > On Sun, Jun 29, 2025 at 07:43:36PM +0100, Jonathan Cameron wrote: > > On Sun, 29 Jun 2025 19:36:49 +0100 > > Jonathan Cameron <jic23@kernel.org> wrote: > > > > > From: Jonathan Cameron <Jonathan.Cameron@huawei.com> > > > > > > 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() > > > > > > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> > > > --- > > > > > > 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/20211003153306.391766-1-jic23@kernel.org/ > > > > 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 > > 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? 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] iio: accel: kionix-kx022a: Apply approximate iwyu principles to includes 2025-06-30 14:06 ` Jonathan Cameron @ 2025-07-12 16:52 ` Tanzir Hasan 0 siblings, 0 replies; 10+ messages in thread From: Tanzir Hasan @ 2025-07-12 16:52 UTC (permalink / raw) To: Jonathan Cameron Cc: Andy Shevchenko, Jonathan Cameron, linux-iio, Nuno Sá, Andy Shevchenko, David Lechner, Matti Vaittinen, Nick Desaulniers On Mon, Jun 30, 2025 at 10:06 AM Jonathan Cameron <Jonathan.Cameron@huawei.com> wrote: > > On Mon, 30 Jun 2025 13:42:00 +0300 > Andy Shevchenko <andriy.shevchenko@intel.com> wrote: > > > On Sun, Jun 29, 2025 at 07:43:36PM +0100, Jonathan Cameron wrote: > > > On Sun, 29 Jun 2025 19:36:49 +0100 > > > Jonathan Cameron <jic23@kernel.org> wrote: > > > > > > > From: Jonathan Cameron <Jonathan.Cameron@huawei.com> > > > > > > > > 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() > > > > > > > > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> > > > > --- > > > > > > > > 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/20211003153306.391766-1-jic23@kernel.org/ > > > > > > 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 > > > > 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? > > 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. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] iio: accel: kionix-kx022a: Apply approximate iwyu principles to includes 2025-06-29 18:36 [PATCH] iio: accel: kionix-kx022a: Apply approximate iwyu principles to includes Jonathan Cameron 2025-06-29 18:43 ` Jonathan Cameron @ 2025-06-30 10:40 ` Andy Shevchenko 2025-07-06 17:13 ` Jonathan Cameron 2025-07-07 19:53 ` Andy Shevchenko 2 siblings, 1 reply; 10+ messages in thread From: Andy Shevchenko @ 2025-06-30 10:40 UTC (permalink / raw) To: Jonathan Cameron Cc: linux-iio, Nuno Sá, Andy Shevchenko, David Lechner, Matti Vaittinen, Jonathan Cameron On Sun, Jun 29, 2025 at 07:36:49PM +0100, Jonathan Cameron wrote: > From: Jonathan Cameron <Jonathan.Cameron@huawei.com> > > 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() > > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> > --- > > 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. -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] iio: accel: kionix-kx022a: Apply approximate iwyu principles to includes 2025-06-30 10:40 ` Andy Shevchenko @ 2025-07-06 17:13 ` Jonathan Cameron 2025-07-10 6:53 ` Matti Vaittinen 0 siblings, 1 reply; 10+ messages in thread From: Jonathan Cameron @ 2025-07-06 17:13 UTC (permalink / raw) To: Andy Shevchenko Cc: linux-iio, Nuno Sá, Andy Shevchenko, David Lechner, Matti Vaittinen, Jonathan Cameron On Mon, 30 Jun 2025 13:40:32 +0300 Andy Shevchenko <andriy.shevchenko@intel.com> wrote: > On Sun, Jun 29, 2025 at 07:36:49PM +0100, Jonathan Cameron wrote: > > From: Jonathan Cameron <Jonathan.Cameron@huawei.com> > > > > 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() > > > > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> > > --- > > > > 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. > 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? :) ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] iio: accel: kionix-kx022a: Apply approximate iwyu principles to includes 2025-07-06 17:13 ` Jonathan Cameron @ 2025-07-10 6:53 ` Matti Vaittinen 0 siblings, 0 replies; 10+ messages in thread From: Matti Vaittinen @ 2025-07-10 6:53 UTC (permalink / raw) To: Jonathan Cameron, Andy Shevchenko Cc: linux-iio, Nuno Sá, Andy Shevchenko, David Lechner, Jonathan Cameron On 06/07/2025 20:13, Jonathan Cameron wrote: > On Mon, 30 Jun 2025 13:40:32 +0300 > Andy Shevchenko <andriy.shevchenko@intel.com> wrote: > >> On Sun, Jun 29, 2025 at 07:36:49PM +0100, Jonathan Cameron wrote: >>> From: Jonathan Cameron <Jonathan.Cameron@huawei.com> >>> >>> 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() >>> >>> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> >>> --- >>> >>> 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. >> > 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] iio: accel: kionix-kx022a: Apply approximate iwyu principles to includes 2025-06-29 18:36 [PATCH] iio: accel: kionix-kx022a: Apply approximate iwyu principles to includes Jonathan Cameron 2025-06-29 18:43 ` Jonathan Cameron 2025-06-30 10:40 ` Andy Shevchenko @ 2025-07-07 19:53 ` Andy Shevchenko 2025-07-09 13:32 ` Jonathan Cameron 2 siblings, 1 reply; 10+ messages in thread From: Andy Shevchenko @ 2025-07-07 19:53 UTC (permalink / raw) To: Jonathan Cameron Cc: linux-iio, Nuno Sá, Andy Shevchenko, David Lechner, Matti Vaittinen, Jonathan Cameron On Sun, Jun 29, 2025 at 07:36:49PM +0100, Jonathan Cameron wrote: > From: Jonathan Cameron <Jonathan.Cameron@huawei.com> > > 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() Change LGTM, Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] iio: accel: kionix-kx022a: Apply approximate iwyu principles to includes 2025-07-07 19:53 ` Andy Shevchenko @ 2025-07-09 13:32 ` Jonathan Cameron 0 siblings, 0 replies; 10+ messages in thread From: Jonathan Cameron @ 2025-07-09 13:32 UTC (permalink / raw) To: Andy Shevchenko Cc: linux-iio, Nuno Sá, Andy Shevchenko, David Lechner, Matti Vaittinen, Jonathan Cameron On Mon, 7 Jul 2025 22:53:43 +0300 Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > On Sun, Jun 29, 2025 at 07:36:49PM +0100, Jonathan Cameron wrote: > > From: Jonathan Cameron <Jonathan.Cameron@huawei.com> > > > > 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() > > Change LGTM, > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > Applied. Thanks, Jonathan ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-07-12 16:52 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-06-29 18:36 [PATCH] iio: accel: kionix-kx022a: Apply approximate iwyu principles to includes Jonathan Cameron 2025-06-29 18:43 ` Jonathan Cameron 2025-06-30 10:42 ` Andy Shevchenko 2025-06-30 14:06 ` Jonathan Cameron 2025-07-12 16:52 ` Tanzir Hasan 2025-06-30 10:40 ` Andy Shevchenko 2025-07-06 17:13 ` Jonathan Cameron 2025-07-10 6:53 ` Matti Vaittinen 2025-07-07 19:53 ` Andy Shevchenko 2025-07-09 13:32 ` Jonathan Cameron
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox