[06/17] drm/i915: Move {pin, long}_mask initialization to caller from intel_get_hpd_pins()
diff mbox

Message ID 1440708972-17112-7-git-send-email-ville.syrjala@linux.intel.com
State New
Headers show

Commit Message

Ville Syrjala Aug. 27, 2015, 8:56 p.m. UTC
From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Move the 0 initialization of pin_mask and long_mask from
intel_get_hpd_pins() into each caller. This we we can call
intel_get_hpd_pins() multiple times to accumulate more pins from several
sources.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_irq.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

Comments

Paulo Zanoni Aug. 28, 2015, 6:01 p.m. UTC | #1
2015-08-27 17:56 GMT-03:00  <ville.syrjala@linux.intel.com>:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> Move the 0 initialization of pin_mask and long_mask from
> intel_get_hpd_pins() into each caller. This we we can call
> intel_get_hpd_pins() multiple times to accumulate more pins from several
> sources.

Hmm... I'm not a big fan of this approach since it makes the code more
dangerous. I wouldn't be surprised if next year we discover that the
code for the next hardware generation forgot to zero-initialize the
variables. You know, programmers from the future are always really
bad.

You could at least write a small comment at the top of
intel_get_hpd_pins() telling the callers to clear their masks first.

I would still prefer my original suggestion of having 2 variables for
people who call this twice, but this one is correct, so:
Reviewed-by: Paulo Zanoni <paulo.r.zanoni@intel.com>

>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>  drivers/gpu/drm/i915/i915_irq.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
> index 3388b64..db27945 100644
> --- a/drivers/gpu/drm/i915/i915_irq.c
> +++ b/drivers/gpu/drm/i915/i915_irq.c
> @@ -1301,9 +1301,6 @@ static void intel_get_hpd_pins(u32 *pin_mask, u32 *long_mask,
>         enum port port;
>         int i;
>
> -       *pin_mask = 0;
> -       *long_mask = 0;
> -
>         for_each_hpd_pin(i) {
>                 if ((hpd[i] & hotplug_trigger) == 0)
>                         continue;
> @@ -1544,7 +1541,7 @@ static void i9xx_hpd_irq_handler(struct drm_device *dev)
>  {
>         struct drm_i915_private *dev_priv = dev->dev_private;
>         u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
> -       u32 pin_mask, long_mask;
> +       u32 pin_mask = 0, long_mask = 0;
>
>         if (!hotplug_status)
>                 return;
> @@ -1673,7 +1670,7 @@ static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
>         u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
>
>         if (hotplug_trigger) {
> -               u32 dig_hotplug_reg, pin_mask, long_mask;
> +               u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
>
>                 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
>                 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
> @@ -1781,7 +1778,7 @@ static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
>                 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
>
>         if (hotplug_trigger) {
> -               u32 dig_hotplug_reg, pin_mask, long_mask;
> +               u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
>
>                 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
>                 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
> @@ -2004,7 +2001,7 @@ static void bxt_hpd_handler(struct drm_device *dev, uint32_t iir_status)
>  {
>         struct drm_i915_private *dev_priv = dev->dev_private;
>         u32 hp_control, hp_trigger;
> -       u32 pin_mask, long_mask;
> +       u32 pin_mask = 0, long_mask = 0;
>
>         /* Get the status */
>         hp_trigger = iir_status & BXT_DE_PORT_HOTPLUG_MASK;
> --
> 2.4.6
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Ville Syrjala Aug. 28, 2015, 6:25 p.m. UTC | #2
On Fri, Aug 28, 2015 at 03:01:50PM -0300, Paulo Zanoni wrote:
> 2015-08-27 17:56 GMT-03:00  <ville.syrjala@linux.intel.com>:
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> >
> > Move the 0 initialization of pin_mask and long_mask from
> > intel_get_hpd_pins() into each caller. This we we can call
> > intel_get_hpd_pins() multiple times to accumulate more pins from several
> > sources.
> 
> Hmm... I'm not a big fan of this approach since it makes the code more
> dangerous. I wouldn't be surprised if next year we discover that the
> code for the next hardware generation forgot to zero-initialize the
> variables. You know, programmers from the future are always really
> bad.

Yeah there's a slight danger. But after the series all the hpd handling
is rather uniform looking, so hopefully the future programmers will just
resort to copy-paste and get it right ;)

> 
> You could at least write a small comment at the top of
> intel_get_hpd_pins() telling the callers to clear their masks first.

Done.

> 
> I would still prefer my original suggestion of having 2 variables for
> people who call this twice, but this one is correct, so:
> Reviewed-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
> 
> >
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > ---
> >  drivers/gpu/drm/i915/i915_irq.c | 11 ++++-------
> >  1 file changed, 4 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
> > index 3388b64..db27945 100644
> > --- a/drivers/gpu/drm/i915/i915_irq.c
> > +++ b/drivers/gpu/drm/i915/i915_irq.c
> > @@ -1301,9 +1301,6 @@ static void intel_get_hpd_pins(u32 *pin_mask, u32 *long_mask,
> >         enum port port;
> >         int i;
> >
> > -       *pin_mask = 0;
> > -       *long_mask = 0;
> > -
> >         for_each_hpd_pin(i) {
> >                 if ((hpd[i] & hotplug_trigger) == 0)
> >                         continue;
> > @@ -1544,7 +1541,7 @@ static void i9xx_hpd_irq_handler(struct drm_device *dev)
> >  {
> >         struct drm_i915_private *dev_priv = dev->dev_private;
> >         u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
> > -       u32 pin_mask, long_mask;
> > +       u32 pin_mask = 0, long_mask = 0;
> >
> >         if (!hotplug_status)
> >                 return;
> > @@ -1673,7 +1670,7 @@ static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
> >         u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
> >
> >         if (hotplug_trigger) {
> > -               u32 dig_hotplug_reg, pin_mask, long_mask;
> > +               u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
> >
> >                 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
> >                 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
> > @@ -1781,7 +1778,7 @@ static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
> >                 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
> >
> >         if (hotplug_trigger) {
> > -               u32 dig_hotplug_reg, pin_mask, long_mask;
> > +               u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
> >
> >                 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
> >                 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
> > @@ -2004,7 +2001,7 @@ static void bxt_hpd_handler(struct drm_device *dev, uint32_t iir_status)
> >  {
> >         struct drm_i915_private *dev_priv = dev->dev_private;
> >         u32 hp_control, hp_trigger;
> > -       u32 pin_mask, long_mask;
> > +       u32 pin_mask = 0, long_mask = 0;
> >
> >         /* Get the status */
> >         hp_trigger = iir_status & BXT_DE_PORT_HOTPLUG_MASK;
> > --
> > 2.4.6
> >
> > _______________________________________________
> > Intel-gfx mailing list
> > Intel-gfx@lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/intel-gfx
> 
> 
> 
> -- 
> Paulo Zanoni

Patch
diff mbox

diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
index 3388b64..db27945 100644
--- a/drivers/gpu/drm/i915/i915_irq.c
+++ b/drivers/gpu/drm/i915/i915_irq.c
@@ -1301,9 +1301,6 @@  static void intel_get_hpd_pins(u32 *pin_mask, u32 *long_mask,
 	enum port port;
 	int i;
 
-	*pin_mask = 0;
-	*long_mask = 0;
-
 	for_each_hpd_pin(i) {
 		if ((hpd[i] & hotplug_trigger) == 0)
 			continue;
@@ -1544,7 +1541,7 @@  static void i9xx_hpd_irq_handler(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
-	u32 pin_mask, long_mask;
+	u32 pin_mask = 0, long_mask = 0;
 
 	if (!hotplug_status)
 		return;
@@ -1673,7 +1670,7 @@  static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
 	u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
 
 	if (hotplug_trigger) {
-		u32 dig_hotplug_reg, pin_mask, long_mask;
+		u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
 
 		dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
 		I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
@@ -1781,7 +1778,7 @@  static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
 		hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
 
 	if (hotplug_trigger) {
-		u32 dig_hotplug_reg, pin_mask, long_mask;
+		u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
 
 		dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
 		I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
@@ -2004,7 +2001,7 @@  static void bxt_hpd_handler(struct drm_device *dev, uint32_t iir_status)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	u32 hp_control, hp_trigger;
-	u32 pin_mask, long_mask;
+	u32 pin_mask = 0, long_mask = 0;
 
 	/* Get the status */
 	hp_trigger = iir_status & BXT_DE_PORT_HOTPLUG_MASK;