Skip to contentSkip to conversation

drm/i915/bxt: Fix wrongly placed ')' in I915_READ()

PATCH Applied Damien Lespiau 5 participants 7 messages Sep 17, 2015 – Oct 14, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/i915/bxt: Fix wrongly placed ')' in I915_READ()

Not the first time! not the last time?

There is a possibility to use gcc 5's -Wbool-compare to try and compare (reg) in those macros to a constant and gcc will warn that the comparison between a boolean expression and a constant is always either true or false. Maybe.

---
 drivers/gpu/drm/i915/intel_ddi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_ddi.c +1 -1
index 4823184..5b600bf 100644
@@ -2882,7 +2882,7 @@ static bool bxt_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv,
 	 * here just read out lanes 0/1 and output a note if lanes 2/3 differ.
 	 */
 	hw_state->pcsdw12 = I915_READ(BXT_PORT_PCS_DW12_LN01(port));
-	if (I915_READ(BXT_PORT_PCS_DW12_LN23(port) != hw_state->pcsdw12))
+	if (I915_READ(BXT_PORT_PCS_DW12_LN23(port)) != hw_state->pcsdw12)
 		DRM_DEBUG_DRIVER("lane stagger config different for lane 01 (%08x) and 23 (%08x)\n",
 				 hw_state->pcsdw12,
 				 I915_READ(BXT_PORT_PCS_DW12_LN23(port)));
Signature · 6 lines
2.1.0

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Damien Lespiau

Not the first time! not the last time?

There is a possibility to use gcc 5's -Wbool-compare to try and compare (reg) in those macros to a constant and gcc will warn that the comparison between a boolean expression and a constant is always either true or false. Maybe.

Errrr. Thanks for catching it:

Quoted 9 lines
---
 drivers/gpu/drm/i915/intel_ddi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_ddi.c +0 -0
index 4823184..5b600bf 100644

drivers/gpu/drm/i915/intel_ddi.c static bool bxt_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv, · line 2888

Quoted 8 lines
drivers/gpu/drm/i915/intel_ddi.c +1 -1
@@ -2882,7 +2882,7 @@ static bool bxt_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv,
 	 * here just read out lanes 0/1 and output a note if lanes 2/3 differ.
 	 */
 	hw_state->pcsdw12 = I915_READ(BXT_PORT_PCS_DW12_LN01(port));
-	if (I915_READ(BXT_PORT_PCS_DW12_LN23(port) != hw_state->pcsdw12))
+	if (I915_READ(BXT_PORT_PCS_DW12_LN23(port)) != hw_state->pcsdw12)
 		DRM_DEBUG_DRIVER("lane stagger config different for lane 01 (%08x) and 23 (%08x)\n",
 				 hw_state->pcsdw12,
 				 I915_READ(BXT_PORT_PCS_DW12_LN23(port)));

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

maintainer Applied
#2 lore raw
Quoted 8 lines · Imre Deak
Quoted 7 lines · Damien Lespiau

Not the first time! not the last time?

There is a possibility to use gcc 5's -Wbool-compare to try and compare (reg) in those macros to a constant and gcc will warn that the comparison between a boolean expression and a constant is always either true or false. Maybe.

Quoted 5 lines
Quoted 2 lines

Errrr. Thanks for catching it:

Pushed to drm-intel-next-queued, thanks for the patch and review.

BR,
Jani.

Quoted 24 lines
Quoted 10 lines
---
 drivers/gpu/drm/i915/intel_ddi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_ddi.c +0 -0
index 4823184..5b600bf 100644

drivers/gpu/drm/i915/intel_ddi.c static bool bxt_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv, · line 2888

Quoted 8 lines
drivers/gpu/drm/i915/intel_ddi.c +1 -1
@@ -2882,7 +2882,7 @@ static bool bxt_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv,
 	 * here just read out lanes 0/1 and output a note if lanes 2/3 differ.
 	 */
 	hw_state->pcsdw12 = I915_READ(BXT_PORT_PCS_DW12_LN01(port));
-	if (I915_READ(BXT_PORT_PCS_DW12_LN23(port) != hw_state->pcsdw12))
+	if (I915_READ(BXT_PORT_PCS_DW12_LN23(port)) != hw_state->pcsdw12)
 		DRM_DEBUG_DRIVER("lane stagger config different for lane 01 (%08x) and 23 (%08x)\n",
 				 hw_state->pcsdw12,
 				 I915_READ(BXT_PORT_PCS_DW12_LN23(port)));

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw
In reply to Damien Lespiau
Quoted 6 lines · Damien Lespiau

Not the first time! not the last time?

There is a possibility to use gcc 5's -Wbool-compare to try and compare (reg) in those macros to a constant and gcc will warn that the comparison between a boolean expression and a constant is always either true or false. Maybe.

Since boolean true (1) cannot be a valid argument to this macro, it could contain a compile-time check that the parameter is not 1; if boolean false (0) happens not to be a valid register address (BSpec says MMIO 0 is reserved) the macro could check that the argument is neither of these values, and the compiler might then detect that all possible paths lead to a compile-time error. Something like this?

#define I915_READ(reg)                                                 \
        ({                                                             \
            if (__builtin_constant_p(reg)) {                           \
                BUILD_BUG_ON((reg) == false);                          \
                BUILD_BUG_ON((reg) == true);                           \
            }                                                          \
            dev_priv->uncore.funcs.mmio_readl(dev_priv, (reg), true);  \
        })

Interestingly, that reported three errors, all in intel_dsi.c where the port-selection macros use 0s to fill in dummy elements when less than 3 ports are being used.

In function ‘intel_dsi_get_hw_state’
In function ‘intel_dsi_port_disable’
In function ‘intel_dsi_port_enable’

Other than that, there weren't any cases where a bool constant was being passed to this specific macro (as of today).

.Dave.

Quoted 11 lines
---
  drivers/gpu/drm/i915/intel_ddi.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_ddi.c +0 -0
index 4823184..5b600bf 100644

drivers/gpu/drm/i915/intel_ddi.c static bool bxt_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv, · line 2888

Quoted 8 lines
drivers/gpu/drm/i915/intel_ddi.c +1 -1
@@ -2882,7 +2882,7 @@ static bool bxt_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv,
  	 * here just read out lanes 0/1 and output a note if lanes 2/3 differ.
  	 */
  	hw_state->pcsdw12 = I915_READ(BXT_PORT_PCS_DW12_LN01(port));
-	if (I915_READ(BXT_PORT_PCS_DW12_LN23(port) != hw_state->pcsdw12))
+	if (I915_READ(BXT_PORT_PCS_DW12_LN23(port)) != hw_state->pcsdw12)
  		DRM_DEBUG_DRIVER("lane stagger config different for lane 01 (%08x) and 23 (%08x)\n",
  				 hw_state->pcsdw12,
  				 I915_READ(BXT_PORT_PCS_DW12_LN23(port)));

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#4 lore raw
Quoted 15 lines · Dave Gordon
Quoted 6 lines · Damien Lespiau

Not the first time! not the last time?

There is a possibility to use gcc 5's -Wbool-compare to try and compare (reg) in those macros to a constant and gcc will warn that the comparison between a boolean expression and a constant is always either true or false. Maybe.

Since boolean true (1) cannot be a valid argument to this macro, it could contain a compile-time check that the parameter is not 1; if boolean false
(0) happens not to be a valid register address (BSpec says MMIO 0 is reserved) the macro could check that the argument is neither of these values, and the compiler might then detect that all possible paths lead to a compile-time error. Something like this?

Quoted 8 lines
#define I915_READ(reg)                                                 \
        ({                                                             \
            if (__builtin_constant_p(reg)) {                           \
                BUILD_BUG_ON((reg) == false);                          \
                BUILD_BUG_ON((reg) == true);                           \
            }                                                          \
            dev_priv->uncore.funcs.mmio_readl(dev_priv, (reg), true);  \
        })

I like this.

Quoted 10 lines

Interestingly, that reported three errors, all in intel_dsi.c where the port-selection macros use 0s to fill in dummy elements when less than 3 ports are being used.

In function ‘intel_dsi_get_hw_state’
In function ‘intel_dsi_port_disable’
In function ‘intel_dsi_port_enable’

Other than that, there weren't any cases where a bool constant was being passed to this specific macro (as of today).

I guess we could fix for_each_dsi_port to only enumerate A and C with something like

#define for_each_dsi_port(port, mask) \
	for (port = PORT_A, port <= PORT_C; port == PORT_A ? PORT_C : port++) \
		if (...)

I still think that Ville's approach should catch even more fallout (like mixing up values and registers for write maybe), but this is a great interim hack.

Patch wanted ;-)

-Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
maintainer
#5 lore raw
In reply to Dave Gordon
Quoted 8 lines · Dave Gordon
Quoted 6 lines · Damien Lespiau

Not the first time! not the last time?

There is a possibility to use gcc 5's -Wbool-compare to try and compare (reg) in those macros to a constant and gcc will warn that the comparison between a boolean expression and a constant is always either true or false. Maybe.

Quoted 6 lines

Since boolean true (1) cannot be a valid argument to this macro, it could contain a compile-time check that the parameter is not 1; if boolean false (0) happens not to be a valid register address (BSpec says MMIO 0 is reserved) the macro could check that the argument is neither of these values, and the compiler might then detect that all possible paths lead to a compile-time error. Something like this?

The past errors have also been of the form

	if (I915_READ(SOME_REG(pipe) & MASK) == val)

which isn't caught by your check. See [1].

BR,
Jani.

[1] http://mid.gmane.org/[email protected]

Quoted 48 lines
#define I915_READ(reg)                                                 \
         ({                                                             \
             if (__builtin_constant_p(reg)) {                           \
                 BUILD_BUG_ON((reg) == false);                          \
                 BUILD_BUG_ON((reg) == true);                           \
             }                                                          \
             dev_priv->uncore.funcs.mmio_readl(dev_priv, (reg), true);  \
         })

Interestingly, that reported three errors, all in intel_dsi.c where the port-selection macros use 0s to fill in dummy elements when less than 3 ports are being used.

In function ‘intel_dsi_get_hw_state’
In function ‘intel_dsi_port_disable’
In function ‘intel_dsi_port_enable’

Other than that, there weren't any cases where a bool constant was being passed to this specific macro (as of today).

.Dave.

Quoted 11 lines
---
  drivers/gpu/drm/i915/intel_ddi.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_ddi.c +0 -0
index 4823184..5b600bf 100644

drivers/gpu/drm/i915/intel_ddi.c static bool bxt_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv, · line 2888

Quoted 8 lines
drivers/gpu/drm/i915/intel_ddi.c +1 -1
@@ -2882,7 +2882,7 @@ static bool bxt_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv,
  	 * here just read out lanes 0/1 and output a note if lanes 2/3 differ.
  	 */
  	hw_state->pcsdw12 = I915_READ(BXT_PORT_PCS_DW12_LN01(port));
-	if (I915_READ(BXT_PORT_PCS_DW12_LN23(port) != hw_state->pcsdw12))
+	if (I915_READ(BXT_PORT_PCS_DW12_LN23(port)) != hw_state->pcsdw12)
  		DRM_DEBUG_DRIVER("lane stagger config different for lane 01 (%08x) and 23 (%08x)\n",
  				 hw_state->pcsdw12,
  				 I915_READ(BXT_PORT_PCS_DW12_LN23(port)));

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
maintainer
#6 lore raw
Quoted 20 lines · Jani Nikula
Quoted 8 lines · Dave Gordon
Quoted 6 lines · Damien Lespiau

Not the first time! not the last time?

There is a possibility to use gcc 5's -Wbool-compare to try and compare (reg) in those macros to a constant and gcc will warn that the comparison between a boolean expression and a constant is always either true or false. Maybe.

Quoted 6 lines

Since boolean true (1) cannot be a valid argument to this macro, it could contain a compile-time check that the parameter is not 1; if boolean false (0) happens not to be a valid register address (BSpec says MMIO 0 is reserved) the macro could check that the argument is neither of these values, and the compiler might then detect that all possible paths lead to a compile-time error. Something like this?

The past errors have also been of the form

	if (I915_READ(SOME_REG(pipe) & MASK) == val)
Quoted 17 lines

which isn't caught by your check. See [1].

BR,
Jani.

[1] http://mid.gmane.org/[email protected]

Quoted 4 lines
#define I915_READ(reg)                                                 \
         ({                                                             \
             if (__builtin_constant_p(reg)) {                           \

Also, what Damien fixed wouldn't have been caught because "BXT_PORT_PCS_DW12_LN23(port) != hw_state->pcsdw12" is not a builtin constant.

Daniel, I don't think this is interim solution material, sorry.

BR,
Jani.

Quoted 47 lines
Quoted 44 lines
                 BUILD_BUG_ON((reg) == false);                          \
                 BUILD_BUG_ON((reg) == true);                           \
             }                                                          \
             dev_priv->uncore.funcs.mmio_readl(dev_priv, (reg), true);  \
         })

Interestingly, that reported three errors, all in intel_dsi.c where the port-selection macros use 0s to fill in dummy elements when less than 3 ports are being used.

In function ‘intel_dsi_get_hw_state’
In function ‘intel_dsi_port_disable’
In function ‘intel_dsi_port_enable’

Other than that, there weren't any cases where a bool constant was being passed to this specific macro (as of today).

.Dave.

Quoted 11 lines
---
  drivers/gpu/drm/i915/intel_ddi.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_ddi.c +0 -0
index 4823184..5b600bf 100644

drivers/gpu/drm/i915/intel_ddi.c static bool bxt_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv, · line 2888

Quoted 8 lines
drivers/gpu/drm/i915/intel_ddi.c +1 -1
@@ -2882,7 +2882,7 @@ static bool bxt_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv,
  	 * here just read out lanes 0/1 and output a note if lanes 2/3 differ.
  	 */
  	hw_state->pcsdw12 = I915_READ(BXT_PORT_PCS_DW12_LN01(port));
-	if (I915_READ(BXT_PORT_PCS_DW12_LN23(port) != hw_state->pcsdw12))
+	if (I915_READ(BXT_PORT_PCS_DW12_LN23(port)) != hw_state->pcsdw12)
  		DRM_DEBUG_DRIVER("lane stagger config different for lane 01 (%08x) and 23 (%08x)\n",
  				 hw_state->pcsdw12,
  				 I915_READ(BXT_PORT_PCS_DW12_LN23(port)));

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Signature · 1 line
Jani Nikula, Intel Open Source Technology Center
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx