Skip to contentSkip to conversation

IIO: Bring core header includes up to date.

RFC PATCH In review Jonathan Cameron 3 participants 18 messages Oct 3, 2021 – Nov 1, 2021 IIO

lore
Share & tools
lore

Jonathan Cameron

author maintainer
#0 lore raw

cover IIO: Bring core header includes up to date.

From: Jonathan Cameron <[email protected]>

The includes from the various IIO core files have bitrotted over time (and probably were not great in the first place).

This series is based loosely on the suggests the include-what-you-use tool provides but with a lot of discretion applied. Note that tool will tell you:
1) What includes provide elements directly used in a given .c file.
2) What includes are providing nothing that is directly used in the .c file.
3) It will not follow 'include chains', then concept being that anything used should be defined in a header directly included.
It can't always distinguish between different paths to the header and knows nothing about intended include structures in the kernel. (for example including eventpoll.h directly is not intended to be safe,
instead poll.h should be used).

In recent times a lot of code has moved around in IIO and as a result often headers have gotten left behind or haven't made the move along with the code they were there to support.

I made some decisions to reduce includes.

#include <linux/device.h>
can be assumed to bring in dev_printk.h and device/bus.h so don't include those directly.
#include <linux/err.h>
is a good general header to bring in errno.h as well as the various PTR_ERR() macros and similar.
#include <linux/poll.h>
brings in everything related to polling.
#include <linux/irq.h> or <linux/interrupt.h> as appropriate will bring in irqreturn.h.

(probably some other cases I've forgotten about).

Andy has been working on breaking up some of the headers that tend to get included everywhere because they are a pile of unrelated things. Some impact of that can be seen in this series.

I would like to move IIO in the right direction even if we then end up with some additional churn in future reflecting changes in the headers we are using. This is an RFC primarily because there is a lot of 'interpretation' involved so I'd like to get high level feedback.

I've included below the suggestions iwyu made for reference. As you can see the raw output is mostly useful for highlighting things that should not be there and roughly what should be.

drivers/iio/buffer/kfifo_buf.c should add these lines:

#include <stddef.h>                  // for size_t, NULL
#include "asm-generic/errno-base.h"  // for EINVAL, EBUSY, ENOMEM
#include "linux/compiler_types.h"    // for __user, inline
#include "linux/errno.h"             // for ERESTARTSYS
#include "linux/export.h"            // for EXPORT_SYMBOL, EXPORT_SYMBOL_GPL
#include "linux/gfp.h"               // for GFP_KERNEL
#include "linux/log2.h"              // for roundup_pow_of_two
#include "linux/stddef.h"            // for true, false
#include "vdso/limits.h"             // for UINT_MAX

struct attribute;

drivers/iio/buffer/kfifo_buf.c should remove these lines:
- #include <linux/poll.h> // lines 14-14
- #include <linux/sched.h> // lines 13-13
- #include <linux/workqueue.h> // lines 6-6

The full include-list for drivers/iio/buffer/kfifo_buf.c:

#include <linux/device.h>            // for devres_add, devres_free, devres_...
#include <linux/iio/buffer.h>        // for iio_device_attach_buffer
#include <linux/iio/buffer_impl.h>   // for iio_buffer, iio_buffer_init, iio...
#include <linux/iio/iio.h>           // for iio_dev, INDIO_BUFFER_SOFTWARE
#include <linux/iio/kfifo_buf.h>     // for devm_iio_kfifo_buffer_setup_ext
#include <linux/kernel.h>            // for container_of
#include <linux/kfifo.h>             // for __kfifo_alloc, kfifo_free, kfifo
#include <linux/module.h>            // for MODULE_LICENSE
#include <linux/mutex.h>             // for mutex_unlock, mutex_lock, mutex_...
#include <linux/slab.h>              // for kfree, kzalloc
#include <stddef.h>                  // for size_t, NULL
#include "asm-generic/errno-base.h"  // for EINVAL, EBUSY, ENOMEM
#include "linux/compiler_types.h"    // for __user, inline
#include "linux/errno.h"             // for ERESTARTSYS
#include "linux/export.h"            // for EXPORT_SYMBOL, EXPORT_SYMBOL_GPL
#include "linux/gfp.h"               // for GFP_KERNEL
#include "linux/log2.h"              // for roundup_pow_of_two
#include "linux/stddef.h"            // for true, false
#include "vdso/limits.h"             // for UINT_MAX

struct attribute;

drivers/iio/buffer/industrialio-buffer-cb.c should add these lines:

#include <stddef.h>                                  // for NULL, size_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for set_bit
#include "asm-generic/errno-base.h"                  // for EINVAL, ENOMEM
#include "linux/bitmap.h"                            // for bitmap_free, bit...
#include "linux/dev_printk.h"                        // for dev_err
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/list.h"                              // for INIT_LIST_HEAD

struct device;

drivers/iio/buffer/industrialio-buffer-cb.c should remove these lines:

The full include-list for drivers/iio/buffer/industrialio-buffer-cb.c:

#include <linux/err.h>                               // for ERR_PTR, IS_ERR
#include <linux/export.h>                            // for EXPORT_SYMBOL_GPL
#include <linux/iio/buffer_impl.h>                   // for iio_buffer, iio_...
#include <linux/iio/consumer.h>                      // for iio_channel, iio...
#include <linux/iio/iio.h>                           // for INDIO_BUFFER_SOF...
#include <linux/kernel.h>                            // for container_of
#include <linux/module.h>                            // for MODULE_AUTHOR
#include <linux/slab.h>                              // for kfree, kzalloc
#include <stddef.h>                                  // for NULL, size_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for set_bit
#include "asm-generic/errno-base.h"                  // for EINVAL, ENOMEM
#include "linux/bitmap.h"                            // for bitmap_free, bit...
#include "linux/dev_printk.h"                        // for dev_err
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/list.h"                              // for INIT_LIST_HEAD

struct device;

drivers/iio/buffer/industrialio-triggered-buffer.c should add these lines:

#include <stddef.h>                      // for NULL
#include "asm-generic/errno-base.h"      // for ENOMEM
#include "linux/device.h"                // for devm_add_action_or_reset
#include "linux/interrupt.h"             // for IRQF_ONESHOT
#include "linux/irqreturn.h"             // for irqreturn_t

struct attribute;

drivers/iio/buffer/industrialio-triggered-buffer.c should remove these lines:
- #include <linux/kernel.h> // lines 7-7

The full include-list for drivers/iio/buffer/industrialio-triggered-buffer.c:

#include <linux/export.h>                // for EXPORT_SYMBOL, EXPORT_SYMBOL...
#include <linux/iio/buffer.h>            // for iio_device_attach_buffer
#include <linux/iio/buffer_impl.h>       // for iio_buffer
#include <linux/iio/iio.h>               // for iio_dev, iio_device_id, INDI...
#include <linux/iio/kfifo_buf.h>         // for iio_kfifo_free, iio_kfifo_al...
#include <linux/iio/trigger_consumer.h>  // for iio_dealloc_pollfunc, iio_al...
#include <linux/iio/triggered_buffer.h>  // for devm_iio_triggered_buffer_se...
#include <linux/module.h>                // for MODULE_AUTHOR, MODULE_DESCRI...
#include <stddef.h>                      // for NULL
#include "asm-generic/errno-base.h"      // for ENOMEM
#include "linux/device.h"                // for devm_add_action_or_reset
#include "linux/interrupt.h"             // for IRQF_ONESHOT
#include "linux/irqreturn.h"             // for irqreturn_t

struct attribute;

drivers/iio/industrialio-triggered-event.c should add these lines:

#include <stddef.h>                      // for NULL
#include "asm-generic/errno-base.h"      // for ENOMEM
#include "linux/interrupt.h"             // for IRQF_ONESHOT
#include "linux/irqreturn.h"             // for irqreturn_t

drivers/iio/industrialio-triggered-event.c should remove these lines:
- #include <linux/kernel.h> // lines 6-6

The full include-list for drivers/iio/industrialio-triggered-event.c:

#include <linux/export.h>                // for EXPORT_SYMBOL
#include <linux/iio/iio.h>               // for iio_dev, iio_device_id, INDI...
#include <linux/iio/trigger_consumer.h>  // for iio_alloc_pollfunc, iio_deal...
#include <linux/iio/triggered_event.h>   // for iio_triggered_event_cleanup
#include <linux/module.h>                // for MODULE_AUTHOR, MODULE_DESCRI...
#include <stddef.h>                      // for NULL
#include "asm-generic/errno-base.h"      // for ENOMEM
#include "linux/interrupt.h"             // for IRQF_ONESHOT
#include "linux/irqreturn.h"             // for irqreturn_t

drivers/iio/industrialio-event.c should add these lines:

#include <asm/bitops.h>                              // for test_bit
#include <stddef.h>                                  // for NULL, size_t
#include <sys/types.h>                               // for ssize_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit, test_...
#include "asm-generic/errno-base.h"                  // for EINVAL, ENODEV
#include "asm-generic/fcntl.h"                       // for O_NONBLOCK, O_CL...
#include "asm-generic/int-ll64.h"                    // for s64, u64
#include "asm/string_64.h"                           // for memcpy
#include "linux/bitops.h"                            // for for_each_set_bit
#include "linux/compiler_types.h"                    // for __user, inline
#include "linux/errno.h"                             // for ERESTARTSYS
#include "linux/eventpoll.h"                         // for EPOLLIN, EPOLLRD...
#include "linux/export.h"                            // for EXPORT_SYMBOL
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/iio/events.h"                        // for iio_event_data
#include "linux/iio/types.h"                         // for iio_event_direction
#include "linux/kstrtox.h"                           // for strtobool
#include "linux/list.h"                              // for INIT_LIST_HEAD
#include "linux/mutex.h"                             // for mutex_lock_inter...
#include "linux/stddef.h"                            // for false, true
#include "linux/sysfs.h"                             // for attribute_group
#include "linux/types.h"                             // for list_head, bool

drivers/iio/industrialio-event.c should remove these lines:
- #include <linux/iio/events.h> // lines 24-24
- #include <linux/module.h> // lines 14-14
- #include <linux/sched.h> // lines 16-16

The full include-list for drivers/iio/industrialio-event.c:

#include <asm/bitops.h>                              // for test_bit
#include <linux/anon_inodes.h>                       // for anon_inode_getfd
#include <linux/device.h>                            // for device_attribute
#include <linux/fs.h>                                // for file, noop_llseek
#include <linux/iio/iio-opaque.h>                    // for iio_dev_opaque
#include <linux/iio/iio.h>                           // for iio_dev, iio_eve...
#include <linux/iio/sysfs.h>                         // for iio_dev_attr
#include <linux/kernel.h>                            // for kasprintf, ARRAY...
#include <linux/kfifo.h>                             // for kfifo_is_empty
#include <linux/poll.h>                              // for poll_wait
#include <linux/slab.h>                              // for kfree, kcalloc
#include <linux/uaccess.h>                           // for copy_to_user
#include <linux/wait.h>                              // for init_waitqueue_head
#include <stddef.h>                                  // for NULL, size_t
#include <sys/types.h>                               // for ssize_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit, test_...
#include "asm-generic/errno-base.h"                  // for EINVAL, ENODEV
#include "asm-generic/fcntl.h"                       // for O_NONBLOCK, O_CL...
#include "asm-generic/int-ll64.h"                    // for s64, u64
#include "asm/string_64.h"                           // for memcpy
#include "iio_core.h"                                // for iio_free_chan_de...
#include "linux/bitops.h"                            // for for_each_set_bit
#include "linux/compiler_types.h"                    // for __user, inline
#include "linux/errno.h"                             // for ERESTARTSYS
#include "linux/eventpoll.h"                         // for EPOLLIN, EPOLLRD...
#include "linux/export.h"                            // for EXPORT_SYMBOL
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/iio/events.h"                        // for iio_event_data
#include "linux/iio/types.h"                         // for iio_event_direction
#include "linux/kstrtox.h"                           // for strtobool
#include "linux/list.h"                              // for INIT_LIST_HEAD
#include "linux/mutex.h"                             // for mutex_lock_inter...
#include "linux/stddef.h"                            // for false, true
#include "linux/sysfs.h"                             // for attribute_group
#include "linux/types.h"                             // for list_head, bool

drivers/iio/industrialio-core.c should add these lines:

#include <asm/bug.h>                                 // for WARN
#include <linux/ktime.h>                             // for ktime_get_bootti...
#include <stddef.h>                                  // for NULL, size_t
#include <stdint.h>                                  // for uintptr_t
#include <sys/types.h>                               // for ssize_t, dev_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit, test_...
#include "asm-generic/errno-base.h"                  // for EINVAL, EBUSY
#include "asm-generic/int-ll64.h"                    // for s64, u64
#include "asm/bug.h"                                 // for BUG
#include "asm/page_types.h"                          // for PAGE_SIZE
#include "asm/string_64.h"                           // for memcpy
#include "generated/autoconf.h"                      // for CONFIG_DEBUG_FS
#include "linux/align.h"                             // for ALIGN
#include "linux/bitops.h"                            // for for_each_set_bit
#include "linux/compiler_attributes.h"               // for fallthrough
#include "linux/compiler_types.h"                    // for __user
#include "linux/dev_printk.h"                        // for dev_err, dev_info
#include "linux/device/bus.h"                        // for bus_unregister
#include "linux/export.h"                            // for EXPORT_SYMBOL_GPL
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/hrtimer.h"                           // for hrtimer_resolution
#include "linux/iio/types.h"                         // for IIO_VAL_INT, IIO...
#include "linux/init.h"                              // for __exit, __init
#include "linux/kstrtox.h"                           // for kstrtoint
#include "linux/ktime.h"                             // for ktime_to_ns
#include "linux/list.h"                              // for INIT_LIST_HEAD
#include "linux/math.h"                              // for abs
#include "linux/math64.h"                            // for div_s64_rem, div...
#include "linux/minmax.h"                            // for min_t
#include "linux/of.h"                                // for of_get_property
#include "linux/printk.h"                            // for pr_err
#include "linux/stat.h"                              // for S_IRUGO, S_IWUSR
#include "linux/stddef.h"                            // for false, true
#include "linux/string.h"                            // for sysfs_streq, str...
#include "linux/sysfs.h"                             // for sysfs_emit_at
#include "linux/time.h"                              // for CLOCK_BOOTTIME
#include "linux/time64.h"                            // for timespec64_to_ns
#include "linux/timex.h"                             // for shift_right
#include "linux/types.h"                             // for list_head, bool
#include "linux/uaccess.h"                           // for copy_from_user
#include "vdso/ktime.h"                              // for LOW_RES_NSEC

struct iio_buffer;

drivers/iio/industrialio-core.c should remove these lines:
- #include <linux/anon_inodes.h> // lines 24-24
- #include <linux/iio/buffer.h> // lines 33-33
- #include <linux/iio/buffer_impl.h> // lines 34-34
- #include <linux/iio/events.h> // lines 32-32
- #include <linux/poll.h> // lines 18-18
- #include <linux/sched.h> // lines 20-20
- #include <linux/wait.h> // lines 21-21

The full include-list for drivers/iio/industrialio-core.c:

#include <asm/bug.h>                                 // for WARN
#include <linux/cdev.h>                              // for cdev_init, cdev_...
#include <linux/debugfs.h>                           // for debugfs_create_dir
#include <linux/device.h>                            // for device, device_a...
#include <linux/err.h>                               // for IS_ERR, PTR_ERR
#include <linux/fs.h>                                // for noop_llseek, inode
#include <linux/idr.h>                               // for DEFINE_IDA, ida_...
#include <linux/iio/iio-opaque.h>                    // for iio_dev_opaque
#include <linux/iio/iio.h>                           // for iio_dev, iio_cha...
#include <linux/iio/sysfs.h>                         // for iio_dev_attr
#include <linux/kdev_t.h>                            // for MAJOR, MKDEV
#include <linux/kernel.h>                            // for kasprintf, sscanf
#include <linux/ktime.h>                             // for ktime_get_bootti...
#include <linux/module.h>                            // for MODULE_AUTHOR
#include <linux/mutex.h>                             // for mutex_unlock
#include <linux/property.h>                          // for device_property_...
#include <linux/slab.h>                              // for kfree, kzalloc
#include <stddef.h>                                  // for NULL, size_t
#include <stdint.h>                                  // for uintptr_t
#include <sys/types.h>                               // for ssize_t, dev_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit, test_...
#include "asm-generic/errno-base.h"                  // for EINVAL, EBUSY
#include "asm-generic/int-ll64.h"                    // for s64, u64
#include "asm/bug.h"                                 // for BUG
#include "asm/page_types.h"                          // for PAGE_SIZE
#include "asm/string_64.h"                           // for memcpy
#include "generated/autoconf.h"                      // for CONFIG_DEBUG_FS
#include "iio_core.h"                                // for iio_ioctl_handler
#include "iio_core_trigger.h"                        // for iio_device_regis...
#include "linux/align.h"                             // for ALIGN
#include "linux/bitops.h"                            // for for_each_set_bit
#include "linux/compiler_attributes.h"               // for fallthrough
#include "linux/compiler_types.h"                    // for __user
#include "linux/dev_printk.h"                        // for dev_err, dev_info
#include "linux/device/bus.h"                        // for bus_unregister
#include "linux/export.h"                            // for EXPORT_SYMBOL_GPL
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/hrtimer.h"                           // for hrtimer_resolution
#include "linux/iio/types.h"                         // for IIO_VAL_INT, IIO...
#include "linux/init.h"                              // for __exit, __init
#include "linux/kstrtox.h"                           // for kstrtoint
#include "linux/ktime.h"                             // for ktime_to_ns
#include "linux/list.h"                              // for INIT_LIST_HEAD
#include "linux/math.h"                              // for abs
#include "linux/math64.h"                            // for div_s64_rem, div...
#include "linux/minmax.h"                            // for min_t
#include "linux/of.h"                                // for of_get_property
#include "linux/printk.h"                            // for pr_err
#include "linux/stat.h"                              // for S_IRUGO, S_IWUSR
#include "linux/stddef.h"                            // for false, true
#include "linux/string.h"                            // for sysfs_streq, str...
#include "linux/sysfs.h"                             // for sysfs_emit_at
#include "linux/time.h"                              // for CLOCK_BOOTTIME
#include "linux/time64.h"                            // for timespec64_to_ns
#include "linux/timex.h"                             // for shift_right
#include "linux/types.h"                             // for list_head, bool
#include "linux/uaccess.h"                           // for copy_from_user
#include "vdso/ktime.h"                              // for LOW_RES_NSEC

struct iio_buffer;

drivers/iio/industrialio-configfs.c should add these lines:
#include "linux/export.h" // for EXPORT_SYMBOL, THIS_MODULE
#include "linux/mutex.h" // for mutex, __MUTEX_INITIALIZER

drivers/iio/industrialio-configfs.c should remove these lines:
- #include <linux/iio/configfs.h> // lines 15-15
- #include <linux/iio/iio.h> // lines 14-14
- #include <linux/kmod.h> // lines 11-11
- #include <linux/slab.h> // lines 12-12

The full include-list for drivers/iio/industrialio-configfs.c:

#include <linux/configfs.h>  // for configfs_subsystem, config_group_init
#include <linux/init.h>      // for __exit, __init
#include <linux/module.h>    // for MODULE_AUTHOR, MODULE_DESCRIPTION, MODUL...
#include "linux/export.h"    // for EXPORT_SYMBOL, THIS_MODULE
#include "linux/mutex.h"     // for mutex, __MUTEX_INITIALIZER

drivers/iio/inkern.c should add these lines:

#include <stddef.h>                  // for NULL, size_t
#include <stdint.h>                  // for uint32_t
#include <sys/types.h>               // for ssize_t
#include "asm-generic/errno-base.h"  // for ENODEV, EINVAL, ENOMEM
#include "asm-generic/int-ll64.h"    // for s64
#include "generated/autoconf.h"      // for CONFIG_OF
#include "linux/dev_printk.h"        // for dev_err
#include "linux/device.h"            // for devm_add_action_or_reset, dev_name
#include "linux/device/bus.h"        // for bus_find_device
#include "linux/errno.h"             // for EPROBE_DEFER
#include "linux/gfp.h"               // for GFP_KERNEL
#include "linux/iio/types.h"         // for iio_chan_info_enum, IIO_CHAN_INF...
#include "linux/list.h"              // for list_add_tail, list_del, list_fo...
#include "linux/math64.h"            // for div_s64
#include "linux/printk.h"            // for pr_err
#include "linux/string.h"            // for strcmp
#include "linux/types.h"             // for list_head

drivers/iio/inkern.c should remove these lines:

The full include-list for drivers/iio/inkern.c:

#include <linux/err.h>               // for ERR_PTR, IS_ERR, PTR_ERR
#include <linux/export.h>            // for EXPORT_SYMBOL_GPL
#include <linux/iio/consumer.h>      // for iio_channel, devm_iio_channel_get
#include <linux/iio/driver.h>        // for devm_iio_map_array_register, iio...
#include <linux/iio/iio-opaque.h>    // for iio_dev_opaque, to_iio_dev_opaque
#include <linux/iio/iio.h>           // for iio_dev, iio_device_put, iio_cha...
#include <linux/iio/machine.h>       // for iio_map
#include <linux/mutex.h>             // for mutex_unlock, mutex_lock, mutex
#include <linux/of.h>                // for of_phandle_args, of_parse_phandl...
#include <linux/slab.h>              // for kfree, kzalloc, kcalloc
#include <stddef.h>                  // for NULL, size_t
#include <stdint.h>                  // for uint32_t
#include <sys/types.h>               // for ssize_t
#include "asm-generic/errno-base.h"  // for ENODEV, EINVAL, ENOMEM
#include "asm-generic/int-ll64.h"    // for s64
#include "generated/autoconf.h"      // for CONFIG_OF
#include "iio_core.h"                // for iio_device_type
#include "linux/dev_printk.h"        // for dev_err
#include "linux/device.h"            // for devm_add_action_or_reset, dev_name
#include "linux/device/bus.h"        // for bus_find_device
#include "linux/errno.h"             // for EPROBE_DEFER
#include "linux/gfp.h"               // for GFP_KERNEL
#include "linux/iio/types.h"         // for iio_chan_info_enum, IIO_CHAN_INF...
#include "linux/list.h"              // for list_add_tail, list_del, list_fo...
#include "linux/math64.h"            // for div_s64
#include "linux/printk.h"            // for pr_err
#include "linux/string.h"            // for strcmp
#include "linux/types.h"             // for list_head

drivers/iio/industrialio-sw-device.c should add these lines:

#include <stddef.h>                  // for NULL
#include "asm-generic/errno-base.h"  // for EBUSY, EINVAL
#include "linux/err.h"               // for IS_ERR, ERR_CAST, ERR_PTR, PTR_ERR
#include "linux/export.h"            // for EXPORT_SYMBOL, THIS_MODULE
#include "linux/mutex.h"             // for mutex_lock, mutex_unlock, mutex
#include "linux/printk.h"            // for pr_err
#include "linux/string.h"            // for strlen, strcmp
#include "linux/types.h"             // for list_head

drivers/iio/industrialio-sw-device.c should remove these lines:
- #include <linux/kmod.h> // lines 10-10
- #include <linux/slab.h> // lines 12-12

The full include-list for drivers/iio/industrialio-sw-device.c:

#include <linux/configfs.h>          // for configfs_register_default_group
#include <linux/iio/configfs.h>      // for iio_configfs_subsys
#include <linux/iio/sw_device.h>     // for iio_sw_device_type, iio_sw_device
#include <linux/init.h>              // for __exit, __init
#include <linux/list.h>              // for list_add_tail, list_del, LIST_HEAD
#include <linux/module.h>            // for module_put, try_module_get, MODU...
#include <stddef.h>                  // for NULL
#include "asm-generic/errno-base.h"  // for EBUSY, EINVAL
#include "linux/err.h"               // for IS_ERR, ERR_CAST, ERR_PTR, PTR_ERR
#include "linux/export.h"            // for EXPORT_SYMBOL, THIS_MODULE
#include "linux/mutex.h"             // for mutex_lock, mutex_unlock, mutex
#include "linux/printk.h"            // for pr_err
#include "linux/string.h"            // for strlen, strcmp
#include "linux/types.h"             // for list_head

drivers/iio/industrialio-trigger.c should add these lines:

#include <asm/bug.h>                                 // for WARN_ON
#include <linux/irq.h>                               // for generic_handle_irq
#include <stdarg.h>                                  // for va_list
#include <stddef.h>                                  // for NULL, size_t
#include <sys/types.h>                               // for ssize_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit
#include "asm-generic/errno-base.h"                  // for EINVAL, EBUSY
#include "generated/autoconf.h"                      // for CONFIG_IIO_CONSU...
#include "linux/atomic/atomic-instrumented.h"        // for atomic_read, ato...
#include "linux/bitmap.h"                            // for bitmap_empty
#include "linux/compiler_attributes.h"               // for __printf
#include "linux/export.h"                            // for EXPORT_SYMBOL
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/irq.h"                               // for irq_data_get_irq...
#include "linux/irqreturn.h"                         // for irqreturn_t, IRQ...
#include "linux/log2.h"                              // for ilog2
#include "linux/module.h"                            // for module_put, __mo...
#include "linux/mutex.h"                             // for mutex_unlock
#include "linux/printk.h"                            // for pr_err
#include "linux/stat.h"                              // for S_IRUGO, S_IWUSR
#include "linux/stdarg.h"                            // for va_end, va_start
#include "linux/stddef.h"                            // for true, false
#include "linux/string.h"                            // for strcmp, sysfs_streq
#include "linux/sysfs.h"                             // for sysfs_emit, ATTR...
#include "linux/types.h"                             // for list_head, bool

drivers/iio/industrialio-trigger.c should remove these lines:
- #include <linux/err.h> // lines 9-9

The full include-list for drivers/iio/industrialio-trigger.c:

#include <asm/bug.h>                                 // for WARN_ON
#include <linux/device.h>                            // for device, device_del
#include <linux/idr.h>                               // for ida_simple_remove
#include <linux/iio/iio-opaque.h>                    // for iio_dev_opaque
#include <linux/iio/iio.h>                           // for iio_dev, dev_to_...
#include <linux/iio/trigger.h>                       // for iio_trigger, iio...
#include <linux/iio/trigger_consumer.h>              // for iio_poll_func
#include <linux/interrupt.h>                         // for free_irq, reques...
#include <linux/irq.h>                               // for generic_handle_irq
#include <linux/kernel.h>                            // for kvasprintf, cont...
#include <linux/list.h>                              // for list_add_tail
#include <linux/slab.h>                              // for kfree, kmalloc
#include <stdarg.h>                                  // for va_list
#include <stddef.h>                                  // for NULL, size_t
#include <sys/types.h>                               // for ssize_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit
#include "asm-generic/errno-base.h"                  // for EINVAL, EBUSY
#include "generated/autoconf.h"                      // for CONFIG_IIO_CONSU...
#include "iio_core.h"                                // for iio_device_regis...
#include "iio_core_trigger.h"                        // for iio_device_regis...
#include "linux/atomic/atomic-instrumented.h"        // for atomic_read, ato...
#include "linux/bitmap.h"                            // for bitmap_empty
#include "linux/compiler_attributes.h"               // for __printf
#include "linux/export.h"                            // for EXPORT_SYMBOL
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/irq.h"                               // for irq_data_get_irq...
#include "linux/irqreturn.h"                         // for irqreturn_t, IRQ...
#include "linux/log2.h"                              // for ilog2
#include "linux/module.h"                            // for module_put, __mo...
#include "linux/mutex.h"                             // for mutex_unlock
#include "linux/printk.h"                            // for pr_err
#include "linux/stat.h"                              // for S_IRUGO, S_IWUSR
#include "linux/stdarg.h"                            // for va_end, va_start
#include "linux/stddef.h"                            // for true, false
#include "linux/string.h"                            // for strcmp, sysfs_streq
#include "linux/sysfs.h"                             // for sysfs_emit, ATTR...
#include "linux/types.h"                             // for list_head, bool

drivers/iio/industrialio-sw-trigger.c should add these lines:

#include <stddef.h>                  // for NULL
#include "asm-generic/errno-base.h"  // for EBUSY, EINVAL
#include "linux/err.h"               // for IS_ERR, ERR_CAST, ERR_PTR, PTR_ERR
#include "linux/export.h"            // for EXPORT_SYMBOL, THIS_MODULE
#include "linux/mutex.h"             // for mutex_lock, mutex_unlock, mutex
#include "linux/printk.h"            // for pr_err
#include "linux/string.h"            // for strlen, strcmp
#include "linux/types.h"             // for list_head

drivers/iio/industrialio-sw-trigger.c should remove these lines:
- #include <linux/kmod.h> // lines 10-10
- #include <linux/slab.h> // lines 12-12

The full include-list for drivers/iio/industrialio-sw-trigger.c:

#include <linux/configfs.h>          // for configfs_register_default_group
#include <linux/iio/configfs.h>      // for iio_configfs_subsys
#include <linux/iio/sw_trigger.h>    // for iio_sw_trigger_type, iio_sw_trigger
#include <linux/init.h>              // for __exit, __init
#include <linux/list.h>              // for list_add_tail, list_del, LIST_HEAD
#include <linux/module.h>            // for module_put, try_module_get, MODU...
#include <stddef.h>                  // for NULL
#include "asm-generic/errno-base.h"  // for EBUSY, EINVAL
#include "linux/err.h"               // for IS_ERR, ERR_CAST, ERR_PTR, PTR_ERR
#include "linux/export.h"            // for EXPORT_SYMBOL, THIS_MODULE
#include "linux/mutex.h"             // for mutex_lock, mutex_unlock, mutex
#include "linux/printk.h"            // for pr_err
#include "linux/string.h"            // for strlen, strcmp
#include "linux/types.h"             // for list_head

drivers/iio/industrialio-buffer.c should add these lines:

#include <asm/bitops.h>                              // for test_bit
#include <asm/bug.h>                                 // for WARN
#include <stddef.h>                                  // for size_t, NULL
#include <sys/types.h>                               // for ssize_t
#include "asm-generic/bitops/find.h"                 // for find_next_bit
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit, set_bit
#include "asm-generic/errno-base.h"                  // for ENOMEM, EINVAL
#include "asm-generic/fcntl.h"                       // for O_NONBLOCK, O_CL...
#include "asm-generic/int-ll64.h"                    // for u8
#include "asm/current.h"                             // for current
#include "asm/string_64.h"                           // for memcpy, memset
#include "linux/align.h"                             // for ALIGN
#include "linux/bitmap.h"                            // for bitmap_free, bit...
#include "linux/bitops.h"                            // for for_each_set_bit
#include "linux/compiler_types.h"                    // for __user
#include "linux/dev_printk.h"                        // for dev_dbg
#include "linux/errno.h"                             // for ERESTARTSYS
#include "linux/eventpoll.h"                         // for EPOLLIN, EPOLLRD...
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/iio/buffer.h"                        // for IIO_BUFFER_GET_F...
#include "linux/iio/types.h"                         // for IIO_TIMESTAMP
#include "linux/kconfig.h"                           // for __LITTLE_ENDIAN
#include "linux/kref.h"                              // for kref_get, kref_init
#include "linux/kstrtox.h"                           // for strtobool, kstrt...
#include "linux/list.h"                              // for list_empty, INIT...
#include "linux/math.h"                              // for roundup
#include "linux/minmax.h"                            // for max, min, min_t
#include "linux/mutex.h"                             // for mutex_lock, mute...
#include "linux/sched.h"                             // for MAX_SCHEDULE_TIM...
#include "linux/stat.h"                              // for S_IRUGO, S_IWUSR
#include "linux/stddef.h"                            // for false, true
#include "linux/string.h"                            // for kstrdup_const
#include "linux/sysfs.h"                             // for sysfs_emit, attr...
#include "linux/types.h"                             // for list_head, bool
#include "linux/uaccess.h"                           // for copy_from_user
#include "linux/wait.h"                              // for woken_wake_function

drivers/iio/industrialio-buffer.c should remove these lines:
- #include <linux/cdev.h> // lines 18-18

The full include-list for drivers/iio/industrialio-buffer.c:

#include <asm/bitops.h>                              // for test_bit
#include <asm/bug.h>                                 // for WARN
#include <linux/anon_inodes.h>                       // for anon_inode_getfd
#include <linux/device.h>                            // for device_attribute
#include <linux/export.h>                            // for EXPORT_SYMBOL_GPL
#include <linux/file.h>                              // for put_unused_fd
#include <linux/fs.h>                                // for file, noop_llseek
#include <linux/iio/buffer.h>                        // for iio_device_attac...
#include <linux/iio/buffer_impl.h>                   // for iio_buffer, iio_...
#include <linux/iio/iio-opaque.h>                    // for iio_dev_opaque
#include <linux/iio/iio.h>                           // for iio_dev, iio_cha...
#include <linux/iio/sysfs.h>                         // for iio_dev_attr
#include <linux/kernel.h>                            // for ARRAY_SIZE, cont...
#include <linux/poll.h>                              // for poll_wait
#include <linux/sched/signal.h>                      // for signal_pending
#include <linux/slab.h>                              // for kfree, kzalloc
#include <stddef.h>                                  // for size_t, NULL
#include <sys/types.h>                               // for ssize_t
#include "asm-generic/bitops/find.h"                 // for find_next_bit
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit, set_bit
#include "asm-generic/errno-base.h"                  // for ENOMEM, EINVAL
#include "asm-generic/fcntl.h"                       // for O_NONBLOCK, O_CL...
#include "asm-generic/int-ll64.h"                    // for u8
#include "asm/current.h"                             // for current
#include "asm/string_64.h"                           // for memcpy, memset
#include "iio_core.h"                                // for __iio_add_chan_d...
#include "iio_core_trigger.h"                        // for iio_trigger_deta...
#include "linux/align.h"                             // for ALIGN
#include "linux/bitmap.h"                            // for bitmap_free, bit...
#include "linux/bitops.h"                            // for for_each_set_bit
#include "linux/compiler_types.h"                    // for __user
#include "linux/dev_printk.h"                        // for dev_dbg
#include "linux/errno.h"                             // for ERESTARTSYS
#include "linux/eventpoll.h"                         // for EPOLLIN, EPOLLRD...
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/iio/buffer.h"                        // for IIO_BUFFER_GET_F...
#include "linux/iio/types.h"                         // for IIO_TIMESTAMP
#include "linux/kconfig.h"                           // for __LITTLE_ENDIAN
#include "linux/kref.h"                              // for kref_get, kref_init
#include "linux/kstrtox.h"                           // for strtobool, kstrt...
#include "linux/list.h"                              // for list_empty, INIT...
#include "linux/math.h"                              // for roundup
#include "linux/minmax.h"                            // for max, min, min_t
#include "linux/mutex.h"                             // for mutex_lock, mute...
#include "linux/sched.h"                             // for MAX_SCHEDULE_TIM...
#include "linux/stat.h"                              // for S_IRUGO, S_IWUSR
#include "linux/stddef.h"                            // for false, true
#include "linux/string.h"                            // for kstrdup_const
#include "linux/sysfs.h"                             // for sysfs_emit, attr...
#include "linux/types.h"                             // for list_head, bool
#include "linux/uaccess.h"                           // for copy_from_user
#include "linux/wait.h"                              // for woken_wake_function

Jonathan Cameron (11):
iio: industrialio-core: Reorder header includes to be alphabetical.
iio: industrialio-core - Bring includes up to date.
iio: industrialio-buffer.c: Bring includes up to date.
iio: industrialio-event.c: Bring includes up to date.
iio: industrialio-trigger.c: Bring includes up to date.
iio: inkern: Bring includes up to date.
iio: configfs: Bring includes up to date
iio: misc core files: Bring includes up to date
iio: industrialio-triggered-buffer: Bring includes up to date.
iio: industrialio-buffer-cb: Bring includes up to date.
iio: kfifo-buf.c: Bring includes up to date.

 drivers/iio/buffer/industrialio-buffer-cb.c   |  7 +++-
 .../buffer/industrialio-triggered-buffer.c    |  6 ++-
 drivers/iio/buffer/kfifo_buf.c                | 15 ++++---
 drivers/iio/industrialio-buffer.c             | 23 ++++++++--
 drivers/iio/industrialio-configfs.c           |  7 ++--
 drivers/iio/industrialio-core.c               | 42 ++++++++++++-------
 drivers/iio/industrialio-event.c              |  9 +++-
 drivers/iio/industrialio-sw-device.c          |  8 ++--
 drivers/iio/industrialio-sw-trigger.c         |  9 ++--
 drivers/iio/industrialio-trigger.c            | 15 +++++--
 drivers/iio/industrialio-triggered-event.c    |  3 +-
 drivers/iio/inkern.c                          |  7 +++-
 12 files changed, 107 insertions(+), 44 deletions(-)
Signature · 1 line
2.33.0
author maintainer
#1 lore raw

RFC PATCH 1/11 iio: industrialio-core: Reorder header includes to be alphabetical.

From: Jonathan Cameron <[email protected]>

All includes in alphabetical order, with the IIO specific headers in a separate block.

Note this is a precursor to refining which headers are included.

---
 drivers/iio/industrialio-core.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/iio/industrialio-core.c +11 -10
index 6afa70c89c80..d6c2875a832e 100644
@@ -8,22 +8,23 @@
 
 #define pr_fmt(fmt) "iio-core: " fmt
 
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/idr.h>
-#include <linux/kdev_t.h>
-#include <linux/err.h>
+#include <linux/anon_inodes.h>
 #include <linux/device.h>
+#include <linux/cdev.h>
+#include <linux/debugfs.h>
+#include <linux/err.h>
 #include <linux/fs.h>
+#include <linux/idr.h>
+#include <linux/kdev_t.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/poll.h>
 #include <linux/property.h>
 #include <linux/sched.h>
-#include <linux/wait.h>
-#include <linux/cdev.h>
 #include <linux/slab.h>
-#include <linux/anon_inodes.h>
-#include <linux/debugfs.h>
-#include <linux/mutex.h>
+#include <linux/wait.h>
+
 #include <linux/iio/iio.h>
 #include "iio_core.h"
 #include "iio_core_trigger.h"
Signature · 1 line
2.33.0
author maintainer
#2 lore raw

RFC PATCH 2/11 iio: industrialio-core - Bring includes up to date.

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Using the include-what-you-use tool as a guide
a) Drop unnused headers.
b) Add missing headers for functionality directly used in this file.

Note that this is not an automated process and in somecases the suggestions were ignored, or a different header included to reflect what I understand to be expected structure of includes.

---
 drivers/iio/industrialio-core.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)
drivers/iio/industrialio-core.c +20 -7
index d6c2875a832e..64f4aba20d9e 100644
@@ -8,22 +8,35 @@
 
 #define pr_fmt(fmt) "iio-core: " fmt
 
-#include <linux/anon_inodes.h>
-#include <linux/device.h>
+#include <linux/align.h>
+#include <linux/bitops.h>
 #include <linux/cdev.h>
 #include <linux/debugfs.h>
+#include <linux/device.h>
 #include <linux/err.h>
+#include <linux/export.h>
 #include <linux/fs.h>
+#include <linux/hrtimer.h>
 #include <linux/idr.h>
+#include <linux/init.h>
 #include <linux/kdev_t.h>
 #include <linux/kernel.h>
+#include <linux/kstrtox.h>
+#include <linux/ktime.h>
+#include <linux/list.h>
+#include <linux/math.h>
+#include <linux/math64.h>
+#include <linux/minmax.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
-#include <linux/poll.h>
+#include <linux/printk.h>
 #include <linux/property.h>
-#include <linux/sched.h>
 #include <linux/slab.h>
-#include <linux/wait.h>
+#include <linux/stat.h>
+#include <linux/string.h>
+#include <linux/sysfs.h>
+#include <linux/time64.h>
+#include <linux/uaccess.h>
 
 #include <linux/iio/iio.h>
 #include "iio_core.h"
@@ -31,8 +44,8 @@
 #include "iio_opaque.h"
 #include <linux/iio/sysfs.h>
 #include <linux/iio/events.h>
-#include <linux/iio/buffer.h>
-#include <linux/iio/buffer_impl.h>
+
+struct iio_buffer;
 
 /* IDA to assign each registered device a unique id */
 static DEFINE_IDA(iio_ida);
Signature · 1 line
2.33.0
author maintainer
#3 lore raw

RFC PATCH 3/11 iio: industrialio-buffer.c: Bring includes up to date.

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Note that a lot of functionality has moved around in IIO over the years and header includes have not always kept track.

Based on manual inspection suggestions from the include-what-you-use-tool adjusted to take into account certain 'super headers' used in the kernel.

Includes reordering headers to alphabetical order (mostly in order so not done in a separate patch).

---
 drivers/iio/industrialio-buffer.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
drivers/iio/industrialio-buffer.c +19 -4
index ed7a5c0a31e1..f5ab3a43d5d6 100644
@@ -9,16 +9,31 @@
  * - Better memory allocation techniques?
  * - Alternative access techniques?
  */
+#include <linux/align.h>
+#include <linux/bitmap.h>
+#include <linux/bitops.h>
 #include <linux/anon_inodes.h>
-#include <linux/kernel.h>
-#include <linux/export.h>
 #include <linux/device.h>
+#include <linux/err.h>
+#include <linux/export.h>
 #include <linux/file.h>
 #include <linux/fs.h>
-#include <linux/cdev.h>
-#include <linux/slab.h>
+#include <linux/kernel.h>
+#include <linux/kref.h>
+#include <linux/kstrtox.h>
+#include <linux/list.h>
+#include <linux/math.h>
+#include <linux/minmax.h>
+#include <linux/mutex.h>
 #include <linux/poll.h>
+#include <linux/sched.h>
 #include <linux/sched/signal.h>
+#include <linux/slab.h>
+#include <linux/stat.h>
+#include <linux/string.h>
+#include <linux/sysfs.h>
+#include <linux/uaccess.h>
+#include <linux/wait.h>
 
 #include <linux/iio/iio.h>
 #include "iio_core.h"
Signature · 1 line
2.33.0
author maintainer
#4 lore raw

RFC PATCH 4/11 iio: industrialio-event.c: Bring includes up to date.

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Partly as a result of moving code around in IIO and not keeping includes updated.

Based on manual inspection of the output of
include-what-you-use

---
 drivers/iio/industrialio-event.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/iio/industrialio-event.c +7 -2
index 1d49714d9832..e807cb9d091d 100644
@@ -7,14 +7,19 @@
  */
 
 #include <linux/anon_inodes.h>
+#include <linux/bitops.h>
 #include <linux/device.h>
+#include <linux/errno.h>
+#include <linux/export.h>
 #include <linux/fs.h>
 #include <linux/kernel.h>
 #include <linux/kfifo.h>
-#include <linux/module.h>
+#include <linux/kstrtox.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
 #include <linux/poll.h>
-#include <linux/sched.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 #include <linux/uaccess.h>
 #include <linux/wait.h>
 #include <linux/iio/iio.h>
Signature · 1 line
2.33.0
author maintainer
#5 lore raw

RFC PATCH 5/11 iio: industrialio-trigger.c: Bring includes up to date.

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Based on manual inspection of the suggestions from the include-what-you-use tool.

---
 drivers/iio/industrialio-trigger.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/iio/industrialio-trigger.c +12 -3
index e4e59466a263..3b77371aea57 100644
@@ -4,13 +4,22 @@
  * Copyright (c) 2008 Jonathan Cameron
  */
 
-#include <linux/kernel.h>
-#include <linux/idr.h>
-#include <linux/err.h>
 #include <linux/device.h>
+#include <linux/err.h>
+#include <linux/export.h>
+#include <linux/idr.h>
 #include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/kernel.h>
 #include <linux/list.h>
+#include <linux/log2.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/printk.h>
 #include <linux/slab.h>
+#include <linux/stat.h>
+#include <linux/string.h>
+#include <linux/sysfs.h>
 
 #include <linux/iio/iio.h>
 #include <linux/iio/trigger.h>
Signature · 1 line
2.33.0
author maintainer
#6 lore raw

RFC PATCH 6/11 iio: inkern: Bring includes up to date.

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Based on manual inspection of the suggestions from the include-what-you-use tool.

---
 drivers/iio/inkern.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/iio/inkern.c +6 -1
index 72c130d9fecb..2b478261f9a2 100644
@@ -3,11 +3,16 @@
  *
  * Copyright (c) 2011 Jonathan Cameron
  */
+#include <linux/device.h>
 #include <linux/err.h>
 #include <linux/export.h>
-#include <linux/slab.h>
+#include <linux/list.h>
+#include <linux/math64.h>
 #include <linux/mutex.h>
 #include <linux/of.h>
+#include <linux/printk.h>
+#include <linux/slab.h>
+#include <linux/string.h>
 
 #include <linux/iio/iio.h>
 #include "iio_core.h"
Signature · 1 line
2.33.0
author maintainer
#7 lore raw

RFC PATCH 7/11 iio: configfs: Bring includes up to date

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Based on manual inspection of the suggestions from the include-what-you-use tool

---
 drivers/iio/industrialio-configfs.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/industrialio-configfs.c +3 -4
index 47900de1f105..37f530faa131 100644
@@ -6,12 +6,11 @@
  */
 
 #include <linux/configfs.h>
-#include <linux/module.h>
+#include <linux/export.h>
 #include <linux/init.h>
-#include <linux/kmod.h>
-#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
 
-#include <linux/iio/iio.h>
 #include <linux/iio/configfs.h>
 
 static const struct config_item_type iio_root_group_type = {
Signature · 1 line
2.33.0
author maintainer
#8 lore raw

RFC PATCH 8/11 iio: misc core files: Bring includes up to date

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Small utility files from the IIO core grouped together in this commit. Based on manual inspection fo the suggestions from the include-what-you-use tool.

---
 drivers/iio/industrialio-sw-device.c       | 8 +++++---
 drivers/iio/industrialio-sw-trigger.c      | 9 ++++++---
 drivers/iio/industrialio-triggered-event.c | 3 ++-
 3 files changed, 13 insertions(+), 7 deletions(-)
drivers/iio/industrialio-sw-device.c +5 -3
index 49f775f16ad5..6bcea1bacec2 100644
@@ -5,11 +5,13 @@
  * Copyright (c) 2016 Intel Corporation
  */
 
-#include <linux/module.h>
+#include <linux/err.h>
 #include <linux/init.h>
-#include <linux/kmod.h>
 #include <linux/list.h>
-#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/printk.h>
+#include <linux/string.h>
 
 #include <linux/iio/sw_device.h>
 #include <linux/iio/configfs.h>
drivers/iio/industrialio-sw-trigger.c +6 -3
index 9ae793a70b8b..66796ca59676 100644
@@ -5,11 +5,14 @@
  * Copyright (c) 2015 Intel Corporation
  */
 
-#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/export.h>
 #include <linux/init.h>
-#include <linux/kmod.h>
 #include <linux/list.h>
-#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/printk.h>
+#include <linux/string.h>
 
 #include <linux/iio/sw_trigger.h>
 #include <linux/iio/configfs.h>
drivers/iio/industrialio-triggered-event.c +2 -1
index 4bedc65c9fe3..91179482dc4f 100644
@@ -3,8 +3,9 @@
  * Copyright (C) 2015 Cogent Embedded, Inc.
  */
 
-#include <linux/kernel.h>
+#include <linux/err.h>
 #include <linux/export.h>
+#include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/triggered_event.h>
Signature · 1 line
2.33.0
author maintainer
#9 lore raw

RFC PATCH 9/11 iio: industrialio-triggered-buffer: Bring includes up to date.

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Based on manual inspection of the suggestions made by the include-what-you-use tool.

---
 drivers/iio/buffer/industrialio-triggered-buffer.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/iio/buffer/industrialio-triggered-buffer.c +5 -1
index f77c4538141e..c1c445853c66 100644
@@ -4,8 +4,10 @@
  *  Author: Lars-Peter Clausen <[email protected]>
  */
 
-#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/err.h>
 #include <linux/export.h>
+#include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/buffer.h>
@@ -14,6 +16,8 @@
 #include <linux/iio/triggered_buffer.h>
 #include <linux/iio/trigger_consumer.h>
 
+struct attribute;
+
 /**
  * iio_triggered_buffer_setup_ext() - Setup triggered buffer and pollfunc
  * @indio_dev:		IIO device structure
Signature · 1 line
2.33.0
author maintainer
#10 lore raw

RFC PATCH 10/11 iio: industrialio-buffer-cb: Bring includes up to date.

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Based on manual inspection of the suggestions from the include-what-you-use tool.

---
 drivers/iio/buffer/industrialio-buffer-cb.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/iio/buffer/industrialio-buffer-cb.c +5 -2
index 4c12b7a94af5..3918176384c6 100644
@@ -2,11 +2,14 @@
 /* The industrial I/O callback buffer
  */
 
+#include <linux/bitmap.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/export.h>
 #include <linux/kernel.h>
+#include <linux/list.h>
 #include <linux/module.h>
 #include <linux/slab.h>
-#include <linux/err.h>
-#include <linux/export.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/buffer_impl.h>
 #include <linux/iio/consumer.h>
Signature · 1 line
2.33.0
author maintainer
#11 lore raw

RFC PATCH 11/11 iio: kfifo-buf.c: Bring includes up to date.

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Based on manual inspection of the suggestions from the include-what-you-use tool.

---
 drivers/iio/buffer/kfifo_buf.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/iio/buffer/kfifo_buf.c +9 -6
index 516eb3465de1..9564fcbb8979 100644
@@ -1,17 +1,20 @@
 // SPDX-License-Identifier: GPL-2.0-only
-#include <linux/slab.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
 #include <linux/device.h>
-#include <linux/workqueue.h>
+#include <linux/err.h>
+#include <linux/export.h>
+#include <linux/kernel.h>
 #include <linux/kfifo.h>
+#include <linux/log2.h>
+#include <linux/module.h>
 #include <linux/mutex.h>
+#include <linux/slab.h>
+
 #include <linux/iio/iio.h>
 #include <linux/iio/buffer.h>
 #include <linux/iio/kfifo_buf.h>
 #include <linux/iio/buffer_impl.h>
-#include <linux/sched.h>
-#include <linux/poll.h>
+
+struct attribute;
 
 struct iio_kfifo {
 	struct iio_buffer buffer;
Signature · 1 line
2.33.0
author maintainer
#12 lore raw
In reply to Jonathan Cameron
Quoted 4 lines · On Sun, 3 Oct 2021 16:32:55 +0100 Jonathan Cameron <[email protected]> wrote:

From: Jonathan Cameron <[email protected]>

The includes from the various IIO core files have bitrotted over time (and probably were not great in the first place).

Given ongoing churn in core kernel includes as Andy cleans them up, I've pushed this particular work out on a branch at

https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/log/?h=iio-iwyu-cleanups

This will get me 0-day exposure and allow me to keep moving these forwards as the core kernel headers change.

I would like to start merging 'some' of these in the meantime and there are some precursor cleanup patches that I'll pull out separately.

Perhaps most 'useful' is the top patch in that branch which is the iwyu mapping file I've put together to get it to make more reasonable suggestions. Note that there are some cases where the answer isn't obvious and some where you can't push iwyu to do the right thing.

One example is struct regmap which is deliberately opaque. iwyu always wants a forwards definition of it in all files where pointers to it occur, but personally I think including linux/regmap.h is sufficient as that will always have the forwards definition needed.

Note this branch will rebase frequently and may well eat babies. In particularly I will be cherry picking Andy and anyone else's work to the top of it and making changes through the rest of the patches as that affects them.

I'm not particularly expecting feedback, but I do want to avoid duplicate work. I'm also likely to 'fixing' new code as it comes in based on this toolchain - I may main in reviews or just fix it whilst applying (and tell people obviously!)

Long term plan here is to bring consistency to includes with benefits of resilience and hopefully reducing just how much code is actually pulled in whilst compiling.

Thanks,

Jonathan

Quoted 664 lines

This series is based loosely on the suggests the include-what-you-use tool provides but with a lot of discretion applied. Note that tool will tell you:
1) What includes provide elements directly used in a given .c file.
2) What includes are providing nothing that is directly used in the .c file.
3) It will not follow 'include chains', then concept being that anything used should be defined in a header directly included.
It can't always distinguish between different paths to the header and knows nothing about intended include structures in the kernel. (for example including eventpoll.h directly is not intended to be safe,
instead poll.h should be used).

In recent times a lot of code has moved around in IIO and as a result often headers have gotten left behind or haven't made the move along with the code they were there to support.

I made some decisions to reduce includes.

#include <linux/device.h>
can be assumed to bring in dev_printk.h and device/bus.h so don't include those directly.
#include <linux/err.h>
is a good general header to bring in errno.h as well as the various PTR_ERR() macros and similar.
#include <linux/poll.h>
brings in everything related to polling.
#include <linux/irq.h> or <linux/interrupt.h> as appropriate will bring in irqreturn.h.

(probably some other cases I've forgotten about).

Andy has been working on breaking up some of the headers that tend to get included everywhere because they are a pile of unrelated things. Some impact of that can be seen in this series.

I would like to move IIO in the right direction even if we then end up with some additional churn in future reflecting changes in the headers we are using. This is an RFC primarily because there is a lot of 'interpretation' involved so I'd like to get high level feedback.

I've included below the suggestions iwyu made for reference. As you can see the raw output is mostly useful for highlighting things that should not be there and roughly what should be.

drivers/iio/buffer/kfifo_buf.c should add these lines:

#include <stddef.h>                  // for size_t, NULL
#include "asm-generic/errno-base.h"  // for EINVAL, EBUSY, ENOMEM
#include "linux/compiler_types.h"    // for __user, inline
#include "linux/errno.h"             // for ERESTARTSYS
#include "linux/export.h"            // for EXPORT_SYMBOL, EXPORT_SYMBOL_GPL
#include "linux/gfp.h"               // for GFP_KERNEL
#include "linux/log2.h"              // for roundup_pow_of_two
#include "linux/stddef.h"            // for true, false
#include "vdso/limits.h"             // for UINT_MAX

struct attribute;

drivers/iio/buffer/kfifo_buf.c should remove these lines:
- #include <linux/poll.h> // lines 14-14
- #include <linux/sched.h> // lines 13-13
- #include <linux/workqueue.h> // lines 6-6

The full include-list for drivers/iio/buffer/kfifo_buf.c:

#include <linux/device.h>            // for devres_add, devres_free, devres_...
#include <linux/iio/buffer.h>        // for iio_device_attach_buffer
#include <linux/iio/buffer_impl.h>   // for iio_buffer, iio_buffer_init, iio...
#include <linux/iio/iio.h>           // for iio_dev, INDIO_BUFFER_SOFTWARE
#include <linux/iio/kfifo_buf.h>     // for devm_iio_kfifo_buffer_setup_ext
#include <linux/kernel.h>            // for container_of
#include <linux/kfifo.h>             // for __kfifo_alloc, kfifo_free, kfifo
#include <linux/module.h>            // for MODULE_LICENSE
#include <linux/mutex.h>             // for mutex_unlock, mutex_lock, mutex_...
#include <linux/slab.h>              // for kfree, kzalloc
#include <stddef.h>                  // for size_t, NULL
#include "asm-generic/errno-base.h"  // for EINVAL, EBUSY, ENOMEM
#include "linux/compiler_types.h"    // for __user, inline
#include "linux/errno.h"             // for ERESTARTSYS
#include "linux/export.h"            // for EXPORT_SYMBOL, EXPORT_SYMBOL_GPL
#include "linux/gfp.h"               // for GFP_KERNEL
#include "linux/log2.h"              // for roundup_pow_of_two
#include "linux/stddef.h"            // for true, false
#include "vdso/limits.h"             // for UINT_MAX

struct attribute;

drivers/iio/buffer/industrialio-buffer-cb.c should add these lines:

#include <stddef.h>                                  // for NULL, size_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for set_bit
#include "asm-generic/errno-base.h"                  // for EINVAL, ENOMEM
#include "linux/bitmap.h"                            // for bitmap_free, bit...
#include "linux/dev_printk.h"                        // for dev_err
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/list.h"                              // for INIT_LIST_HEAD

struct device;

drivers/iio/buffer/industrialio-buffer-cb.c should remove these lines:

The full include-list for drivers/iio/buffer/industrialio-buffer-cb.c:

#include <linux/err.h>                               // for ERR_PTR, IS_ERR
#include <linux/export.h>                            // for EXPORT_SYMBOL_GPL
#include <linux/iio/buffer_impl.h>                   // for iio_buffer, iio_...
#include <linux/iio/consumer.h>                      // for iio_channel, iio...
#include <linux/iio/iio.h>                           // for INDIO_BUFFER_SOF...
#include <linux/kernel.h>                            // for container_of
#include <linux/module.h>                            // for MODULE_AUTHOR
#include <linux/slab.h>                              // for kfree, kzalloc
#include <stddef.h>                                  // for NULL, size_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for set_bit
#include "asm-generic/errno-base.h"                  // for EINVAL, ENOMEM
#include "linux/bitmap.h"                            // for bitmap_free, bit...
#include "linux/dev_printk.h"                        // for dev_err
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/list.h"                              // for INIT_LIST_HEAD

struct device;

drivers/iio/buffer/industrialio-triggered-buffer.c should add these lines:

#include <stddef.h>                      // for NULL
#include "asm-generic/errno-base.h"      // for ENOMEM
#include "linux/device.h"                // for devm_add_action_or_reset
#include "linux/interrupt.h"             // for IRQF_ONESHOT
#include "linux/irqreturn.h"             // for irqreturn_t

struct attribute;

drivers/iio/buffer/industrialio-triggered-buffer.c should remove these lines:
- #include <linux/kernel.h> // lines 7-7

The full include-list for drivers/iio/buffer/industrialio-triggered-buffer.c:

#include <linux/export.h>                // for EXPORT_SYMBOL, EXPORT_SYMBOL...
#include <linux/iio/buffer.h>            // for iio_device_attach_buffer
#include <linux/iio/buffer_impl.h>       // for iio_buffer
#include <linux/iio/iio.h>               // for iio_dev, iio_device_id, INDI...
#include <linux/iio/kfifo_buf.h>         // for iio_kfifo_free, iio_kfifo_al...
#include <linux/iio/trigger_consumer.h>  // for iio_dealloc_pollfunc, iio_al...
#include <linux/iio/triggered_buffer.h>  // for devm_iio_triggered_buffer_se...
#include <linux/module.h>                // for MODULE_AUTHOR, MODULE_DESCRI...
#include <stddef.h>                      // for NULL
#include "asm-generic/errno-base.h"      // for ENOMEM
#include "linux/device.h"                // for devm_add_action_or_reset
#include "linux/interrupt.h"             // for IRQF_ONESHOT
#include "linux/irqreturn.h"             // for irqreturn_t

struct attribute;

drivers/iio/industrialio-triggered-event.c should add these lines:

#include <stddef.h>                      // for NULL
#include "asm-generic/errno-base.h"      // for ENOMEM
#include "linux/interrupt.h"             // for IRQF_ONESHOT
#include "linux/irqreturn.h"             // for irqreturn_t

drivers/iio/industrialio-triggered-event.c should remove these lines:
- #include <linux/kernel.h> // lines 6-6

The full include-list for drivers/iio/industrialio-triggered-event.c:

#include <linux/export.h>                // for EXPORT_SYMBOL
#include <linux/iio/iio.h>               // for iio_dev, iio_device_id, INDI...
#include <linux/iio/trigger_consumer.h>  // for iio_alloc_pollfunc, iio_deal...
#include <linux/iio/triggered_event.h>   // for iio_triggered_event_cleanup
#include <linux/module.h>                // for MODULE_AUTHOR, MODULE_DESCRI...
#include <stddef.h>                      // for NULL
#include "asm-generic/errno-base.h"      // for ENOMEM
#include "linux/interrupt.h"             // for IRQF_ONESHOT
#include "linux/irqreturn.h"             // for irqreturn_t

drivers/iio/industrialio-event.c should add these lines:

#include <asm/bitops.h>                              // for test_bit
#include <stddef.h>                                  // for NULL, size_t
#include <sys/types.h>                               // for ssize_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit, test_...
#include "asm-generic/errno-base.h"                  // for EINVAL, ENODEV
#include "asm-generic/fcntl.h"                       // for O_NONBLOCK, O_CL...
#include "asm-generic/int-ll64.h"                    // for s64, u64
#include "asm/string_64.h"                           // for memcpy
#include "linux/bitops.h"                            // for for_each_set_bit
#include "linux/compiler_types.h"                    // for __user, inline
#include "linux/errno.h"                             // for ERESTARTSYS
#include "linux/eventpoll.h"                         // for EPOLLIN, EPOLLRD...
#include "linux/export.h"                            // for EXPORT_SYMBOL
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/iio/events.h"                        // for iio_event_data
#include "linux/iio/types.h"                         // for iio_event_direction
#include "linux/kstrtox.h"                           // for strtobool
#include "linux/list.h"                              // for INIT_LIST_HEAD
#include "linux/mutex.h"                             // for mutex_lock_inter...
#include "linux/stddef.h"                            // for false, true
#include "linux/sysfs.h"                             // for attribute_group
#include "linux/types.h"                             // for list_head, bool

drivers/iio/industrialio-event.c should remove these lines:
- #include <linux/iio/events.h> // lines 24-24
- #include <linux/module.h> // lines 14-14
- #include <linux/sched.h> // lines 16-16

The full include-list for drivers/iio/industrialio-event.c:

#include <asm/bitops.h>                              // for test_bit
#include <linux/anon_inodes.h>                       // for anon_inode_getfd
#include <linux/device.h>                            // for device_attribute
#include <linux/fs.h>                                // for file, noop_llseek
#include <linux/iio/iio-opaque.h>                    // for iio_dev_opaque
#include <linux/iio/iio.h>                           // for iio_dev, iio_eve...
#include <linux/iio/sysfs.h>                         // for iio_dev_attr
#include <linux/kernel.h>                            // for kasprintf, ARRAY...
#include <linux/kfifo.h>                             // for kfifo_is_empty
#include <linux/poll.h>                              // for poll_wait
#include <linux/slab.h>                              // for kfree, kcalloc
#include <linux/uaccess.h>                           // for copy_to_user
#include <linux/wait.h>                              // for init_waitqueue_head
#include <stddef.h>                                  // for NULL, size_t
#include <sys/types.h>                               // for ssize_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit, test_...
#include "asm-generic/errno-base.h"                  // for EINVAL, ENODEV
#include "asm-generic/fcntl.h"                       // for O_NONBLOCK, O_CL...
#include "asm-generic/int-ll64.h"                    // for s64, u64
#include "asm/string_64.h"                           // for memcpy
#include "iio_core.h"                                // for iio_free_chan_de...
#include "linux/bitops.h"                            // for for_each_set_bit
#include "linux/compiler_types.h"                    // for __user, inline
#include "linux/errno.h"                             // for ERESTARTSYS
#include "linux/eventpoll.h"                         // for EPOLLIN, EPOLLRD...
#include "linux/export.h"                            // for EXPORT_SYMBOL
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/iio/events.h"                        // for iio_event_data
#include "linux/iio/types.h"                         // for iio_event_direction
#include "linux/kstrtox.h"                           // for strtobool
#include "linux/list.h"                              // for INIT_LIST_HEAD
#include "linux/mutex.h"                             // for mutex_lock_inter...
#include "linux/stddef.h"                            // for false, true
#include "linux/sysfs.h"                             // for attribute_group
#include "linux/types.h"                             // for list_head, bool

drivers/iio/industrialio-core.c should add these lines:

#include <asm/bug.h>                                 // for WARN
#include <linux/ktime.h>                             // for ktime_get_bootti...
#include <stddef.h>                                  // for NULL, size_t
#include <stdint.h>                                  // for uintptr_t
#include <sys/types.h>                               // for ssize_t, dev_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit, test_...
#include "asm-generic/errno-base.h"                  // for EINVAL, EBUSY
#include "asm-generic/int-ll64.h"                    // for s64, u64
#include "asm/bug.h"                                 // for BUG
#include "asm/page_types.h"                          // for PAGE_SIZE
#include "asm/string_64.h"                           // for memcpy
#include "generated/autoconf.h"                      // for CONFIG_DEBUG_FS
#include "linux/align.h"                             // for ALIGN
#include "linux/bitops.h"                            // for for_each_set_bit
#include "linux/compiler_attributes.h"               // for fallthrough
#include "linux/compiler_types.h"                    // for __user
#include "linux/dev_printk.h"                        // for dev_err, dev_info
#include "linux/device/bus.h"                        // for bus_unregister
#include "linux/export.h"                            // for EXPORT_SYMBOL_GPL
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/hrtimer.h"                           // for hrtimer_resolution
#include "linux/iio/types.h"                         // for IIO_VAL_INT, IIO...
#include "linux/init.h"                              // for __exit, __init
#include "linux/kstrtox.h"                           // for kstrtoint
#include "linux/ktime.h"                             // for ktime_to_ns
#include "linux/list.h"                              // for INIT_LIST_HEAD
#include "linux/math.h"                              // for abs
#include "linux/math64.h"                            // for div_s64_rem, div...
#include "linux/minmax.h"                            // for min_t
#include "linux/of.h"                                // for of_get_property
#include "linux/printk.h"                            // for pr_err
#include "linux/stat.h"                              // for S_IRUGO, S_IWUSR
#include "linux/stddef.h"                            // for false, true
#include "linux/string.h"                            // for sysfs_streq, str...
#include "linux/sysfs.h"                             // for sysfs_emit_at
#include "linux/time.h"                              // for CLOCK_BOOTTIME
#include "linux/time64.h"                            // for timespec64_to_ns
#include "linux/timex.h"                             // for shift_right
#include "linux/types.h"                             // for list_head, bool
#include "linux/uaccess.h"                           // for copy_from_user
#include "vdso/ktime.h"                              // for LOW_RES_NSEC

struct iio_buffer;

drivers/iio/industrialio-core.c should remove these lines:
- #include <linux/anon_inodes.h> // lines 24-24
- #include <linux/iio/buffer.h> // lines 33-33
- #include <linux/iio/buffer_impl.h> // lines 34-34
- #include <linux/iio/events.h> // lines 32-32
- #include <linux/poll.h> // lines 18-18
- #include <linux/sched.h> // lines 20-20
- #include <linux/wait.h> // lines 21-21

The full include-list for drivers/iio/industrialio-core.c:

#include <asm/bug.h>                                 // for WARN
#include <linux/cdev.h>                              // for cdev_init, cdev_...
#include <linux/debugfs.h>                           // for debugfs_create_dir
#include <linux/device.h>                            // for device, device_a...
#include <linux/err.h>                               // for IS_ERR, PTR_ERR
#include <linux/fs.h>                                // for noop_llseek, inode
#include <linux/idr.h>                               // for DEFINE_IDA, ida_...
#include <linux/iio/iio-opaque.h>                    // for iio_dev_opaque
#include <linux/iio/iio.h>                           // for iio_dev, iio_cha...
#include <linux/iio/sysfs.h>                         // for iio_dev_attr
#include <linux/kdev_t.h>                            // for MAJOR, MKDEV
#include <linux/kernel.h>                            // for kasprintf, sscanf
#include <linux/ktime.h>                             // for ktime_get_bootti...
#include <linux/module.h>                            // for MODULE_AUTHOR
#include <linux/mutex.h>                             // for mutex_unlock
#include <linux/property.h>                          // for device_property_...
#include <linux/slab.h>                              // for kfree, kzalloc
#include <stddef.h>                                  // for NULL, size_t
#include <stdint.h>                                  // for uintptr_t
#include <sys/types.h>                               // for ssize_t, dev_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit, test_...
#include "asm-generic/errno-base.h"                  // for EINVAL, EBUSY
#include "asm-generic/int-ll64.h"                    // for s64, u64
#include "asm/bug.h"                                 // for BUG
#include "asm/page_types.h"                          // for PAGE_SIZE
#include "asm/string_64.h"                           // for memcpy
#include "generated/autoconf.h"                      // for CONFIG_DEBUG_FS
#include "iio_core.h"                                // for iio_ioctl_handler
#include "iio_core_trigger.h"                        // for iio_device_regis...
#include "linux/align.h"                             // for ALIGN
#include "linux/bitops.h"                            // for for_each_set_bit
#include "linux/compiler_attributes.h"               // for fallthrough
#include "linux/compiler_types.h"                    // for __user
#include "linux/dev_printk.h"                        // for dev_err, dev_info
#include "linux/device/bus.h"                        // for bus_unregister
#include "linux/export.h"                            // for EXPORT_SYMBOL_GPL
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/hrtimer.h"                           // for hrtimer_resolution
#include "linux/iio/types.h"                         // for IIO_VAL_INT, IIO...
#include "linux/init.h"                              // for __exit, __init
#include "linux/kstrtox.h"                           // for kstrtoint
#include "linux/ktime.h"                             // for ktime_to_ns
#include "linux/list.h"                              // for INIT_LIST_HEAD
#include "linux/math.h"                              // for abs
#include "linux/math64.h"                            // for div_s64_rem, div...
#include "linux/minmax.h"                            // for min_t
#include "linux/of.h"                                // for of_get_property
#include "linux/printk.h"                            // for pr_err
#include "linux/stat.h"                              // for S_IRUGO, S_IWUSR
#include "linux/stddef.h"                            // for false, true
#include "linux/string.h"                            // for sysfs_streq, str...
#include "linux/sysfs.h"                             // for sysfs_emit_at
#include "linux/time.h"                              // for CLOCK_BOOTTIME
#include "linux/time64.h"                            // for timespec64_to_ns
#include "linux/timex.h"                             // for shift_right
#include "linux/types.h"                             // for list_head, bool
#include "linux/uaccess.h"                           // for copy_from_user
#include "vdso/ktime.h"                              // for LOW_RES_NSEC

struct iio_buffer;

drivers/iio/industrialio-configfs.c should add these lines:
#include "linux/export.h" // for EXPORT_SYMBOL, THIS_MODULE
#include "linux/mutex.h" // for mutex, __MUTEX_INITIALIZER

drivers/iio/industrialio-configfs.c should remove these lines:
- #include <linux/iio/configfs.h> // lines 15-15
- #include <linux/iio/iio.h> // lines 14-14
- #include <linux/kmod.h> // lines 11-11
- #include <linux/slab.h> // lines 12-12

The full include-list for drivers/iio/industrialio-configfs.c:

#include <linux/configfs.h>  // for configfs_subsystem, config_group_init
#include <linux/init.h>      // for __exit, __init
#include <linux/module.h>    // for MODULE_AUTHOR, MODULE_DESCRIPTION, MODUL...
#include "linux/export.h"    // for EXPORT_SYMBOL, THIS_MODULE
#include "linux/mutex.h"     // for mutex, __MUTEX_INITIALIZER

drivers/iio/inkern.c should add these lines:

#include <stddef.h>                  // for NULL, size_t
#include <stdint.h>                  // for uint32_t
#include <sys/types.h>               // for ssize_t
#include "asm-generic/errno-base.h"  // for ENODEV, EINVAL, ENOMEM
#include "asm-generic/int-ll64.h"    // for s64
#include "generated/autoconf.h"      // for CONFIG_OF
#include "linux/dev_printk.h"        // for dev_err
#include "linux/device.h"            // for devm_add_action_or_reset, dev_name
#include "linux/device/bus.h"        // for bus_find_device
#include "linux/errno.h"             // for EPROBE_DEFER
#include "linux/gfp.h"               // for GFP_KERNEL
#include "linux/iio/types.h"         // for iio_chan_info_enum, IIO_CHAN_INF...
#include "linux/list.h"              // for list_add_tail, list_del, list_fo...
#include "linux/math64.h"            // for div_s64
#include "linux/printk.h"            // for pr_err
#include "linux/string.h"            // for strcmp
#include "linux/types.h"             // for list_head

drivers/iio/inkern.c should remove these lines:

The full include-list for drivers/iio/inkern.c:

#include <linux/err.h>               // for ERR_PTR, IS_ERR, PTR_ERR
#include <linux/export.h>            // for EXPORT_SYMBOL_GPL
#include <linux/iio/consumer.h>      // for iio_channel, devm_iio_channel_get
#include <linux/iio/driver.h>        // for devm_iio_map_array_register, iio...
#include <linux/iio/iio-opaque.h>    // for iio_dev_opaque, to_iio_dev_opaque
#include <linux/iio/iio.h>           // for iio_dev, iio_device_put, iio_cha...
#include <linux/iio/machine.h>       // for iio_map
#include <linux/mutex.h>             // for mutex_unlock, mutex_lock, mutex
#include <linux/of.h>                // for of_phandle_args, of_parse_phandl...
#include <linux/slab.h>              // for kfree, kzalloc, kcalloc
#include <stddef.h>                  // for NULL, size_t
#include <stdint.h>                  // for uint32_t
#include <sys/types.h>               // for ssize_t
#include "asm-generic/errno-base.h"  // for ENODEV, EINVAL, ENOMEM
#include "asm-generic/int-ll64.h"    // for s64
#include "generated/autoconf.h"      // for CONFIG_OF
#include "iio_core.h"                // for iio_device_type
#include "linux/dev_printk.h"        // for dev_err
#include "linux/device.h"            // for devm_add_action_or_reset, dev_name
#include "linux/device/bus.h"        // for bus_find_device
#include "linux/errno.h"             // for EPROBE_DEFER
#include "linux/gfp.h"               // for GFP_KERNEL
#include "linux/iio/types.h"         // for iio_chan_info_enum, IIO_CHAN_INF...
#include "linux/list.h"              // for list_add_tail, list_del, list_fo...
#include "linux/math64.h"            // for div_s64
#include "linux/printk.h"            // for pr_err
#include "linux/string.h"            // for strcmp
#include "linux/types.h"             // for list_head

drivers/iio/industrialio-sw-device.c should add these lines:

#include <stddef.h>                  // for NULL
#include "asm-generic/errno-base.h"  // for EBUSY, EINVAL
#include "linux/err.h"               // for IS_ERR, ERR_CAST, ERR_PTR, PTR_ERR
#include "linux/export.h"            // for EXPORT_SYMBOL, THIS_MODULE
#include "linux/mutex.h"             // for mutex_lock, mutex_unlock, mutex
#include "linux/printk.h"            // for pr_err
#include "linux/string.h"            // for strlen, strcmp
#include "linux/types.h"             // for list_head

drivers/iio/industrialio-sw-device.c should remove these lines:
- #include <linux/kmod.h> // lines 10-10
- #include <linux/slab.h> // lines 12-12

The full include-list for drivers/iio/industrialio-sw-device.c:

#include <linux/configfs.h>          // for configfs_register_default_group
#include <linux/iio/configfs.h>      // for iio_configfs_subsys
#include <linux/iio/sw_device.h>     // for iio_sw_device_type, iio_sw_device
#include <linux/init.h>              // for __exit, __init
#include <linux/list.h>              // for list_add_tail, list_del, LIST_HEAD
#include <linux/module.h>            // for module_put, try_module_get, MODU...
#include <stddef.h>                  // for NULL
#include "asm-generic/errno-base.h"  // for EBUSY, EINVAL
#include "linux/err.h"               // for IS_ERR, ERR_CAST, ERR_PTR, PTR_ERR
#include "linux/export.h"            // for EXPORT_SYMBOL, THIS_MODULE
#include "linux/mutex.h"             // for mutex_lock, mutex_unlock, mutex
#include "linux/printk.h"            // for pr_err
#include "linux/string.h"            // for strlen, strcmp
#include "linux/types.h"             // for list_head

drivers/iio/industrialio-trigger.c should add these lines:

#include <asm/bug.h>                                 // for WARN_ON
#include <linux/irq.h>                               // for generic_handle_irq
#include <stdarg.h>                                  // for va_list
#include <stddef.h>                                  // for NULL, size_t
#include <sys/types.h>                               // for ssize_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit
#include "asm-generic/errno-base.h"                  // for EINVAL, EBUSY
#include "generated/autoconf.h"                      // for CONFIG_IIO_CONSU...
#include "linux/atomic/atomic-instrumented.h"        // for atomic_read, ato...
#include "linux/bitmap.h"                            // for bitmap_empty
#include "linux/compiler_attributes.h"               // for __printf
#include "linux/export.h"                            // for EXPORT_SYMBOL
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/irq.h"                               // for irq_data_get_irq...
#include "linux/irqreturn.h"                         // for irqreturn_t, IRQ...
#include "linux/log2.h"                              // for ilog2
#include "linux/module.h"                            // for module_put, __mo...
#include "linux/mutex.h"                             // for mutex_unlock
#include "linux/printk.h"                            // for pr_err
#include "linux/stat.h"                              // for S_IRUGO, S_IWUSR
#include "linux/stdarg.h"                            // for va_end, va_start
#include "linux/stddef.h"                            // for true, false
#include "linux/string.h"                            // for strcmp, sysfs_streq
#include "linux/sysfs.h"                             // for sysfs_emit, ATTR...
#include "linux/types.h"                             // for list_head, bool

drivers/iio/industrialio-trigger.c should remove these lines:
- #include <linux/err.h> // lines 9-9

The full include-list for drivers/iio/industrialio-trigger.c:

#include <asm/bug.h>                                 // for WARN_ON
#include <linux/device.h>                            // for device, device_del
#include <linux/idr.h>                               // for ida_simple_remove
#include <linux/iio/iio-opaque.h>                    // for iio_dev_opaque
#include <linux/iio/iio.h>                           // for iio_dev, dev_to_...
#include <linux/iio/trigger.h>                       // for iio_trigger, iio...
#include <linux/iio/trigger_consumer.h>              // for iio_poll_func
#include <linux/interrupt.h>                         // for free_irq, reques...
#include <linux/irq.h>                               // for generic_handle_irq
#include <linux/kernel.h>                            // for kvasprintf, cont...
#include <linux/list.h>                              // for list_add_tail
#include <linux/slab.h>                              // for kfree, kmalloc
#include <stdarg.h>                                  // for va_list
#include <stddef.h>                                  // for NULL, size_t
#include <sys/types.h>                               // for ssize_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit
#include "asm-generic/errno-base.h"                  // for EINVAL, EBUSY
#include "generated/autoconf.h"                      // for CONFIG_IIO_CONSU...
#include "iio_core.h"                                // for iio_device_regis...
#include "iio_core_trigger.h"                        // for iio_device_regis...
#include "linux/atomic/atomic-instrumented.h"        // for atomic_read, ato...
#include "linux/bitmap.h"                            // for bitmap_empty
#include "linux/compiler_attributes.h"               // for __printf
#include "linux/export.h"                            // for EXPORT_SYMBOL
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/irq.h"                               // for irq_data_get_irq...
#include "linux/irqreturn.h"                         // for irqreturn_t, IRQ...
#include "linux/log2.h"                              // for ilog2
#include "linux/module.h"                            // for module_put, __mo...
#include "linux/mutex.h"                             // for mutex_unlock
#include "linux/printk.h"                            // for pr_err
#include "linux/stat.h"                              // for S_IRUGO, S_IWUSR
#include "linux/stdarg.h"                            // for va_end, va_start
#include "linux/stddef.h"                            // for true, false
#include "linux/string.h"                            // for strcmp, sysfs_streq
#include "linux/sysfs.h"                             // for sysfs_emit, ATTR...
#include "linux/types.h"                             // for list_head, bool

drivers/iio/industrialio-sw-trigger.c should add these lines:

#include <stddef.h>                  // for NULL
#include "asm-generic/errno-base.h"  // for EBUSY, EINVAL
#include "linux/err.h"               // for IS_ERR, ERR_CAST, ERR_PTR, PTR_ERR
#include "linux/export.h"            // for EXPORT_SYMBOL, THIS_MODULE
#include "linux/mutex.h"             // for mutex_lock, mutex_unlock, mutex
#include "linux/printk.h"            // for pr_err
#include "linux/string.h"            // for strlen, strcmp
#include "linux/types.h"             // for list_head

drivers/iio/industrialio-sw-trigger.c should remove these lines:
- #include <linux/kmod.h> // lines 10-10
- #include <linux/slab.h> // lines 12-12

The full include-list for drivers/iio/industrialio-sw-trigger.c:

#include <linux/configfs.h>          // for configfs_register_default_group
#include <linux/iio/configfs.h>      // for iio_configfs_subsys
#include <linux/iio/sw_trigger.h>    // for iio_sw_trigger_type, iio_sw_trigger
#include <linux/init.h>              // for __exit, __init
#include <linux/list.h>              // for list_add_tail, list_del, LIST_HEAD
#include <linux/module.h>            // for module_put, try_module_get, MODU...
#include <stddef.h>                  // for NULL
#include "asm-generic/errno-base.h"  // for EBUSY, EINVAL
#include "linux/err.h"               // for IS_ERR, ERR_CAST, ERR_PTR, PTR_ERR
#include "linux/export.h"            // for EXPORT_SYMBOL, THIS_MODULE
#include "linux/mutex.h"             // for mutex_lock, mutex_unlock, mutex
#include "linux/printk.h"            // for pr_err
#include "linux/string.h"            // for strlen, strcmp
#include "linux/types.h"             // for list_head

drivers/iio/industrialio-buffer.c should add these lines:

#include <asm/bitops.h>                              // for test_bit
#include <asm/bug.h>                                 // for WARN
#include <stddef.h>                                  // for size_t, NULL
#include <sys/types.h>                               // for ssize_t
#include "asm-generic/bitops/find.h"                 // for find_next_bit
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit, set_bit
#include "asm-generic/errno-base.h"                  // for ENOMEM, EINVAL
#include "asm-generic/fcntl.h"                       // for O_NONBLOCK, O_CL...
#include "asm-generic/int-ll64.h"                    // for u8
#include "asm/current.h"                             // for current
#include "asm/string_64.h"                           // for memcpy, memset
#include "linux/align.h"                             // for ALIGN
#include "linux/bitmap.h"                            // for bitmap_free, bit...
#include "linux/bitops.h"                            // for for_each_set_bit
#include "linux/compiler_types.h"                    // for __user
#include "linux/dev_printk.h"                        // for dev_dbg
#include "linux/errno.h"                             // for ERESTARTSYS
#include "linux/eventpoll.h"                         // for EPOLLIN, EPOLLRD...
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/iio/buffer.h"                        // for IIO_BUFFER_GET_F...
#include "linux/iio/types.h"                         // for IIO_TIMESTAMP
#include "linux/kconfig.h"                           // for __LITTLE_ENDIAN
#include "linux/kref.h"                              // for kref_get, kref_init
#include "linux/kstrtox.h"                           // for strtobool, kstrt...
#include "linux/list.h"                              // for list_empty, INIT...
#include "linux/math.h"                              // for roundup
#include "linux/minmax.h"                            // for max, min, min_t
#include "linux/mutex.h"                             // for mutex_lock, mute...
#include "linux/sched.h"                             // for MAX_SCHEDULE_TIM...
#include "linux/stat.h"                              // for S_IRUGO, S_IWUSR
#include "linux/stddef.h"                            // for false, true
#include "linux/string.h"                            // for kstrdup_const
#include "linux/sysfs.h"                             // for sysfs_emit, attr...
#include "linux/types.h"                             // for list_head, bool
#include "linux/uaccess.h"                           // for copy_from_user
#include "linux/wait.h"                              // for woken_wake_function

drivers/iio/industrialio-buffer.c should remove these lines:
- #include <linux/cdev.h> // lines 18-18

The full include-list for drivers/iio/industrialio-buffer.c:

#include <asm/bitops.h>                              // for test_bit
#include <asm/bug.h>                                 // for WARN
#include <linux/anon_inodes.h>                       // for anon_inode_getfd
#include <linux/device.h>                            // for device_attribute
#include <linux/export.h>                            // for EXPORT_SYMBOL_GPL
#include <linux/file.h>                              // for put_unused_fd
#include <linux/fs.h>                                // for file, noop_llseek
#include <linux/iio/buffer.h>                        // for iio_device_attac...
#include <linux/iio/buffer_impl.h>                   // for iio_buffer, iio_...
#include <linux/iio/iio-opaque.h>                    // for iio_dev_opaque
#include <linux/iio/iio.h>                           // for iio_dev, iio_cha...
#include <linux/iio/sysfs.h>                         // for iio_dev_attr
#include <linux/kernel.h>                            // for ARRAY_SIZE, cont...
#include <linux/poll.h>                              // for poll_wait
#include <linux/sched/signal.h>                      // for signal_pending
#include <linux/slab.h>                              // for kfree, kzalloc
#include <stddef.h>                                  // for size_t, NULL
#include <sys/types.h>                               // for ssize_t
#include "asm-generic/bitops/find.h"                 // for find_next_bit
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit, set_bit
#include "asm-generic/errno-base.h"                  // for ENOMEM, EINVAL
#include "asm-generic/fcntl.h"                       // for O_NONBLOCK, O_CL...
#include "asm-generic/int-ll64.h"                    // for u8
#include "asm/current.h"                             // for current
#include "asm/string_64.h"                           // for memcpy, memset
#include "iio_core.h"                                // for __iio_add_chan_d...
#include "iio_core_trigger.h"                        // for iio_trigger_deta...
#include "linux/align.h"                             // for ALIGN
#include "linux/bitmap.h"                            // for bitmap_free, bit...
#include "linux/bitops.h"                            // for for_each_set_bit
#include "linux/compiler_types.h"                    // for __user
#include "linux/dev_printk.h"                        // for dev_dbg
#include "linux/errno.h"                             // for ERESTARTSYS
#include "linux/eventpoll.h"                         // for EPOLLIN, EPOLLRD...
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/iio/buffer.h"                        // for IIO_BUFFER_GET_F...
#include "linux/iio/types.h"                         // for IIO_TIMESTAMP
#include "linux/kconfig.h"                           // for __LITTLE_ENDIAN
#include "linux/kref.h"                              // for kref_get, kref_init
#include "linux/kstrtox.h"                           // for strtobool, kstrt...
#include "linux/list.h"                              // for list_empty, INIT...
#include "linux/math.h"                              // for roundup
#include "linux/minmax.h"                            // for max, min, min_t
#include "linux/mutex.h"                             // for mutex_lock, mute...
#include "linux/sched.h"                             // for MAX_SCHEDULE_TIM...
#include "linux/stat.h"                              // for S_IRUGO, S_IWUSR
#include "linux/stddef.h"                            // for false, true
#include "linux/string.h"                            // for kstrdup_const
#include "linux/sysfs.h"                             // for sysfs_emit, attr...
#include "linux/types.h"                             // for list_head, bool
#include "linux/uaccess.h"                           // for copy_from_user
#include "linux/wait.h"                              // for woken_wake_function

Jonathan Cameron (11):
iio: industrialio-core: Reorder header includes to be alphabetical.
iio: industrialio-core - Bring includes up to date.
iio: industrialio-buffer.c: Bring includes up to date.
iio: industrialio-event.c: Bring includes up to date.
iio: industrialio-trigger.c: Bring includes up to date.
iio: inkern: Bring includes up to date.
iio: configfs: Bring includes up to date
iio: misc core files: Bring includes up to date
iio: industrialio-triggered-buffer: Bring includes up to date.
iio: industrialio-buffer-cb: Bring includes up to date.
iio: kfifo-buf.c: Bring includes up to date.

 drivers/iio/buffer/industrialio-buffer-cb.c   |  7 +++-
 .../buffer/industrialio-triggered-buffer.c    |  6 ++-
 drivers/iio/buffer/kfifo_buf.c                | 15 ++++---
 drivers/iio/industrialio-buffer.c             | 23 ++++++++--
 drivers/iio/industrialio-configfs.c           |  7 ++--
 drivers/iio/industrialio-core.c               | 42 ++++++++++++-------
 drivers/iio/industrialio-event.c              |  9 +++-
 drivers/iio/industrialio-sw-device.c          |  8 ++--
 drivers/iio/industrialio-sw-trigger.c         |  9 ++--
 drivers/iio/industrialio-trigger.c            | 15 +++++--
 drivers/iio/industrialio-triggered-event.c    |  3 +-
 drivers/iio/inkern.c                          |  7 +++-
 12 files changed, 107 insertions(+), 44 deletions(-)
author maintainer
#13 lore raw
Quoted 34 lines · On Sun, 31 Oct 2021 17:08:54 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 4 lines · On Sun, 3 Oct 2021 16:32:55 +0100 Jonathan Cameron <[email protected]> wrote:

From: Jonathan Cameron <[email protected]>

The includes from the various IIO core files have bitrotted over time (and probably were not great in the first place).

Given ongoing churn in core kernel includes as Andy cleans them up, I've pushed this particular work out on a branch at

https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/log/?h=iio-iwyu-cleanups

This will get me 0-day exposure and allow me to keep moving these forwards as the core kernel headers change.

I would like to start merging 'some' of these in the meantime and there are some precursor cleanup patches that I'll pull out separately.

Perhaps most 'useful' is the top patch in that branch which is the iwyu mapping file I've put together to get it to make more reasonable suggestions. Note that there are some cases where the answer isn't obvious and some where you can't push iwyu to do the right thing.

One example is struct regmap which is deliberately opaque. iwyu always wants a forwards definition of it in all files where pointers to it occur, but personally I think including linux/regmap.h is sufficient as that will always have the forwards definition needed.

Note this branch will rebase frequently and may well eat babies. In particularly I will be cherry picking Andy and anyone else's work to the top of it and making changes through the rest of the patches as that affects them.

Quoted 8 lines

I'm not particularly expecting feedback, but I do want to avoid duplicate work. I'm also likely to 'fixing' new code as it comes in based on this toolchain - I may main in reviews or just fix it whilst applying (and tell people obviously!)

Long term plan here is to bring consistency to includes with benefits of resilience and hopefully reducing just how much code is actually pulled in whilst compiling.

I forgot to mention that I've take a stricter view since doing this series so it needs an update even in the tree above. This mostly affects err.h, errno.h, stddef.h and types.h

I'll update those in that tree sometime this week.

Quoted 670 lines

Thanks,

Jonathan

Quoted 664 lines

This series is based loosely on the suggests the include-what-you-use tool provides but with a lot of discretion applied. Note that tool will tell you:
1) What includes provide elements directly used in a given .c file.
2) What includes are providing nothing that is directly used in the .c file.
3) It will not follow 'include chains', then concept being that anything used should be defined in a header directly included.
It can't always distinguish between different paths to the header and knows nothing about intended include structures in the kernel. (for example including eventpoll.h directly is not intended to be safe,
instead poll.h should be used).

In recent times a lot of code has moved around in IIO and as a result often headers have gotten left behind or haven't made the move along with the code they were there to support.

I made some decisions to reduce includes.

#include <linux/device.h>
can be assumed to bring in dev_printk.h and device/bus.h so don't include those directly.
#include <linux/err.h>
is a good general header to bring in errno.h as well as the various PTR_ERR() macros and similar.
#include <linux/poll.h>
brings in everything related to polling.
#include <linux/irq.h> or <linux/interrupt.h> as appropriate will bring in irqreturn.h.

(probably some other cases I've forgotten about).

Andy has been working on breaking up some of the headers that tend to get included everywhere because they are a pile of unrelated things. Some impact of that can be seen in this series.

I would like to move IIO in the right direction even if we then end up with some additional churn in future reflecting changes in the headers we are using. This is an RFC primarily because there is a lot of 'interpretation' involved so I'd like to get high level feedback.

I've included below the suggestions iwyu made for reference. As you can see the raw output is mostly useful for highlighting things that should not be there and roughly what should be.

drivers/iio/buffer/kfifo_buf.c should add these lines:

#include <stddef.h>                  // for size_t, NULL
#include "asm-generic/errno-base.h"  // for EINVAL, EBUSY, ENOMEM
#include "linux/compiler_types.h"    // for __user, inline
#include "linux/errno.h"             // for ERESTARTSYS
#include "linux/export.h"            // for EXPORT_SYMBOL, EXPORT_SYMBOL_GPL
#include "linux/gfp.h"               // for GFP_KERNEL
#include "linux/log2.h"              // for roundup_pow_of_two
#include "linux/stddef.h"            // for true, false
#include "vdso/limits.h"             // for UINT_MAX

struct attribute;

drivers/iio/buffer/kfifo_buf.c should remove these lines:
- #include <linux/poll.h> // lines 14-14
- #include <linux/sched.h> // lines 13-13
- #include <linux/workqueue.h> // lines 6-6

The full include-list for drivers/iio/buffer/kfifo_buf.c:

#include <linux/device.h>            // for devres_add, devres_free, devres_...
#include <linux/iio/buffer.h>        // for iio_device_attach_buffer
#include <linux/iio/buffer_impl.h>   // for iio_buffer, iio_buffer_init, iio...
#include <linux/iio/iio.h>           // for iio_dev, INDIO_BUFFER_SOFTWARE
#include <linux/iio/kfifo_buf.h>     // for devm_iio_kfifo_buffer_setup_ext
#include <linux/kernel.h>            // for container_of
#include <linux/kfifo.h>             // for __kfifo_alloc, kfifo_free, kfifo
#include <linux/module.h>            // for MODULE_LICENSE
#include <linux/mutex.h>             // for mutex_unlock, mutex_lock, mutex_...
#include <linux/slab.h>              // for kfree, kzalloc
#include <stddef.h>                  // for size_t, NULL
#include "asm-generic/errno-base.h"  // for EINVAL, EBUSY, ENOMEM
#include "linux/compiler_types.h"    // for __user, inline
#include "linux/errno.h"             // for ERESTARTSYS
#include "linux/export.h"            // for EXPORT_SYMBOL, EXPORT_SYMBOL_GPL
#include "linux/gfp.h"               // for GFP_KERNEL
#include "linux/log2.h"              // for roundup_pow_of_two
#include "linux/stddef.h"            // for true, false
#include "vdso/limits.h"             // for UINT_MAX

struct attribute;

drivers/iio/buffer/industrialio-buffer-cb.c should add these lines:

#include <stddef.h>                                  // for NULL, size_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for set_bit
#include "asm-generic/errno-base.h"                  // for EINVAL, ENOMEM
#include "linux/bitmap.h"                            // for bitmap_free, bit...
#include "linux/dev_printk.h"                        // for dev_err
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/list.h"                              // for INIT_LIST_HEAD

struct device;

drivers/iio/buffer/industrialio-buffer-cb.c should remove these lines:

The full include-list for drivers/iio/buffer/industrialio-buffer-cb.c:

#include <linux/err.h>                               // for ERR_PTR, IS_ERR
#include <linux/export.h>                            // for EXPORT_SYMBOL_GPL
#include <linux/iio/buffer_impl.h>                   // for iio_buffer, iio_...
#include <linux/iio/consumer.h>                      // for iio_channel, iio...
#include <linux/iio/iio.h>                           // for INDIO_BUFFER_SOF...
#include <linux/kernel.h>                            // for container_of
#include <linux/module.h>                            // for MODULE_AUTHOR
#include <linux/slab.h>                              // for kfree, kzalloc
#include <stddef.h>                                  // for NULL, size_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for set_bit
#include "asm-generic/errno-base.h"                  // for EINVAL, ENOMEM
#include "linux/bitmap.h"                            // for bitmap_free, bit...
#include "linux/dev_printk.h"                        // for dev_err
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/list.h"                              // for INIT_LIST_HEAD

struct device;

drivers/iio/buffer/industrialio-triggered-buffer.c should add these lines:

#include <stddef.h>                      // for NULL
#include "asm-generic/errno-base.h"      // for ENOMEM
#include "linux/device.h"                // for devm_add_action_or_reset
#include "linux/interrupt.h"             // for IRQF_ONESHOT
#include "linux/irqreturn.h"             // for irqreturn_t

struct attribute;

drivers/iio/buffer/industrialio-triggered-buffer.c should remove these lines:
- #include <linux/kernel.h> // lines 7-7

The full include-list for drivers/iio/buffer/industrialio-triggered-buffer.c:

#include <linux/export.h>                // for EXPORT_SYMBOL, EXPORT_SYMBOL...
#include <linux/iio/buffer.h>            // for iio_device_attach_buffer
#include <linux/iio/buffer_impl.h>       // for iio_buffer
#include <linux/iio/iio.h>               // for iio_dev, iio_device_id, INDI...
#include <linux/iio/kfifo_buf.h>         // for iio_kfifo_free, iio_kfifo_al...
#include <linux/iio/trigger_consumer.h>  // for iio_dealloc_pollfunc, iio_al...
#include <linux/iio/triggered_buffer.h>  // for devm_iio_triggered_buffer_se...
#include <linux/module.h>                // for MODULE_AUTHOR, MODULE_DESCRI...
#include <stddef.h>                      // for NULL
#include "asm-generic/errno-base.h"      // for ENOMEM
#include "linux/device.h"                // for devm_add_action_or_reset
#include "linux/interrupt.h"             // for IRQF_ONESHOT
#include "linux/irqreturn.h"             // for irqreturn_t

struct attribute;

drivers/iio/industrialio-triggered-event.c should add these lines:

#include <stddef.h>                      // for NULL
#include "asm-generic/errno-base.h"      // for ENOMEM
#include "linux/interrupt.h"             // for IRQF_ONESHOT
#include "linux/irqreturn.h"             // for irqreturn_t

drivers/iio/industrialio-triggered-event.c should remove these lines:
- #include <linux/kernel.h> // lines 6-6

The full include-list for drivers/iio/industrialio-triggered-event.c:

#include <linux/export.h>                // for EXPORT_SYMBOL
#include <linux/iio/iio.h>               // for iio_dev, iio_device_id, INDI...
#include <linux/iio/trigger_consumer.h>  // for iio_alloc_pollfunc, iio_deal...
#include <linux/iio/triggered_event.h>   // for iio_triggered_event_cleanup
#include <linux/module.h>                // for MODULE_AUTHOR, MODULE_DESCRI...
#include <stddef.h>                      // for NULL
#include "asm-generic/errno-base.h"      // for ENOMEM
#include "linux/interrupt.h"             // for IRQF_ONESHOT
#include "linux/irqreturn.h"             // for irqreturn_t

drivers/iio/industrialio-event.c should add these lines:

#include <asm/bitops.h>                              // for test_bit
#include <stddef.h>                                  // for NULL, size_t
#include <sys/types.h>                               // for ssize_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit, test_...
#include "asm-generic/errno-base.h"                  // for EINVAL, ENODEV
#include "asm-generic/fcntl.h"                       // for O_NONBLOCK, O_CL...
#include "asm-generic/int-ll64.h"                    // for s64, u64
#include "asm/string_64.h"                           // for memcpy
#include "linux/bitops.h"                            // for for_each_set_bit
#include "linux/compiler_types.h"                    // for __user, inline
#include "linux/errno.h"                             // for ERESTARTSYS
#include "linux/eventpoll.h"                         // for EPOLLIN, EPOLLRD...
#include "linux/export.h"                            // for EXPORT_SYMBOL
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/iio/events.h"                        // for iio_event_data
#include "linux/iio/types.h"                         // for iio_event_direction
#include "linux/kstrtox.h"                           // for strtobool
#include "linux/list.h"                              // for INIT_LIST_HEAD
#include "linux/mutex.h"                             // for mutex_lock_inter...
#include "linux/stddef.h"                            // for false, true
#include "linux/sysfs.h"                             // for attribute_group
#include "linux/types.h"                             // for list_head, bool

drivers/iio/industrialio-event.c should remove these lines:
- #include <linux/iio/events.h> // lines 24-24
- #include <linux/module.h> // lines 14-14
- #include <linux/sched.h> // lines 16-16

The full include-list for drivers/iio/industrialio-event.c:

#include <asm/bitops.h>                              // for test_bit
#include <linux/anon_inodes.h>                       // for anon_inode_getfd
#include <linux/device.h>                            // for device_attribute
#include <linux/fs.h>                                // for file, noop_llseek
#include <linux/iio/iio-opaque.h>                    // for iio_dev_opaque
#include <linux/iio/iio.h>                           // for iio_dev, iio_eve...
#include <linux/iio/sysfs.h>                         // for iio_dev_attr
#include <linux/kernel.h>                            // for kasprintf, ARRAY...
#include <linux/kfifo.h>                             // for kfifo_is_empty
#include <linux/poll.h>                              // for poll_wait
#include <linux/slab.h>                              // for kfree, kcalloc
#include <linux/uaccess.h>                           // for copy_to_user
#include <linux/wait.h>                              // for init_waitqueue_head
#include <stddef.h>                                  // for NULL, size_t
#include <sys/types.h>                               // for ssize_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit, test_...
#include "asm-generic/errno-base.h"                  // for EINVAL, ENODEV
#include "asm-generic/fcntl.h"                       // for O_NONBLOCK, O_CL...
#include "asm-generic/int-ll64.h"                    // for s64, u64
#include "asm/string_64.h"                           // for memcpy
#include "iio_core.h"                                // for iio_free_chan_de...
#include "linux/bitops.h"                            // for for_each_set_bit
#include "linux/compiler_types.h"                    // for __user, inline
#include "linux/errno.h"                             // for ERESTARTSYS
#include "linux/eventpoll.h"                         // for EPOLLIN, EPOLLRD...
#include "linux/export.h"                            // for EXPORT_SYMBOL
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/iio/events.h"                        // for iio_event_data
#include "linux/iio/types.h"                         // for iio_event_direction
#include "linux/kstrtox.h"                           // for strtobool
#include "linux/list.h"                              // for INIT_LIST_HEAD
#include "linux/mutex.h"                             // for mutex_lock_inter...
#include "linux/stddef.h"                            // for false, true
#include "linux/sysfs.h"                             // for attribute_group
#include "linux/types.h"                             // for list_head, bool

drivers/iio/industrialio-core.c should add these lines:

#include <asm/bug.h>                                 // for WARN
#include <linux/ktime.h>                             // for ktime_get_bootti...
#include <stddef.h>                                  // for NULL, size_t
#include <stdint.h>                                  // for uintptr_t
#include <sys/types.h>                               // for ssize_t, dev_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit, test_...
#include "asm-generic/errno-base.h"                  // for EINVAL, EBUSY
#include "asm-generic/int-ll64.h"                    // for s64, u64
#include "asm/bug.h"                                 // for BUG
#include "asm/page_types.h"                          // for PAGE_SIZE
#include "asm/string_64.h"                           // for memcpy
#include "generated/autoconf.h"                      // for CONFIG_DEBUG_FS
#include "linux/align.h"                             // for ALIGN
#include "linux/bitops.h"                            // for for_each_set_bit
#include "linux/compiler_attributes.h"               // for fallthrough
#include "linux/compiler_types.h"                    // for __user
#include "linux/dev_printk.h"                        // for dev_err, dev_info
#include "linux/device/bus.h"                        // for bus_unregister
#include "linux/export.h"                            // for EXPORT_SYMBOL_GPL
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/hrtimer.h"                           // for hrtimer_resolution
#include "linux/iio/types.h"                         // for IIO_VAL_INT, IIO...
#include "linux/init.h"                              // for __exit, __init
#include "linux/kstrtox.h"                           // for kstrtoint
#include "linux/ktime.h"                             // for ktime_to_ns
#include "linux/list.h"                              // for INIT_LIST_HEAD
#include "linux/math.h"                              // for abs
#include "linux/math64.h"                            // for div_s64_rem, div...
#include "linux/minmax.h"                            // for min_t
#include "linux/of.h"                                // for of_get_property
#include "linux/printk.h"                            // for pr_err
#include "linux/stat.h"                              // for S_IRUGO, S_IWUSR
#include "linux/stddef.h"                            // for false, true
#include "linux/string.h"                            // for sysfs_streq, str...
#include "linux/sysfs.h"                             // for sysfs_emit_at
#include "linux/time.h"                              // for CLOCK_BOOTTIME
#include "linux/time64.h"                            // for timespec64_to_ns
#include "linux/timex.h"                             // for shift_right
#include "linux/types.h"                             // for list_head, bool
#include "linux/uaccess.h"                           // for copy_from_user
#include "vdso/ktime.h"                              // for LOW_RES_NSEC

struct iio_buffer;

drivers/iio/industrialio-core.c should remove these lines:
- #include <linux/anon_inodes.h> // lines 24-24
- #include <linux/iio/buffer.h> // lines 33-33
- #include <linux/iio/buffer_impl.h> // lines 34-34
- #include <linux/iio/events.h> // lines 32-32
- #include <linux/poll.h> // lines 18-18
- #include <linux/sched.h> // lines 20-20
- #include <linux/wait.h> // lines 21-21

The full include-list for drivers/iio/industrialio-core.c:

#include <asm/bug.h>                                 // for WARN
#include <linux/cdev.h>                              // for cdev_init, cdev_...
#include <linux/debugfs.h>                           // for debugfs_create_dir
#include <linux/device.h>                            // for device, device_a...
#include <linux/err.h>                               // for IS_ERR, PTR_ERR
#include <linux/fs.h>                                // for noop_llseek, inode
#include <linux/idr.h>                               // for DEFINE_IDA, ida_...
#include <linux/iio/iio-opaque.h>                    // for iio_dev_opaque
#include <linux/iio/iio.h>                           // for iio_dev, iio_cha...
#include <linux/iio/sysfs.h>                         // for iio_dev_attr
#include <linux/kdev_t.h>                            // for MAJOR, MKDEV
#include <linux/kernel.h>                            // for kasprintf, sscanf
#include <linux/ktime.h>                             // for ktime_get_bootti...
#include <linux/module.h>                            // for MODULE_AUTHOR
#include <linux/mutex.h>                             // for mutex_unlock
#include <linux/property.h>                          // for device_property_...
#include <linux/slab.h>                              // for kfree, kzalloc
#include <stddef.h>                                  // for NULL, size_t
#include <stdint.h>                                  // for uintptr_t
#include <sys/types.h>                               // for ssize_t, dev_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit, test_...
#include "asm-generic/errno-base.h"                  // for EINVAL, EBUSY
#include "asm-generic/int-ll64.h"                    // for s64, u64
#include "asm/bug.h"                                 // for BUG
#include "asm/page_types.h"                          // for PAGE_SIZE
#include "asm/string_64.h"                           // for memcpy
#include "generated/autoconf.h"                      // for CONFIG_DEBUG_FS
#include "iio_core.h"                                // for iio_ioctl_handler
#include "iio_core_trigger.h"                        // for iio_device_regis...
#include "linux/align.h"                             // for ALIGN
#include "linux/bitops.h"                            // for for_each_set_bit
#include "linux/compiler_attributes.h"               // for fallthrough
#include "linux/compiler_types.h"                    // for __user
#include "linux/dev_printk.h"                        // for dev_err, dev_info
#include "linux/device/bus.h"                        // for bus_unregister
#include "linux/export.h"                            // for EXPORT_SYMBOL_GPL
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/hrtimer.h"                           // for hrtimer_resolution
#include "linux/iio/types.h"                         // for IIO_VAL_INT, IIO...
#include "linux/init.h"                              // for __exit, __init
#include "linux/kstrtox.h"                           // for kstrtoint
#include "linux/ktime.h"                             // for ktime_to_ns
#include "linux/list.h"                              // for INIT_LIST_HEAD
#include "linux/math.h"                              // for abs
#include "linux/math64.h"                            // for div_s64_rem, div...
#include "linux/minmax.h"                            // for min_t
#include "linux/of.h"                                // for of_get_property
#include "linux/printk.h"                            // for pr_err
#include "linux/stat.h"                              // for S_IRUGO, S_IWUSR
#include "linux/stddef.h"                            // for false, true
#include "linux/string.h"                            // for sysfs_streq, str...
#include "linux/sysfs.h"                             // for sysfs_emit_at
#include "linux/time.h"                              // for CLOCK_BOOTTIME
#include "linux/time64.h"                            // for timespec64_to_ns
#include "linux/timex.h"                             // for shift_right
#include "linux/types.h"                             // for list_head, bool
#include "linux/uaccess.h"                           // for copy_from_user
#include "vdso/ktime.h"                              // for LOW_RES_NSEC

struct iio_buffer;

drivers/iio/industrialio-configfs.c should add these lines:
#include "linux/export.h" // for EXPORT_SYMBOL, THIS_MODULE
#include "linux/mutex.h" // for mutex, __MUTEX_INITIALIZER

drivers/iio/industrialio-configfs.c should remove these lines:
- #include <linux/iio/configfs.h> // lines 15-15
- #include <linux/iio/iio.h> // lines 14-14
- #include <linux/kmod.h> // lines 11-11
- #include <linux/slab.h> // lines 12-12

The full include-list for drivers/iio/industrialio-configfs.c:

#include <linux/configfs.h>  // for configfs_subsystem, config_group_init
#include <linux/init.h>      // for __exit, __init
#include <linux/module.h>    // for MODULE_AUTHOR, MODULE_DESCRIPTION, MODUL...
#include "linux/export.h"    // for EXPORT_SYMBOL, THIS_MODULE
#include "linux/mutex.h"     // for mutex, __MUTEX_INITIALIZER

drivers/iio/inkern.c should add these lines:

#include <stddef.h>                  // for NULL, size_t
#include <stdint.h>                  // for uint32_t
#include <sys/types.h>               // for ssize_t
#include "asm-generic/errno-base.h"  // for ENODEV, EINVAL, ENOMEM
#include "asm-generic/int-ll64.h"    // for s64
#include "generated/autoconf.h"      // for CONFIG_OF
#include "linux/dev_printk.h"        // for dev_err
#include "linux/device.h"            // for devm_add_action_or_reset, dev_name
#include "linux/device/bus.h"        // for bus_find_device
#include "linux/errno.h"             // for EPROBE_DEFER
#include "linux/gfp.h"               // for GFP_KERNEL
#include "linux/iio/types.h"         // for iio_chan_info_enum, IIO_CHAN_INF...
#include "linux/list.h"              // for list_add_tail, list_del, list_fo...
#include "linux/math64.h"            // for div_s64
#include "linux/printk.h"            // for pr_err
#include "linux/string.h"            // for strcmp
#include "linux/types.h"             // for list_head

drivers/iio/inkern.c should remove these lines:

The full include-list for drivers/iio/inkern.c:

#include <linux/err.h>               // for ERR_PTR, IS_ERR, PTR_ERR
#include <linux/export.h>            // for EXPORT_SYMBOL_GPL
#include <linux/iio/consumer.h>      // for iio_channel, devm_iio_channel_get
#include <linux/iio/driver.h>        // for devm_iio_map_array_register, iio...
#include <linux/iio/iio-opaque.h>    // for iio_dev_opaque, to_iio_dev_opaque
#include <linux/iio/iio.h>           // for iio_dev, iio_device_put, iio_cha...
#include <linux/iio/machine.h>       // for iio_map
#include <linux/mutex.h>             // for mutex_unlock, mutex_lock, mutex
#include <linux/of.h>                // for of_phandle_args, of_parse_phandl...
#include <linux/slab.h>              // for kfree, kzalloc, kcalloc
#include <stddef.h>                  // for NULL, size_t
#include <stdint.h>                  // for uint32_t
#include <sys/types.h>               // for ssize_t
#include "asm-generic/errno-base.h"  // for ENODEV, EINVAL, ENOMEM
#include "asm-generic/int-ll64.h"    // for s64
#include "generated/autoconf.h"      // for CONFIG_OF
#include "iio_core.h"                // for iio_device_type
#include "linux/dev_printk.h"        // for dev_err
#include "linux/device.h"            // for devm_add_action_or_reset, dev_name
#include "linux/device/bus.h"        // for bus_find_device
#include "linux/errno.h"             // for EPROBE_DEFER
#include "linux/gfp.h"               // for GFP_KERNEL
#include "linux/iio/types.h"         // for iio_chan_info_enum, IIO_CHAN_INF...
#include "linux/list.h"              // for list_add_tail, list_del, list_fo...
#include "linux/math64.h"            // for div_s64
#include "linux/printk.h"            // for pr_err
#include "linux/string.h"            // for strcmp
#include "linux/types.h"             // for list_head

drivers/iio/industrialio-sw-device.c should add these lines:

#include <stddef.h>                  // for NULL
#include "asm-generic/errno-base.h"  // for EBUSY, EINVAL
#include "linux/err.h"               // for IS_ERR, ERR_CAST, ERR_PTR, PTR_ERR
#include "linux/export.h"            // for EXPORT_SYMBOL, THIS_MODULE
#include "linux/mutex.h"             // for mutex_lock, mutex_unlock, mutex
#include "linux/printk.h"            // for pr_err
#include "linux/string.h"            // for strlen, strcmp
#include "linux/types.h"             // for list_head

drivers/iio/industrialio-sw-device.c should remove these lines:
- #include <linux/kmod.h> // lines 10-10
- #include <linux/slab.h> // lines 12-12

The full include-list for drivers/iio/industrialio-sw-device.c:

#include <linux/configfs.h>          // for configfs_register_default_group
#include <linux/iio/configfs.h>      // for iio_configfs_subsys
#include <linux/iio/sw_device.h>     // for iio_sw_device_type, iio_sw_device
#include <linux/init.h>              // for __exit, __init
#include <linux/list.h>              // for list_add_tail, list_del, LIST_HEAD
#include <linux/module.h>            // for module_put, try_module_get, MODU...
#include <stddef.h>                  // for NULL
#include "asm-generic/errno-base.h"  // for EBUSY, EINVAL
#include "linux/err.h"               // for IS_ERR, ERR_CAST, ERR_PTR, PTR_ERR
#include "linux/export.h"            // for EXPORT_SYMBOL, THIS_MODULE
#include "linux/mutex.h"             // for mutex_lock, mutex_unlock, mutex
#include "linux/printk.h"            // for pr_err
#include "linux/string.h"            // for strlen, strcmp
#include "linux/types.h"             // for list_head

drivers/iio/industrialio-trigger.c should add these lines:

#include <asm/bug.h>                                 // for WARN_ON
#include <linux/irq.h>                               // for generic_handle_irq
#include <stdarg.h>                                  // for va_list
#include <stddef.h>                                  // for NULL, size_t
#include <sys/types.h>                               // for ssize_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit
#include "asm-generic/errno-base.h"                  // for EINVAL, EBUSY
#include "generated/autoconf.h"                      // for CONFIG_IIO_CONSU...
#include "linux/atomic/atomic-instrumented.h"        // for atomic_read, ato...
#include "linux/bitmap.h"                            // for bitmap_empty
#include "linux/compiler_attributes.h"               // for __printf
#include "linux/export.h"                            // for EXPORT_SYMBOL
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/irq.h"                               // for irq_data_get_irq...
#include "linux/irqreturn.h"                         // for irqreturn_t, IRQ...
#include "linux/log2.h"                              // for ilog2
#include "linux/module.h"                            // for module_put, __mo...
#include "linux/mutex.h"                             // for mutex_unlock
#include "linux/printk.h"                            // for pr_err
#include "linux/stat.h"                              // for S_IRUGO, S_IWUSR
#include "linux/stdarg.h"                            // for va_end, va_start
#include "linux/stddef.h"                            // for true, false
#include "linux/string.h"                            // for strcmp, sysfs_streq
#include "linux/sysfs.h"                             // for sysfs_emit, ATTR...
#include "linux/types.h"                             // for list_head, bool

drivers/iio/industrialio-trigger.c should remove these lines:
- #include <linux/err.h> // lines 9-9

The full include-list for drivers/iio/industrialio-trigger.c:

#include <asm/bug.h>                                 // for WARN_ON
#include <linux/device.h>                            // for device, device_del
#include <linux/idr.h>                               // for ida_simple_remove
#include <linux/iio/iio-opaque.h>                    // for iio_dev_opaque
#include <linux/iio/iio.h>                           // for iio_dev, dev_to_...
#include <linux/iio/trigger.h>                       // for iio_trigger, iio...
#include <linux/iio/trigger_consumer.h>              // for iio_poll_func
#include <linux/interrupt.h>                         // for free_irq, reques...
#include <linux/irq.h>                               // for generic_handle_irq
#include <linux/kernel.h>                            // for kvasprintf, cont...
#include <linux/list.h>                              // for list_add_tail
#include <linux/slab.h>                              // for kfree, kmalloc
#include <stdarg.h>                                  // for va_list
#include <stddef.h>                                  // for NULL, size_t
#include <sys/types.h>                               // for ssize_t
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit
#include "asm-generic/errno-base.h"                  // for EINVAL, EBUSY
#include "generated/autoconf.h"                      // for CONFIG_IIO_CONSU...
#include "iio_core.h"                                // for iio_device_regis...
#include "iio_core_trigger.h"                        // for iio_device_regis...
#include "linux/atomic/atomic-instrumented.h"        // for atomic_read, ato...
#include "linux/bitmap.h"                            // for bitmap_empty
#include "linux/compiler_attributes.h"               // for __printf
#include "linux/export.h"                            // for EXPORT_SYMBOL
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/irq.h"                               // for irq_data_get_irq...
#include "linux/irqreturn.h"                         // for irqreturn_t, IRQ...
#include "linux/log2.h"                              // for ilog2
#include "linux/module.h"                            // for module_put, __mo...
#include "linux/mutex.h"                             // for mutex_unlock
#include "linux/printk.h"                            // for pr_err
#include "linux/stat.h"                              // for S_IRUGO, S_IWUSR
#include "linux/stdarg.h"                            // for va_end, va_start
#include "linux/stddef.h"                            // for true, false
#include "linux/string.h"                            // for strcmp, sysfs_streq
#include "linux/sysfs.h"                             // for sysfs_emit, ATTR...
#include "linux/types.h"                             // for list_head, bool

drivers/iio/industrialio-sw-trigger.c should add these lines:

#include <stddef.h>                  // for NULL
#include "asm-generic/errno-base.h"  // for EBUSY, EINVAL
#include "linux/err.h"               // for IS_ERR, ERR_CAST, ERR_PTR, PTR_ERR
#include "linux/export.h"            // for EXPORT_SYMBOL, THIS_MODULE
#include "linux/mutex.h"             // for mutex_lock, mutex_unlock, mutex
#include "linux/printk.h"            // for pr_err
#include "linux/string.h"            // for strlen, strcmp
#include "linux/types.h"             // for list_head

drivers/iio/industrialio-sw-trigger.c should remove these lines:
- #include <linux/kmod.h> // lines 10-10
- #include <linux/slab.h> // lines 12-12

The full include-list for drivers/iio/industrialio-sw-trigger.c:

#include <linux/configfs.h>          // for configfs_register_default_group
#include <linux/iio/configfs.h>      // for iio_configfs_subsys
#include <linux/iio/sw_trigger.h>    // for iio_sw_trigger_type, iio_sw_trigger
#include <linux/init.h>              // for __exit, __init
#include <linux/list.h>              // for list_add_tail, list_del, LIST_HEAD
#include <linux/module.h>            // for module_put, try_module_get, MODU...
#include <stddef.h>                  // for NULL
#include "asm-generic/errno-base.h"  // for EBUSY, EINVAL
#include "linux/err.h"               // for IS_ERR, ERR_CAST, ERR_PTR, PTR_ERR
#include "linux/export.h"            // for EXPORT_SYMBOL, THIS_MODULE
#include "linux/mutex.h"             // for mutex_lock, mutex_unlock, mutex
#include "linux/printk.h"            // for pr_err
#include "linux/string.h"            // for strlen, strcmp
#include "linux/types.h"             // for list_head

drivers/iio/industrialio-buffer.c should add these lines:

#include <asm/bitops.h>                              // for test_bit
#include <asm/bug.h>                                 // for WARN
#include <stddef.h>                                  // for size_t, NULL
#include <sys/types.h>                               // for ssize_t
#include "asm-generic/bitops/find.h"                 // for find_next_bit
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit, set_bit
#include "asm-generic/errno-base.h"                  // for ENOMEM, EINVAL
#include "asm-generic/fcntl.h"                       // for O_NONBLOCK, O_CL...
#include "asm-generic/int-ll64.h"                    // for u8
#include "asm/current.h"                             // for current
#include "asm/string_64.h"                           // for memcpy, memset
#include "linux/align.h"                             // for ALIGN
#include "linux/bitmap.h"                            // for bitmap_free, bit...
#include "linux/bitops.h"                            // for for_each_set_bit
#include "linux/compiler_types.h"                    // for __user
#include "linux/dev_printk.h"                        // for dev_dbg
#include "linux/errno.h"                             // for ERESTARTSYS
#include "linux/eventpoll.h"                         // for EPOLLIN, EPOLLRD...
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/iio/buffer.h"                        // for IIO_BUFFER_GET_F...
#include "linux/iio/types.h"                         // for IIO_TIMESTAMP
#include "linux/kconfig.h"                           // for __LITTLE_ENDIAN
#include "linux/kref.h"                              // for kref_get, kref_init
#include "linux/kstrtox.h"                           // for strtobool, kstrt...
#include "linux/list.h"                              // for list_empty, INIT...
#include "linux/math.h"                              // for roundup
#include "linux/minmax.h"                            // for max, min, min_t
#include "linux/mutex.h"                             // for mutex_lock, mute...
#include "linux/sched.h"                             // for MAX_SCHEDULE_TIM...
#include "linux/stat.h"                              // for S_IRUGO, S_IWUSR
#include "linux/stddef.h"                            // for false, true
#include "linux/string.h"                            // for kstrdup_const
#include "linux/sysfs.h"                             // for sysfs_emit, attr...
#include "linux/types.h"                             // for list_head, bool
#include "linux/uaccess.h"                           // for copy_from_user
#include "linux/wait.h"                              // for woken_wake_function

drivers/iio/industrialio-buffer.c should remove these lines:
- #include <linux/cdev.h> // lines 18-18

The full include-list for drivers/iio/industrialio-buffer.c:

#include <asm/bitops.h>                              // for test_bit
#include <asm/bug.h>                                 // for WARN
#include <linux/anon_inodes.h>                       // for anon_inode_getfd
#include <linux/device.h>                            // for device_attribute
#include <linux/export.h>                            // for EXPORT_SYMBOL_GPL
#include <linux/file.h>                              // for put_unused_fd
#include <linux/fs.h>                                // for file, noop_llseek
#include <linux/iio/buffer.h>                        // for iio_device_attac...
#include <linux/iio/buffer_impl.h>                   // for iio_buffer, iio_...
#include <linux/iio/iio-opaque.h>                    // for iio_dev_opaque
#include <linux/iio/iio.h>                           // for iio_dev, iio_cha...
#include <linux/iio/sysfs.h>                         // for iio_dev_attr
#include <linux/kernel.h>                            // for ARRAY_SIZE, cont...
#include <linux/poll.h>                              // for poll_wait
#include <linux/sched/signal.h>                      // for signal_pending
#include <linux/slab.h>                              // for kfree, kzalloc
#include <stddef.h>                                  // for size_t, NULL
#include <sys/types.h>                               // for ssize_t
#include "asm-generic/bitops/find.h"                 // for find_next_bit
#include "asm-generic/bitops/instrumented-atomic.h"  // for clear_bit, set_bit
#include "asm-generic/errno-base.h"                  // for ENOMEM, EINVAL
#include "asm-generic/fcntl.h"                       // for O_NONBLOCK, O_CL...
#include "asm-generic/int-ll64.h"                    // for u8
#include "asm/current.h"                             // for current
#include "asm/string_64.h"                           // for memcpy, memset
#include "iio_core.h"                                // for __iio_add_chan_d...
#include "iio_core_trigger.h"                        // for iio_trigger_deta...
#include "linux/align.h"                             // for ALIGN
#include "linux/bitmap.h"                            // for bitmap_free, bit...
#include "linux/bitops.h"                            // for for_each_set_bit
#include "linux/compiler_types.h"                    // for __user
#include "linux/dev_printk.h"                        // for dev_dbg
#include "linux/errno.h"                             // for ERESTARTSYS
#include "linux/eventpoll.h"                         // for EPOLLIN, EPOLLRD...
#include "linux/gfp.h"                               // for GFP_KERNEL
#include "linux/iio/buffer.h"                        // for IIO_BUFFER_GET_F...
#include "linux/iio/types.h"                         // for IIO_TIMESTAMP
#include "linux/kconfig.h"                           // for __LITTLE_ENDIAN
#include "linux/kref.h"                              // for kref_get, kref_init
#include "linux/kstrtox.h"                           // for strtobool, kstrt...
#include "linux/list.h"                              // for list_empty, INIT...
#include "linux/math.h"                              // for roundup
#include "linux/minmax.h"                            // for max, min, min_t
#include "linux/mutex.h"                             // for mutex_lock, mute...
#include "linux/sched.h"                             // for MAX_SCHEDULE_TIM...
#include "linux/stat.h"                              // for S_IRUGO, S_IWUSR
#include "linux/stddef.h"                            // for false, true
#include "linux/string.h"                            // for kstrdup_const
#include "linux/sysfs.h"                             // for sysfs_emit, attr...
#include "linux/types.h"                             // for list_head, bool
#include "linux/uaccess.h"                           // for copy_from_user
#include "linux/wait.h"                              // for woken_wake_function

Jonathan Cameron (11):
iio: industrialio-core: Reorder header includes to be alphabetical.
iio: industrialio-core - Bring includes up to date.
iio: industrialio-buffer.c: Bring includes up to date.
iio: industrialio-event.c: Bring includes up to date.
iio: industrialio-trigger.c: Bring includes up to date.
iio: inkern: Bring includes up to date.
iio: configfs: Bring includes up to date
iio: misc core files: Bring includes up to date
iio: industrialio-triggered-buffer: Bring includes up to date.
iio: industrialio-buffer-cb: Bring includes up to date.
iio: kfifo-buf.c: Bring includes up to date.

 drivers/iio/buffer/industrialio-buffer-cb.c   |  7 +++-
 .../buffer/industrialio-triggered-buffer.c    |  6 ++-
 drivers/iio/buffer/kfifo_buf.c                | 15 ++++---
 drivers/iio/industrialio-buffer.c             | 23 ++++++++--
 drivers/iio/industrialio-configfs.c           |  7 ++--
 drivers/iio/industrialio-core.c               | 42 ++++++++++++-------
 drivers/iio/industrialio-event.c              |  9 +++-
 drivers/iio/industrialio-sw-device.c          |  8 ++--
 drivers/iio/industrialio-sw-trigger.c         |  9 ++--
 drivers/iio/industrialio-trigger.c            | 15 +++++--
 drivers/iio/industrialio-triggered-event.c    |  3 +-
 drivers/iio/inkern.c                          |  7 +++-
 12 files changed, 107 insertions(+), 44 deletions(-)
#14 lore raw
Quoted 4 lines · Jonathan Cameron
Quoted 2 lines · On Sun, 31 Oct 2021 17:08:54 +0000 Jonathan Cameron <[email protected]> wrote:

On Sun, 3 Oct 2021 16:32:55 +0100
Jonathan Cameron <[email protected]> wrote:

...

Quoted 7 lines
Quoted 7 lines

Given ongoing churn in core kernel includes as Andy cleans them up, I've pushed this particular work out on a branch at

https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/log/?h=iio-iwyu-cleanups

This will get me 0-day exposure and allow me to keep moving these forwards as the core kernel headers change.

Thanks! I'm in favour of the work. Here are few things though:
- blank line in between of the groups of headers (like before iio/*)
- fixing properly bitops.h and other typos (hope lkp will tell you about)
- thinking more about the list of very-low-level includes (see below)

On top of that, the main idea behind header usage is to make sure we have no circular and other hell dependencies in the *headers*, C-files can go with more relaxed rules (but again, I'm in favour of the series and effort).

Quoted 23 lines
Quoted 23 lines

I would like to start merging 'some' of these in the meantime and there are some precursor cleanup patches that I'll pull out separately.

Perhaps most 'useful' is the top patch in that branch which is the iwyu mapping file I've put together to get it to make more reasonable suggestions. Note that there are some cases where the answer isn't obvious and some where you can't push iwyu to do the right thing.

One example is struct regmap which is deliberately opaque. iwyu always wants a forwards definition of it in all files where pointers to it occur, but personally I think including linux/regmap.h is sufficient as that will always have the forwards definition needed.

Note this branch will rebase frequently and may well eat babies. In particularly I will be cherry picking Andy and anyone else's work to the top of it and making changes through the rest of the patches as that affects them.

I'm not particularly expecting feedback, but I do want to avoid duplicate work. I'm also likely to 'fixing' new code as it comes in based on this toolchain - I may main in reviews or just fix it whilst applying (and tell people obviously!)

Quoted 7 lines
Quoted 3 lines

Long term plan here is to bring consistency to includes with benefits of resilience and hopefully reducing just how much code is actually pulled in whilst compiling.

I forgot to mention that I've take a stricter view since doing this series so it needs an update even in the tree above. This mostly affects err.h, errno.h, stddef.h and types.h

I don't think we need to include stddef.h to every C file, it should be guaranteed via something like types.h or so.

Quoted 1 line

I'll update those in that tree sometime this week.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#15 lore raw
Quoted 11 lines · On Sun, 31 Oct 2021 22:21:44 +0200 Andy Shevchenko <[email protected]>…
Quoted 4 lines · Jonathan Cameron
Quoted 2 lines · On Sun, 31 Oct 2021 17:08:54 +0000 Jonathan Cameron <[email protected]> wrote:

On Sun, 3 Oct 2021 16:32:55 +0100
Jonathan Cameron <[email protected]> wrote:

...

Quoted 3 lines
Quoted 3 lines

Given ongoing churn in core kernel includes as Andy cleans them up, I've pushed this particular work out on a branch at

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/log/?h=iio-iwyu-cleanups

This will get me 0-day exposure and allow me to keep moving these forwards as the core kernel headers change.

Thanks! I'm in favour of the work. Here are few things though:
- blank line in between of the groups of headers (like before iio/*)

Ok. I was trying to leave style in keeping with what was there in drivers, but fair enough can standardise on that.

Quoted 1 line

- fixing properly bitops.h and other typos (hope lkp will tell you about)

Huh. I'll watch out for that as getting clean builds...

Quoted 1 line

- thinking more about the list of very-low-level includes (see below)

Agreed. I'm not sure on some of these - one of the big reasons this is a work in progress.

Quoted 5 lines

On top of that, the main idea behind header usage is to make sure we have no circular and other hell dependencies in the *headers*, C-files can go with more relaxed rules (but again, I'm in favour of the series and effort).

Agreed, but added advantage of this tooling is identifying the entirely pointless includes - of which there are lots. Getting rid of those was my main motivation in this.

Getting the balance right is going to be the trick and I'd rather a tool that told us (more or less) that we have things correct than rely on 'common practice'.

Quoted 28 lines
Quoted 28 lines
Quoted 27 lines

I would like to start merging 'some' of these in the meantime and there are some precursor cleanup patches that I'll pull out separately.

Perhaps most 'useful' is the top patch in that branch which is the iwyu mapping file I've put together to get it to make more reasonable suggestions. Note that there are some cases where the answer isn't obvious and some where you can't push iwyu to do the right thing.

One example is struct regmap which is deliberately opaque. iwyu always wants a forwards definition of it in all files where pointers to it occur, but personally I think including linux/regmap.h is sufficient as that will always have the forwards definition needed.

Note this branch will rebase frequently and may well eat babies. In particularly I will be cherry picking Andy and anyone else's work to the top of it and making changes through the rest of the patches as that affects them.

I'm not particularly expecting feedback, but I do want to avoid duplicate work. I'm also likely to 'fixing' new code as it comes in based on this toolchain - I may main in reviews or just fix it whilst applying (and tell people obviously!)

Long term plan here is to bring consistency to includes with benefits of resilience and hopefully reducing just how much code is actually pulled in whilst compiling.

Quoted 6 lines
Quoted 3 lines

I forgot to mention that I've take a stricter view since doing this series so it needs an update even in the tree above. This mostly affects err.h, errno.h, stddef.h and types.h

I don't think we need to include stddef.h to every C file, it should be guaranteed via something like types.h or so.

There are places with stddef.h but not types.h required. I debated which way to go on that and hence ended up with both for now, but it's obviously easy to tweak.

It may be that long term we look to have a standard kernel iwyu mapping file. It's possible to build in a fair bit of flexibility but maybe we'll need to tweak the tool to allow us even more.

Jonathan

Quoted 3 lines
Quoted 2 lines

I'll update those in that tree sometime this week.

#16 lore raw
Quoted 22 lines · On Sun, 31 Oct 2021 20:56:18 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 11 lines · On Sun, 31 Oct 2021 22:21:44 +0200 Andy Shevchenko <[email protected]>…
Quoted 4 lines · Jonathan Cameron
Quoted 2 lines · On Sun, 31 Oct 2021 17:08:54 +0000 Jonathan Cameron <[email protected]> wrote:

On Sun, 3 Oct 2021 16:32:55 +0100
Jonathan Cameron <[email protected]> wrote:

...

Quoted 3 lines
Quoted 3 lines

Given ongoing churn in core kernel includes as Andy cleans them up, I've pushed this particular work out on a branch at

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/log/?h=iio-iwyu-cleanups

This will get me 0-day exposure and allow me to keep moving these forwards as the core kernel headers change.

Thanks! I'm in favour of the work. Here are few things though:
- blank line in between of the groups of headers (like before iio/*)

Quoted 6 lines

Ok. I was trying to leave style in keeping with what was there in drivers, but fair enough can standardise on that.

Quoted 1 line

- fixing properly bitops.h and other typos (hope lkp will tell you about)

Huh. I'll watch out for that as getting clean builds...

Or not ;) Seems I did the normal stupid thing of adding just one more tweak and forgot to build before pushing out.

Indeed, the build bot did it's job perfectly!

Jonathan

Quoted 69 lines
Quoted 2 lines

- thinking more about the list of very-low-level includes (see below)

Agreed. I'm not sure on some of these - one of the big reasons this is a work in progress.

Quoted 5 lines

On top of that, the main idea behind header usage is to make sure we have no circular and other hell dependencies in the *headers*, C-files can go with more relaxed rules (but again, I'm in favour of the series and effort).

Agreed, but added advantage of this tooling is identifying the entirely pointless includes - of which there are lots. Getting rid of those was my main motivation in this.

Getting the balance right is going to be the trick and I'd rather a tool that told us (more or less) that we have things correct than rely on 'common practice'.

Quoted 28 lines
Quoted 28 lines
Quoted 27 lines

I would like to start merging 'some' of these in the meantime and there are some precursor cleanup patches that I'll pull out separately.

Perhaps most 'useful' is the top patch in that branch which is the iwyu mapping file I've put together to get it to make more reasonable suggestions. Note that there are some cases where the answer isn't obvious and some where you can't push iwyu to do the right thing.

One example is struct regmap which is deliberately opaque. iwyu always wants a forwards definition of it in all files where pointers to it occur, but personally I think including linux/regmap.h is sufficient as that will always have the forwards definition needed.

Note this branch will rebase frequently and may well eat babies. In particularly I will be cherry picking Andy and anyone else's work to the top of it and making changes through the rest of the patches as that affects them.

I'm not particularly expecting feedback, but I do want to avoid duplicate work. I'm also likely to 'fixing' new code as it comes in based on this toolchain - I may main in reviews or just fix it whilst applying (and tell people obviously!)

Long term plan here is to bring consistency to includes with benefits of resilience and hopefully reducing just how much code is actually pulled in whilst compiling.

Quoted 6 lines
Quoted 3 lines

I forgot to mention that I've take a stricter view since doing this series so it needs an update even in the tree above. This mostly affects err.h, errno.h, stddef.h and types.h

I don't think we need to include stddef.h to every C file, it should be guaranteed via something like types.h or so.

There are places with stddef.h but not types.h required. I debated which way to go on that and hence ended up with both for now, but it's obviously easy to tweak.

It may be that long term we look to have a standard kernel iwyu mapping file. It's possible to build in a fair bit of flexibility but maybe we'll need to tweak the tool to allow us even more.

Jonathan

Quoted 3 lines
Quoted 2 lines

I'll update those in that tree sometime this week.

author maintainer
#17 lore raw

...

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

Long term plan here is to bring consistency to includes with benefits of resilience and hopefully reducing just how much code is actually pulled in whilst compiling.

I forgot to mention that I've take a stricter view since doing this series so it needs an update even in the tree above. This mostly affects err.h, errno.h, stddef.h and types.h

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

I don't think we need to include stddef.h to every C file, it should be guaranteed via something like types.h or so.

There are places with stddef.h but not types.h required. I debated which way to go on that and hence ended up with both for now, but it's obviously easy to tweak.

Picking up on this particular example, I assumed it already would be included in something that was pretty much always present (such as types.h) but it isn't...

So maybe I misinterpreted your comment and you are suggesting it would make sense to include stddef.h in types.h?

Just looking at include/linux
we have about 49 instances of stddef.h being included, 91 of types.h but only 16 of both...

From the few I looked at I suspect main reason it's needed is for the definition of NULL though lots of other headers are getting that indirectly. Naturally this is one of the mega list in kernel.h but at least there is no chance of a loop.

I'm open to suggestions on how to proceed.

Jonathan

Quoted 13 lines
Quoted 12 lines

It may be that long term we look to have a standard kernel iwyu mapping file. It's possible to build in a fair bit of flexibility but maybe we'll need to tweak the tool to allow us even more.

Jonathan

Quoted 3 lines
Quoted 2 lines

I'll update those in that tree sometime this week.