Skip to contentSkip to conversation

gpio: Avoid kernel.h inclusion where it's possible

PATCH Superseded Andy Shevchenko 2 participants 3 messages Feb 4, 2020 – Feb 5, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: Avoid kernel.h inclusion where it's possible

Inclusion of kernel.h increases the mess with the header dependencies. Avoid kernel.h inclusion where it's possible.

Besides that, clean up a bit other inclusions inside GPIO subsystem headers.

---
 include/asm-generic/gpio.h    | 4 ++--
 include/linux/gpio.h          | 2 --
 include/linux/gpio/consumer.h | 5 ++++-
 include/linux/of_gpio.h       | 9 ++++++---
 4 files changed, 12 insertions(+), 8 deletions(-)
include/asm-generic/gpio.h +2 -2
index 19eadac415c4..aea9aee1f3e9 100644
@@ -2,10 +2,8 @@
 #ifndef _ASM_GENERIC_GPIO_H
 #define _ASM_GENERIC_GPIO_H
 
-#include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/errno.h>
-#include <linux/of.h>
 
 #ifdef CONFIG_GPIOLIB
 
@@ -140,6 +138,8 @@ static inline void gpio_unexport(unsigned gpio)
 
 #else	/* !CONFIG_GPIOLIB */
 
+#include <linux/kernel.h>
+
 static inline bool gpio_is_valid(int number)
 {
 	/* only non-negative numbers are valid */
include/linux/gpio.h +0 -2
index 2157717c2136..008ad3ee56b7 100644
@@ -102,11 +102,9 @@ void devm_gpio_free(struct device *dev, unsigned int gpio);
 #include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/bug.h>
-#include <linux/pinctrl/pinctrl.h>
 
 struct device;
 struct gpio_chip;
-struct pinctrl_dev;
 
 static inline bool gpio_is_valid(int number)
 {
include/linux/gpio/consumer.h +4 -1
index bf2d017dd7b7..0a72fccf60ff 100644
@@ -2,9 +2,10 @@
 #ifndef __LINUX_GPIO_CONSUMER_H
 #define __LINUX_GPIO_CONSUMER_H
 
+#include <linux/bits.h>
 #include <linux/bug.h>
+#include <linux/compiler_types.h>
 #include <linux/err.h>
-#include <linux/kernel.h>
 
 struct device;
 
@@ -189,6 +190,8 @@ struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
 
 #else /* CONFIG_GPIOLIB */
 
+#include <linux/kernel.h>
+
 static inline int gpiod_count(struct device *dev, const char *con_id)
 {
 	return 0;
include/linux/of_gpio.h +6 -3
index 16967390a3fe..f821095218b0 100644
@@ -11,9 +11,8 @@
 #define __LINUX_OF_GPIO_H
 
 #include <linux/compiler.h>
-#include <linux/kernel.h>
-#include <linux/errno.h>
-#include <linux/gpio.h>
+#include <linux/gpio/driver.h>
+#include <linux/gpio.h>		/* FIXME: Shouldn't be here */
 #include <linux/of.h>
 
 struct device_node;
@@ -34,6 +33,8 @@ enum of_gpio_flags {
 
 #ifdef CONFIG_OF_GPIO
 
+#include <linux/kernel.h>
+
 /*
  * OF GPIO chip for memory mapped banks
  */
@@ -63,6 +64,8 @@ extern void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc);
 
 #else /* CONFIG_OF_GPIO */
 
+#include <linux/errno.h>
+
 /* Drivers may not strictly depend on the GPIO support, so let them link. */
 static inline int of_get_named_gpio_flags(struct device_node *np,
 		const char *list_name, int index, enum of_gpio_flags *flags)
Signature · 1 line
2.24.1
#1 lore raw

wt., 4 lut 2020 o 20:07 Andy Shevchenko
<[email protected]> napisał(a):

Quoted 43 lines

Inclusion of kernel.h increases the mess with the header dependencies. Avoid kernel.h inclusion where it's possible.

Besides that, clean up a bit other inclusions inside GPIO subsystem headers.

---
 include/asm-generic/gpio.h    | 4 ++--
 include/linux/gpio.h          | 2 --
 include/linux/gpio/consumer.h | 5 ++++-
 include/linux/of_gpio.h       | 9 ++++++---
 4 files changed, 12 insertions(+), 8 deletions(-)
include/asm-generic/gpio.h +2 -2
index 19eadac415c4..aea9aee1f3e9 100644
@@ -2,10 +2,8 @@
 #ifndef _ASM_GENERIC_GPIO_H
 #define _ASM_GENERIC_GPIO_H
 
-#include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/errno.h>
-#include <linux/of.h>
 
 #ifdef CONFIG_GPIOLIB
 
@@ -140,6 +138,8 @@ static inline void gpio_unexport(unsigned gpio)
 
 #else  /* !CONFIG_GPIOLIB */
 
+#include <linux/kernel.h>
+
 static inline bool gpio_is_valid(int number)
 {
        /* only non-negative numbers are valid */
include/linux/gpio.h +0 -0
index 2157717c2136..008ad3ee56b7 100644

include/linux/gpio.h void devm_gpio_free(struct device *dev, unsigned int gpio); · line 109

Quoted 8 lines
include/linux/gpio.h +0 -2
@@ -102,11 +102,9 @@ void devm_gpio_free(struct device *dev, unsigned int gpio);
 #include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/bug.h>
-#include <linux/pinctrl/pinctrl.h>
 
 struct device;
 struct gpio_chip;
-struct pinctrl_dev;

If this forward declaration is removed because it's no longer needed after removing the pinctrl include, then please mention it in the commit message. If it's unrelated then please put it in a different patch.

Bartosz

Quoted 65 lines
include/linux/gpio.h +0 -0
 static inline bool gpio_is_valid(int number)
 {
include/linux/gpio/consumer.h +4 -1
index bf2d017dd7b7..0a72fccf60ff 100644
@@ -2,9 +2,10 @@
 #ifndef __LINUX_GPIO_CONSUMER_H
 #define __LINUX_GPIO_CONSUMER_H
 
+#include <linux/bits.h>
 #include <linux/bug.h>
+#include <linux/compiler_types.h>
 #include <linux/err.h>
-#include <linux/kernel.h>
 
 struct device;
 
@@ -189,6 +190,8 @@ struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
 
 #else /* CONFIG_GPIOLIB */
 
+#include <linux/kernel.h>
+
 static inline int gpiod_count(struct device *dev, const char *con_id)
 {
        return 0;
include/linux/of_gpio.h +6 -4
index 16967390a3fe..f821095218b0 100644
@@ -11,9 +11,8 @@
 #define __LINUX_OF_GPIO_H
 
 #include <linux/compiler.h>
-#include <linux/kernel.h>
-#include <linux/errno.h>
-#include <linux/gpio.h>
+#include <linux/gpio/driver.h>
+#include <linux/gpio.h>                /* FIXME: Shouldn't be here */
 #include <linux/of.h>
 
 struct device_node;
@@ -34,6 +33,8 @@ enum of_gpio_flags {
 
 #ifdef CONFIG_OF_GPIO
 
+#include <linux/kernel.h>
+
 /*
  * OF GPIO chip for memory mapped banks
  */
@@ -63,6 +64,8 @@ extern void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc);
 
 #else /* CONFIG_OF_GPIO */
 
+#include <linux/errno.h>
+
 /* Drivers may not strictly depend on the GPIO support, so let them link. */
 static inline int of_get_named_gpio_flags(struct device_node *np,
                const char *list_name, int index, enum of_gpio_flags *flags)
--

2.24.1

#2 lore raw
Quoted 6 lines · Bartosz Golaszewski

wt., 4 lut 2020 o 20:07 Andy Shevchenko
<[email protected]> napisał(a):

Quoted 4 lines

Inclusion of kernel.h increases the mess with the header dependencies. Avoid kernel.h inclusion where it's possible.

Quoted 8 lines
Quoted 3 lines

Besides that, clean up a bit other inclusions inside GPIO subsystem headers.

-struct pinctrl_dev;

If this forward declaration is removed because it's no longer needed after removing the pinctrl include, then please mention it in the commit message. If it's unrelated then please put it in a different patch.

Will do, thanks for review!

Signature · 2 lines
With Best Regards,
Andy Shevchenko