diff mbox series

[v2,4/9] pwm: lpss: Include headers we are direct user of

Message ID 20220908135658.64463-5-andriy.shevchenko@linux.intel.com
State Changes Requested
Headers show
Series pwm: lpss: Clean up and convert to a pure library | expand

Commit Message

Andy Shevchenko Sept. 8, 2022, 1:56 p.m. UTC
For the sake of integrity, include headers we are direct user of.

While at it, replace device.h with a forward declaration and add
missed struct pwm_lpss_boardinfo one.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/pwm/pwm-lpss.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Uwe Kleine-König Sept. 24, 2022, 10:04 a.m. UTC | #1
On Thu, Sep 08, 2022 at 04:56:53PM +0300, Andy Shevchenko wrote:
> For the sake of integrity, include headers we are direct user of.
> 
> While at it, replace device.h with a forward declaration and add
> missed struct pwm_lpss_boardinfo one.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/pwm/pwm-lpss.h | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pwm/pwm-lpss.h b/drivers/pwm/pwm-lpss.h
> index c344921b2cab..839622964b2a 100644
> --- a/drivers/pwm/pwm-lpss.h
> +++ b/drivers/pwm/pwm-lpss.h
> @@ -10,11 +10,15 @@
>  #ifndef __PWM_LPSS_H
>  #define __PWM_LPSS_H
>  
> -#include <linux/device.h>
>  #include <linux/pwm.h>
> +#include <linux/types.h>
>  
>  #define MAX_PWMS			4
>  
> +struct device;

It's not clear to me how this is an improvment. Isn't it saner to
include <linux/device.h>?

> +struct pwm_lpss_boardinfo;

Why is this necessary? The struct is defined a few lines below the
context of this patch and I see no user that would benefit.

Best regards
Uwe
Andy Shevchenko Sept. 26, 2022, 9:48 a.m. UTC | #2
On Sat, Sep 24, 2022 at 12:04:53PM +0200, Uwe Kleine-König wrote:
> On Thu, Sep 08, 2022 at 04:56:53PM +0300, Andy Shevchenko wrote:
> > For the sake of integrity, include headers we are direct user of.
> > 
> > While at it, replace device.h with a forward declaration and add
> > missed struct pwm_lpss_boardinfo one.
> > 
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > ---
> >  drivers/pwm/pwm-lpss.h | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/pwm/pwm-lpss.h b/drivers/pwm/pwm-lpss.h
> > index c344921b2cab..839622964b2a 100644
> > --- a/drivers/pwm/pwm-lpss.h
> > +++ b/drivers/pwm/pwm-lpss.h
> > @@ -10,11 +10,15 @@
> >  #ifndef __PWM_LPSS_H
> >  #define __PWM_LPSS_H
> >  
> > -#include <linux/device.h>
> >  #include <linux/pwm.h>
> > +#include <linux/types.h>
> >  
> >  #define MAX_PWMS			4
> >  
> > +struct device;
> 
> It's not clear to me how this is an improvment. Isn't it saner to
> include <linux/device.h>?

The compilation time improvement. You don't need to include entire
train of unrelated stuff when compile something.

Moreover, the rule of thumb for the headers is avoid as much as possible
unrelated inclusions not only due to compilation time rising, but also
due to potential circular dependencies and increasing dependency hell
of headers. Believe me, we suffer a lot in the kernel due to this
(I have an example). Also you may check the Ingo's work of improving
headers breakage (APIs vs. implementation vs. data types, etc) to see
the achievement(s).

> > +struct pwm_lpss_boardinfo;
> 
> Why is this necessary? The struct is defined a few lines below the
> context of this patch and I see no user that would benefit.

This is clean way of how we program in C. We should forward declare
the types _before_ using them. Since this is a pointer, forward
declaration is enough.
diff mbox series

Patch

diff --git a/drivers/pwm/pwm-lpss.h b/drivers/pwm/pwm-lpss.h
index c344921b2cab..839622964b2a 100644
--- a/drivers/pwm/pwm-lpss.h
+++ b/drivers/pwm/pwm-lpss.h
@@ -10,11 +10,15 @@ 
 #ifndef __PWM_LPSS_H
 #define __PWM_LPSS_H
 
-#include <linux/device.h>
 #include <linux/pwm.h>
+#include <linux/types.h>
 
 #define MAX_PWMS			4
 
+struct device;
+
+struct pwm_lpss_boardinfo;
+
 struct pwm_lpss_chip {
 	struct pwm_chip chip;
 	void __iomem *regs;