Skip to contentSkip to conversation

staging:iio: Header cleanup

PATCH In review Jonathan Cameron 2 participants 13 messages Jun 11, 2021

Subsystems (4)
lore
Share & tools
lore

Jonathan Cameron

author maintainer
#0 lore raw

cover staging:iio: Header cleanup

From: Jonathan Cameron <[email protected]>

0-day recently started giving some reports from the include-what-you-use tool (needs LLVM builds).

I was curious so decided to give it a spin. It produces a wealth of information, but the suggestions require a high degree of interpretation and some choices are down to personal taste.

This set covers resulting changes that I think make sense for remaining IIO drivers in staging (which I just noticed are all Analog devices ones :)

Jonathan Cameron (7):
staging:iio:adc: Cleanup includes staging:iio:addac:adt7316: Cleanup includes staging:iio:cdc:ad7746: Cleanup includes staging:iio:frequency: Cleanup includes staging:iio:impedance-analyzer: Cleanup includes staging:iio:meter:ade7854: Cleanup includes staging:iio:resolver:ad2s1210: Cleanup includes

 drivers/staging/iio/adc/ad7280a.c               | 2 ++
 drivers/staging/iio/adc/ad7816.c                | 3 +--
 drivers/staging/iio/addac/adt7316.c             | 5 -----
 drivers/staging/iio/addac/adt7316.h             | 1 +
 drivers/staging/iio/cdc/ad7746.c                | 6 +++---
 drivers/staging/iio/frequency/ad9832.c          | 3 ++-
 drivers/staging/iio/frequency/ad9834.c          | 6 ++----
 drivers/staging/iio/impedance-analyzer/ad5933.c | 5 ++++-
 drivers/staging/iio/meter/ade7854-i2c.c         | 3 ++-
 drivers/staging/iio/meter/ade7854-spi.c         | 3 ++-
 drivers/staging/iio/meter/ade7854.c             | 4 ----
 drivers/staging/iio/meter/ade7854.h             | 5 +++++
 drivers/staging/iio/resolver/ad2s1210.c         | 5 +++--
 13 files changed, 27 insertions(+), 24 deletions(-)
Signature · 1 line
2.31.1
author maintainer
#1 lore raw

PATCH 1/7 staging:iio:adc: Cleanup includes

From: Jonathan Cameron <[email protected]>

Result of considering the output of the include-what-you-use tool. Note that this is partly a case of taste and consistency.

---
 drivers/staging/iio/adc/ad7280a.c | 2 ++
 drivers/staging/iio/adc/ad7816.c  | 3 +--
 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/staging/iio/adc/ad7280a.c +2 -0
index fef0055b8990..135fdf33c655 100644
@@ -15,6 +15,8 @@
 #include <linux/delay.h>
 #include <linux/interrupt.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/mutex.h>
 
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
drivers/staging/iio/adc/ad7816.c +1 -2
index 6c14d7bcdd67..0d943f99383b 100644
@@ -9,11 +9,10 @@
 #include <linux/gpio/consumer.h>
 #include <linux/device.h>
 #include <linux/kernel.h>
-#include <linux/slab.h>
 #include <linux/sysfs.h>
-#include <linux/list.h>
 #include <linux/spi/spi.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
 
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
Signature · 1 line
2.31.1
author maintainer
#2 lore raw

PATCH 2/7 staging:iio:addac:adt7316: Cleanup includes

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Result of consideration of the output of the include-what-you-use tool. Also a forwards definition of device to avoid any ordering of headers issues.

---
 drivers/staging/iio/addac/adt7316.c | 5 -----
 drivers/staging/iio/addac/adt7316.h | 1 +
 2 files changed, 1 insertion(+), 5 deletions(-)
drivers/staging/iio/addac/adt7316.c +0 -5
index ccbafcaaf27e..e81791ee182f 100644
@@ -8,14 +8,9 @@
 #include <linux/interrupt.h>
 #include <linux/gpio/consumer.h>
 #include <linux/irq.h>
-#include <linux/workqueue.h>
 #include <linux/device.h>
 #include <linux/kernel.h>
-#include <linux/slab.h>
 #include <linux/sysfs.h>
-#include <linux/list.h>
-#include <linux/i2c.h>
-#include <linux/rtc.h>
 #include <linux/module.h>
 
 #include <linux/iio/iio.h>
drivers/staging/iio/addac/adt7316.h +1 -0
index 8c2a92ae7157..a1f6324ead59 100644
@@ -10,6 +10,7 @@
 
 #include <linux/types.h>
 #include <linux/pm.h>
+struct device;
 
 #define ADT7316_REG_MAX_ADDR		0x3F
 
Signature · 1 line
2.31.1
#3 lore raw

Re: [PATCH 2/7] staging:iio:addac:adt7316: Cleanup includes

Quoted 37 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Result of consideration of the output of the include-what-you-use tool. Also a forwards definition of device to avoid any ordering of headers issues.

---
 drivers/staging/iio/addac/adt7316.c | 5 -----
 drivers/staging/iio/addac/adt7316.h | 1 +
 2 files changed, 1 insertion(+), 5 deletions(-)
drivers/staging/iio/addac/adt7316.c +0 -5
index ccbafcaaf27e..e81791ee182f 100644
@@ -8,14 +8,9 @@
 #include <linux/interrupt.h>
 #include <linux/gpio/consumer.h>
 #include <linux/irq.h>
-#include <linux/workqueue.h>
 #include <linux/device.h>
 #include <linux/kernel.h>
-#include <linux/slab.h>
 #include <linux/sysfs.h>
-#include <linux/list.h>
-#include <linux/i2c.h>
-#include <linux/rtc.h>
 #include <linux/module.h>
 
 #include <linux/iio/iio.h>
drivers/staging/iio/addac/adt7316.h +0 -0
index 8c2a92ae7157..a1f6324ead59 100644

drivers/staging/iio/addac/adt7316.h line 12

Quoted 3 lines
drivers/staging/iio/addac/adt7316.h +0 -0
@@ -10,6 +10,7 @@
 
 #include <linux/types.h>
 #include <linux/pm.h>

+ blank line?

Quoted 7 lines
drivers/staging/iio/addac/adt7316.h +1 -1
+struct device;
 
 #define ADT7316_REG_MAX_ADDR           0x3F
 
--

2.31.1

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#4 lore raw

PATCH 3/7 staging:iio:cdc:ad7746: Cleanup includes

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Based on consideration of the output of the include-what-you-use tool. Drop some unused includes + include some which probably should have been there in the first place.

---
 drivers/staging/iio/cdc/ad7746.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/iio/cdc/ad7746.c +3 -3
index 4221312f0a32..fbdf90604c0d 100644
@@ -8,11 +8,11 @@
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/i2c.h>
-#include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/slab.h>
-#include <linux/stat.h>
+#include <linux/mod_devicetable.h>
+#include <linux/mutex.h>
+#include <linux/property.h>
 #include <linux/sysfs.h>
 
 #include <linux/iio/iio.h>
Signature · 1 line
2.31.1
author maintainer
#5 lore raw

PATCH 4/7 staging:iio:frequency: Cleanup includes

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Based on consideration of the output of the include-what-you-use tool. Remove some unused headers and add some that should be directly included.

---
 drivers/staging/iio/frequency/ad9832.c | 3 ++-
 drivers/staging/iio/frequency/ad9834.c | 6 ++----
 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/staging/iio/frequency/ad9832.c +2 -1
index 3f1981e287f5..2d78072ff4c3 100644
@@ -12,8 +12,9 @@
 #include <linux/err.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/mutex.h>
 #include <linux/regulator/consumer.h>
-#include <linux/slab.h>
 #include <linux/spi/spi.h>
 #include <linux/sysfs.h>
 
drivers/staging/iio/frequency/ad9834.c +2 -4
index 94b131ef8a22..c163e91c1bc4 100644
@@ -6,17 +6,15 @@
  */
 
 #include <linux/clk.h>
-#include <linux/interrupt.h>
-#include <linux/workqueue.h>
 #include <linux/device.h>
 #include <linux/kernel.h>
-#include <linux/slab.h>
 #include <linux/sysfs.h>
-#include <linux/list.h>
 #include <linux/spi/spi.h>
 #include <linux/regulator/consumer.h>
 #include <linux/err.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/mutex.h>
 #include <asm/div64.h>
 
 #include <linux/iio/iio.h>
Signature · 1 line
2.31.1
author maintainer
#6 lore raw

PATCH 5/7 staging:iio:impedance-analyzer: Cleanup includes

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Based on consideration of the output of the include-what-you-use tool. Drop unused headers and include some that should probably have always been included.

---
 drivers/staging/iio/impedance-analyzer/ad5933.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/staging/iio/impedance-analyzer/ad5933.c +4 -1
index 793918e1c45f..33dc8b7eb37a 100644
@@ -5,17 +5,20 @@
  * Copyright 2011 Analog Devices Inc.
  */
 
+#include <linux/bitmap.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/err.h>
 #include <linux/i2c.h>
-#include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/mutex.h>
 #include <linux/regulator/consumer.h>
 #include <linux/sysfs.h>
 #include <linux/types.h>
+#include <linux/workqueue.h>
 
 #include <linux/iio/buffer.h>
 #include <linux/iio/iio.h>
Signature · 1 line
2.31.1
author maintainer
#7 lore raw

PATCH 6/7 staging:iio:meter:ade7854: Cleanup includes

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Based on consideration of the output of the include-what-you-use tool. Drop some unused headers and some that should probably have always been included. Also a few forwards definitions to avoid any future issues with header ordering.

---
 drivers/staging/iio/meter/ade7854-i2c.c | 3 ++-
 drivers/staging/iio/meter/ade7854-spi.c | 3 ++-
 drivers/staging/iio/meter/ade7854.c     | 4 ----
 drivers/staging/iio/meter/ade7854.h     | 5 +++++
 4 files changed, 9 insertions(+), 6 deletions(-)
drivers/staging/iio/meter/ade7854-i2c.c +2 -1
index a9a06e8dda51..c6b3e1418c84 100644
@@ -8,8 +8,9 @@
 #include <linux/device.h>
 #include <linux/kernel.h>
 #include <linux/i2c.h>
-#include <linux/slab.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/mutex.h>
 
 #include <linux/iio/iio.h>
 #include "ade7854.h"
drivers/staging/iio/meter/ade7854-spi.c +2 -1
index f12a6c8b3e88..7ba7dc4cdbc9 100644
@@ -8,8 +8,9 @@
 #include <linux/device.h>
 #include <linux/kernel.h>
 #include <linux/spi/spi.h>
-#include <linux/slab.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/mutex.h>
 
 #include <linux/iio/iio.h>
 #include "ade7854.h"
drivers/staging/iio/meter/ade7854.c +0 -4
index 68da6ecde6a3..68a5e9c6b047 100644
@@ -5,15 +5,11 @@
  * Copyright 2010 Analog Devices Inc.
  */
 
-#include <linux/interrupt.h>
-#include <linux/irq.h>
 #include <linux/delay.h>
 #include <linux/mutex.h>
 #include <linux/device.h>
 #include <linux/kernel.h>
-#include <linux/slab.h>
 #include <linux/sysfs.h>
-#include <linux/list.h>
 #include <linux/module.h>
 
 #include <linux/iio/iio.h>
drivers/staging/iio/meter/ade7854.h +5 -0
index a51e6e3183d3..620d3d075f95 100644
@@ -1,4 +1,9 @@
 /* SPDX-License-Identifier: GPL-2.0 */
+
+#include <linux/mutex.h>
+struct device;
+struct iio_device;
+
 #ifndef _ADE7854_H
 #define _ADE7854_H
 
Signature · 1 line
2.31.1
author maintainer
#8 lore raw

PATCH 7/7 staging:iio:resolver:ad2s1210: Cleanup includes

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Based on consideration of the output of the include-what-you-use tool. Drop unused includes and add some that should be there.

---
 drivers/staging/iio/resolver/ad2s1210.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/iio/resolver/ad2s1210.c +3 -2
index 74adb82f37c3..99dec73144ba 100644
@@ -4,15 +4,16 @@
  *
  * Copyright (c) 2010-2010 Analog Devices Inc.
  */
+#include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/mutex.h>
 #include <linux/device.h>
 #include <linux/spi/spi.h>
-#include <linux/slab.h>
 #include <linux/sysfs.h>
-#include <linux/delay.h>
 #include <linux/gpio/consumer.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/of.h>
 
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
Signature · 1 line
2.31.1
author maintainer
#9 lore raw

Re: [PATCH 7/7] staging:iio:resolver:ad2s1210: Cleanup includes

Quoted 16 lines · On Fri, 11 Jun 2021 16:26:14 +0100 Jonathan Cameron <[email protected]> wrote:

From: Jonathan Cameron <[email protected]>

Based on consideration of the output of the include-what-you-use tool. Drop unused includes and add some that should be there.

---
 drivers/staging/iio/resolver/ad2s1210.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/iio/resolver/ad2s1210.c +0 -0
index 74adb82f37c3..99dec73144ba 100644
@@ -4,15 +4,16 @@
  *

drivers/staging/iio/resolver/ad2s1210.c line 13

Quoted 10 lines
drivers/staging/iio/resolver/ad2s1210.c +1 -2
  * Copyright (c) 2010-2010 Analog Devices Inc.
  */
+#include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/mutex.h>
 #include <linux/device.h>
 #include <linux/spi/spi.h>
-#include <linux/slab.h>
 #include <linux/sysfs.h>
-#include <linux/delay.h>

Let's pretend I didn't remove this one by accident as it is needed. I don't want to resend the whole set for that however so will leave it for now.

Quoted 7 lines
drivers/staging/iio/resolver/ad2s1210.c +2 -0
 #include <linux/gpio/consumer.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/of.h>
 
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
#10 lore raw
In reply to Jonathan Cameron
Quoted 6 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

0-day recently started giving some reports from the include-what-you-use tool (needs LLVM builds).

Quoted 6 lines

I was curious so decided to give it a spin. It produces a wealth of information, but the suggestions require a high degree of interpretation and some choices are down to personal taste.

This set covers resulting changes that I think make sense for remaining IIO drivers in staging (which I just noticed are all Analog devices ones :)

In general it's a good idea, but the tool doesn't know the project specifics. I believe that half of what you have done is simply wrong. That is, we have a lot of drivers that include kernel.h which is in its turn a rabbit hole of all possible headers and (circular) dependencies. So, for this and the other series, please double check that removed headers are not removed due to kernel.h (I believe this is the case for almost all if not all entries of slab.h, for example).

The other half seems correct. But due to the above I can't give any tag on these...

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#11 lore raw
Quoted 14 lines · On Fri, 11 Jun 2021 20:45:03 +0300 Andy Shevchenko <[email protected]>…
Quoted 6 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

0-day recently started giving some reports from the include-what-you-use tool (needs LLVM builds).

Quoted 6 lines

I was curious so decided to give it a spin. It produces a wealth of information, but the suggestions require a high degree of interpretation and some choices are down to personal taste.

This set covers resulting changes that I think make sense for remaining IIO drivers in staging (which I just noticed are all Analog devices ones :)

Quoted 7 lines

In general it's a good idea, but the tool doesn't know the project specifics. I believe that half of what you have done is simply wrong. That is, we have a lot of drivers that include kernel.h which is in its turn a rabbit hole of all possible headers and (circular) dependencies. So, for this and the other series, please double check that removed headers are not removed due to kernel.h (I believe this is the case for almost all if not all entries of slab.h, for example).

The tool seems to go rather the other way and suggest including things that are 'obviously' included via another header that we need.

The reason for kernel.h includes when being added is almost always ARRAY_SIZE or container_of as you identified.

The drivers where I'm removing slab.h don't actually make any direct allocate or free calls, they are all wrapped up in various IIO core function (devm_iio_device_alloc etc.)

Jonathan

Quoted 4 lines

The other half seems correct. But due to the above I can't give any tag on these...

#12 lore raw
Quoted 3 lines · Jonathan Cameron
Quoted 1 line · On Fri, 11 Jun 2021 20:45:03 +0300 Andy Shevchenko <[email protected]>…

On Fri, Jun 11, 2021 at 6:25 PM Jonathan Cameron <[email protected]> wrote:

...

Quoted 2 lines

The reason for kernel.h includes when being added is almost always ARRAY_SIZE or container_of as you identified.

Give me some time. I will cook a couple of patches for ya to test (splitting those from kernel.h).

Signature · 2 lines
With Best Regards,
Andy Shevchenko