diff mbox series

[40/59] drm/arcpgu: Stop using drm_device->dev_private

Message ID 20200415074034.175360-41-daniel.vetter@ffwll.ch (mailing list archive)
State New, archived
Headers show
Series devm_drm_dev_alloc, v2 | expand

Commit Message

Daniel Vetter April 15, 2020, 7:40 a.m. UTC
Upcasting using a container_of macro is more typesafe, faster and
easier for the compiler to optimize.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Alexey Brodkin <abrodkin@synopsys.com>
---
 drivers/gpu/drm/arc/arcpgu.h      | 2 ++
 drivers/gpu/drm/arc/arcpgu_crtc.c | 4 ++--
 drivers/gpu/drm/arc/arcpgu_drv.c  | 4 +---
 3 files changed, 5 insertions(+), 5 deletions(-)

Comments

Sam Ravnborg April 24, 2020, 4:46 p.m. UTC | #1
Hi Daniel.

On Wed, Apr 15, 2020 at 09:40:15AM +0200, Daniel Vetter wrote:
> Upcasting using a container_of macro is more typesafe, faster and
> easier for the compiler to optimize.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Cc: Alexey Brodkin <abrodkin@synopsys.com>

Subject: drm/arc: arcpgu: Stop using drm_device->dev_private

And another bikeshedding below.
With this considered:
Acked-by: Sam Ravnborg <sam@ravnborg.org>

> ---
>  drivers/gpu/drm/arc/arcpgu.h      | 2 ++
>  drivers/gpu/drm/arc/arcpgu_crtc.c | 4 ++--
>  drivers/gpu/drm/arc/arcpgu_drv.c  | 4 +---
>  3 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpu/drm/arc/arcpgu.h b/drivers/gpu/drm/arc/arcpgu.h
> index cd9e932f501e..87821c91a00c 100644
> --- a/drivers/gpu/drm/arc/arcpgu.h
> +++ b/drivers/gpu/drm/arc/arcpgu.h
> @@ -17,6 +17,8 @@ struct arcpgu_drm_private {
>  	struct drm_plane	*plane;
>  };
>  
> +#define dev_to_arcpgu(x) container_of(x, struct arcpgu_drm_private, drm)
> +
Preferred name is to_arcgpu(). There is no device in the name of struct
arcpgu_drm_private. And the general consensus it to use to_<driver> for
the top-level struct.

>  #define crtc_to_arcpgu_priv(x) container_of(x, struct arcpgu_drm_private, crtc)
>  
>  static inline void arc_pgu_write(struct arcpgu_drm_private *arcpgu,
> diff --git a/drivers/gpu/drm/arc/arcpgu_crtc.c b/drivers/gpu/drm/arc/arcpgu_crtc.c
> index be7c29cec318..ba796a216244 100644
> --- a/drivers/gpu/drm/arc/arcpgu_crtc.c
> +++ b/drivers/gpu/drm/arc/arcpgu_crtc.c
> @@ -178,7 +178,7 @@ static const struct drm_plane_funcs arc_pgu_plane_funcs = {
>  
>  static struct drm_plane *arc_pgu_plane_init(struct drm_device *drm)
>  {
> -	struct arcpgu_drm_private *arcpgu = drm->dev_private;
> +	struct arcpgu_drm_private *arcpgu = dev_to_arcpgu(drm);
>  	struct drm_plane *plane = NULL;
>  	int ret;
>  
> @@ -202,7 +202,7 @@ static struct drm_plane *arc_pgu_plane_init(struct drm_device *drm)
>  
>  int arc_pgu_setup_crtc(struct drm_device *drm)
>  {
> -	struct arcpgu_drm_private *arcpgu = drm->dev_private;
> +	struct arcpgu_drm_private *arcpgu = dev_to_arcpgu(drm);
>  	struct drm_plane *primary;
>  	int ret;
>  
> diff --git a/drivers/gpu/drm/arc/arcpgu_drv.c b/drivers/gpu/drm/arc/arcpgu_drv.c
> index bbd7acb150f3..81b8d7ae6623 100644
> --- a/drivers/gpu/drm/arc/arcpgu_drv.c
> +++ b/drivers/gpu/drm/arc/arcpgu_drv.c
> @@ -50,8 +50,6 @@ static int arcpgu_load(struct arcpgu_drm_private *arcpgu)
>  	struct resource *res;
>  	int ret;
>  
> -	drm->dev_private = arcpgu;
> -
>  	arcpgu->clk = devm_clk_get(drm->dev, "pxlclk");
>  	if (IS_ERR(arcpgu->clk))
>  		return PTR_ERR(arcpgu->clk);
> @@ -120,7 +118,7 @@ static int arcpgu_show_pxlclock(struct seq_file *m, void *arg)
>  {
>  	struct drm_info_node *node = (struct drm_info_node *)m->private;
>  	struct drm_device *drm = node->minor->dev;
> -	struct arcpgu_drm_private *arcpgu = drm->dev_private;
> +	struct arcpgu_drm_private *arcpgu = dev_to_arcpgu(drm);
>  	unsigned long clkrate = clk_get_rate(arcpgu->clk);
>  	unsigned long mode_clock = arcpgu->crtc.mode.crtc_clock * 1000;
>  
> -- 
> 2.25.1
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
Daniel Vetter Sept. 4, 2020, 1:42 p.m. UTC | #2
On Fri, Apr 24, 2020 at 6:46 PM Sam Ravnborg <sam@ravnborg.org> wrote:
>
> Hi Daniel.
>
> On Wed, Apr 15, 2020 at 09:40:15AM +0200, Daniel Vetter wrote:
> > Upcasting using a container_of macro is more typesafe, faster and
> > easier for the compiler to optimize.
> >
> > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > Cc: Alexey Brodkin <abrodkin@synopsys.com>
>
> Subject: drm/arc: arcpgu: Stop using drm_device->dev_private
>
> And another bikeshedding below.
> With this considered:
> Acked-by: Sam Ravnborg <sam@ravnborg.org>
>
> > ---
> >  drivers/gpu/drm/arc/arcpgu.h      | 2 ++
> >  drivers/gpu/drm/arc/arcpgu_crtc.c | 4 ++--
> >  drivers/gpu/drm/arc/arcpgu_drv.c  | 4 +---
> >  3 files changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/arc/arcpgu.h b/drivers/gpu/drm/arc/arcpgu.h
> > index cd9e932f501e..87821c91a00c 100644
> > --- a/drivers/gpu/drm/arc/arcpgu.h
> > +++ b/drivers/gpu/drm/arc/arcpgu.h
> > @@ -17,6 +17,8 @@ struct arcpgu_drm_private {
> >       struct drm_plane        *plane;
> >  };
> >
> > +#define dev_to_arcpgu(x) container_of(x, struct arcpgu_drm_private, drm)
> > +
> Preferred name is to_arcgpu(). There is no device in the name of struct
> arcpgu_drm_private. And the general consensus it to use to_<driver> for
> the top-level struct.

[Sorry just realized I never replied on-list for this here]

drm_device very much has a dev_  and there's some other drivders with
this pattern too. Plus I think it's more consistent with the other
macros in here. For simple drivers where there's only 1 structure I
agree though, so if you insist I can follow up with a patch. Fixing
this in-series is imo too much trouble for the benefit, every single
patch would need to be redone ...

Cheers, Daniel

>
> >  #define crtc_to_arcpgu_priv(x) container_of(x, struct arcpgu_drm_private, crtc)
> >
> >  static inline void arc_pgu_write(struct arcpgu_drm_private *arcpgu,
> > diff --git a/drivers/gpu/drm/arc/arcpgu_crtc.c b/drivers/gpu/drm/arc/arcpgu_crtc.c
> > index be7c29cec318..ba796a216244 100644
> > --- a/drivers/gpu/drm/arc/arcpgu_crtc.c
> > +++ b/drivers/gpu/drm/arc/arcpgu_crtc.c
> > @@ -178,7 +178,7 @@ static const struct drm_plane_funcs arc_pgu_plane_funcs = {
> >
> >  static struct drm_plane *arc_pgu_plane_init(struct drm_device *drm)
> >  {
> > -     struct arcpgu_drm_private *arcpgu = drm->dev_private;
> > +     struct arcpgu_drm_private *arcpgu = dev_to_arcpgu(drm);
> >       struct drm_plane *plane = NULL;
> >       int ret;
> >
> > @@ -202,7 +202,7 @@ static struct drm_plane *arc_pgu_plane_init(struct drm_device *drm)
> >
> >  int arc_pgu_setup_crtc(struct drm_device *drm)
> >  {
> > -     struct arcpgu_drm_private *arcpgu = drm->dev_private;
> > +     struct arcpgu_drm_private *arcpgu = dev_to_arcpgu(drm);
> >       struct drm_plane *primary;
> >       int ret;
> >
> > diff --git a/drivers/gpu/drm/arc/arcpgu_drv.c b/drivers/gpu/drm/arc/arcpgu_drv.c
> > index bbd7acb150f3..81b8d7ae6623 100644
> > --- a/drivers/gpu/drm/arc/arcpgu_drv.c
> > +++ b/drivers/gpu/drm/arc/arcpgu_drv.c
> > @@ -50,8 +50,6 @@ static int arcpgu_load(struct arcpgu_drm_private *arcpgu)
> >       struct resource *res;
> >       int ret;
> >
> > -     drm->dev_private = arcpgu;
> > -
> >       arcpgu->clk = devm_clk_get(drm->dev, "pxlclk");
> >       if (IS_ERR(arcpgu->clk))
> >               return PTR_ERR(arcpgu->clk);
> > @@ -120,7 +118,7 @@ static int arcpgu_show_pxlclock(struct seq_file *m, void *arg)
> >  {
> >       struct drm_info_node *node = (struct drm_info_node *)m->private;
> >       struct drm_device *drm = node->minor->dev;
> > -     struct arcpgu_drm_private *arcpgu = drm->dev_private;
> > +     struct arcpgu_drm_private *arcpgu = dev_to_arcpgu(drm);
> >       unsigned long clkrate = clk_get_rate(arcpgu->clk);
> >       unsigned long mode_clock = arcpgu->crtc.mode.crtc_clock * 1000;
> >
> > --
> > 2.25.1
> >
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel
Sam Ravnborg Sept. 4, 2020, 2:42 p.m. UTC | #3
Hi Daniel.

On Fri, Sep 04, 2020 at 03:42:44PM +0200, Daniel Vetter wrote:
> On Fri, Apr 24, 2020 at 6:46 PM Sam Ravnborg <sam@ravnborg.org> wrote:
> >
> > Hi Daniel.
> >
> > On Wed, Apr 15, 2020 at 09:40:15AM +0200, Daniel Vetter wrote:
> > > Upcasting using a container_of macro is more typesafe, faster and
> > > easier for the compiler to optimize.
> > >
> > > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > > Cc: Alexey Brodkin <abrodkin@synopsys.com>
> >
> > Subject: drm/arc: arcpgu: Stop using drm_device->dev_private
> >
> > And another bikeshedding below.
> > With this considered:
> > Acked-by: Sam Ravnborg <sam@ravnborg.org>
> >
> > > ---
> > >  drivers/gpu/drm/arc/arcpgu.h      | 2 ++
> > >  drivers/gpu/drm/arc/arcpgu_crtc.c | 4 ++--
> > >  drivers/gpu/drm/arc/arcpgu_drv.c  | 4 +---
> > >  3 files changed, 5 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/arc/arcpgu.h b/drivers/gpu/drm/arc/arcpgu.h
> > > index cd9e932f501e..87821c91a00c 100644
> > > --- a/drivers/gpu/drm/arc/arcpgu.h
> > > +++ b/drivers/gpu/drm/arc/arcpgu.h
> > > @@ -17,6 +17,8 @@ struct arcpgu_drm_private {
> > >       struct drm_plane        *plane;
> > >  };
> > >
> > > +#define dev_to_arcpgu(x) container_of(x, struct arcpgu_drm_private, drm)
> > > +
> > Preferred name is to_arcgpu(). There is no device in the name of struct
> > arcpgu_drm_private. And the general consensus it to use to_<driver> for
> > the top-level struct.
> 
> [Sorry just realized I never replied on-list for this here]
> 
> drm_device very much has a dev_  and there's some other drivders with
> this pattern too. Plus I think it's more consistent with the other
> macros in here. For simple drivers where there's only 1 structure I
> agree though, so if you insist I can follow up with a patch. Fixing
> this in-series is imo too much trouble for the benefit, every single
> patch would need to be redone ...

The naming is my personal choice - others have different opinions.
And since we did not universially agree on dev_to_* versus to_* for the
main driver structure there is no need to adjust.

For me it is just that the main driver structure is more than a device
thingy and I like the short naming. But it seems you, Thomas + more
prefer dev_to_* so maybe I should adjust so we are a little more
aligned.

So it is considered so the patch is obviously:
Acked-by: Sam Ravnborg <sam@ravnborg.org>

	Sam
diff mbox series

Patch

diff --git a/drivers/gpu/drm/arc/arcpgu.h b/drivers/gpu/drm/arc/arcpgu.h
index cd9e932f501e..87821c91a00c 100644
--- a/drivers/gpu/drm/arc/arcpgu.h
+++ b/drivers/gpu/drm/arc/arcpgu.h
@@ -17,6 +17,8 @@  struct arcpgu_drm_private {
 	struct drm_plane	*plane;
 };
 
+#define dev_to_arcpgu(x) container_of(x, struct arcpgu_drm_private, drm)
+
 #define crtc_to_arcpgu_priv(x) container_of(x, struct arcpgu_drm_private, crtc)
 
 static inline void arc_pgu_write(struct arcpgu_drm_private *arcpgu,
diff --git a/drivers/gpu/drm/arc/arcpgu_crtc.c b/drivers/gpu/drm/arc/arcpgu_crtc.c
index be7c29cec318..ba796a216244 100644
--- a/drivers/gpu/drm/arc/arcpgu_crtc.c
+++ b/drivers/gpu/drm/arc/arcpgu_crtc.c
@@ -178,7 +178,7 @@  static const struct drm_plane_funcs arc_pgu_plane_funcs = {
 
 static struct drm_plane *arc_pgu_plane_init(struct drm_device *drm)
 {
-	struct arcpgu_drm_private *arcpgu = drm->dev_private;
+	struct arcpgu_drm_private *arcpgu = dev_to_arcpgu(drm);
 	struct drm_plane *plane = NULL;
 	int ret;
 
@@ -202,7 +202,7 @@  static struct drm_plane *arc_pgu_plane_init(struct drm_device *drm)
 
 int arc_pgu_setup_crtc(struct drm_device *drm)
 {
-	struct arcpgu_drm_private *arcpgu = drm->dev_private;
+	struct arcpgu_drm_private *arcpgu = dev_to_arcpgu(drm);
 	struct drm_plane *primary;
 	int ret;
 
diff --git a/drivers/gpu/drm/arc/arcpgu_drv.c b/drivers/gpu/drm/arc/arcpgu_drv.c
index bbd7acb150f3..81b8d7ae6623 100644
--- a/drivers/gpu/drm/arc/arcpgu_drv.c
+++ b/drivers/gpu/drm/arc/arcpgu_drv.c
@@ -50,8 +50,6 @@  static int arcpgu_load(struct arcpgu_drm_private *arcpgu)
 	struct resource *res;
 	int ret;
 
-	drm->dev_private = arcpgu;
-
 	arcpgu->clk = devm_clk_get(drm->dev, "pxlclk");
 	if (IS_ERR(arcpgu->clk))
 		return PTR_ERR(arcpgu->clk);
@@ -120,7 +118,7 @@  static int arcpgu_show_pxlclock(struct seq_file *m, void *arg)
 {
 	struct drm_info_node *node = (struct drm_info_node *)m->private;
 	struct drm_device *drm = node->minor->dev;
-	struct arcpgu_drm_private *arcpgu = drm->dev_private;
+	struct arcpgu_drm_private *arcpgu = dev_to_arcpgu(drm);
 	unsigned long clkrate = clk_get_rate(arcpgu->clk);
 	unsigned long mode_clock = arcpgu->crtc.mode.crtc_clock * 1000;