Skip to contentSkip to conversation

drm/bridge: fix stack usage warning on old gcc

PATCH In review Arnd Bergmann 3 participants 5 messages Apr 28, 2020 – Apr 29, 2020

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

PATCH 1/1 drm/bridge: fix stack usage warning on old gcc

Some older versions of gcc badly optimize code that passes an inline function argument into another function by reference, causing huge stack usage:

drivers/gpu/drm/bridge/tc358768.c: In function 'tc358768_bridge_pre_enable':
drivers/gpu/drm/bridge/tc358768.c:840:1: error: the frame size of 2256 bytes is larger than 2048 bytes [-Werror=frame-larger-than=]

Use a temporary variable as a workaround and add a comment pointing to the gcc bug.

Fixes ff1ca6397b1d ("drm/bridge: Add tc358768 driver")
---
 drivers/gpu/drm/bridge/tc358768.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/tc358768.c +3 -1
index 1b39e8d37834..6650fe4cfc20 100644
@@ -178,6 +178,8 @@ static int tc358768_clear_error(struct tc358768_priv *priv)
 
 static void tc358768_write(struct tc358768_priv *priv, u32 reg, u32 val)
 {
+	/* work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */
+	int tmpval = val;
 	size_t count = 2;
 
 	if (priv->error)
@@ -187,7 +189,7 @@ static void tc358768_write(struct tc358768_priv *priv, u32 reg, u32 val)
 	if (reg < 0x100 || reg >= 0x600)
 		count = 1;
 
-	priv->error = regmap_bulk_write(priv->regmap, reg, &val, count);
+	priv->error = regmap_bulk_write(priv->regmap, reg, &tmpval, count);
 }
 
 static void tc358768_read(struct tc358768_priv *priv, u32 reg, u32 *val)
Signature · 6 lines
2.26.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 31 lines · Arnd Bergmann

Some older versions of gcc badly optimize code that passes an inline function argument into another function by reference, causing huge stack usage:

drivers/gpu/drm/bridge/tc358768.c: In function 'tc358768_bridge_pre_enable':
drivers/gpu/drm/bridge/tc358768.c:840:1: error: the frame size of 2256 bytes is larger than 2048 bytes [-Werror=frame-larger-than=]

Use a temporary variable as a workaround and add a comment pointing to the gcc bug.

Fixes ff1ca6397b1d ("drm/bridge: Add tc358768 driver")
---
  drivers/gpu/drm/bridge/tc358768.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/tc358768.c +2 -0
index 1b39e8d37834..6650fe4cfc20 100644
@@ -178,6 +178,8 @@ static int tc358768_clear_error(struct tc358768_priv *priv)
 
  static void tc358768_write(struct tc358768_priv *priv, u32 reg, u32 val)
  {
+	/* work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */
+	int tmpval = val;
  	size_t count = 2;
 
  	if (priv->error)

drivers/gpu/drm/bridge/tc358768.c static void tc358768_write(struct tc358768_priv *priv, u32 reg, u32 val) · line 195

Quoted 8 lines
drivers/gpu/drm/bridge/tc358768.c +1 -1
@@ -187,7 +189,7 @@ static void tc358768_write(struct tc358768_priv *priv, u32 reg, u32 val)
  	if (reg < 0x100 || reg >= 0x600)
  		count = 1;
 
-	priv->error = regmap_bulk_write(priv->regmap, reg, &val, count);
+	priv->error = regmap_bulk_write(priv->regmap, reg, &tmpval, count);
  }
 
  static void tc358768_read(struct tc358768_priv *priv, u32 reg, u32 *val)

tc358768_write is not inline. What is the inline function here? Or is tc358768_write optimized to inline by the compiler?

Tomi

Signature · 6 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw
Quoted 6 lines · Tomi Valkeinen
Quoted 6 lines
drivers/gpu/drm/bridge/tc358768.c +0 -0
index 1b39e8d37834..6650fe4cfc20 100644
@@ -178,6 +178,8 @@ static int tc358768_clear_error(struct tc358768_priv *priv)
 
Quoted 8 lines

drivers/gpu/drm/bridge/tc358768.c static int tc358768_clear_error(struct tc358768_priv *priv) · line 182

Quoted 4 lines
drivers/gpu/drm/bridge/tc358768.c +2 -0
  static void tc358768_write(struct tc358768_priv *priv, u32 reg, u32 val)
  {
+     /* work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */
+     int tmpval = val;

tc358768_write is not inline. What is the inline function here? Or is tc358768_write optimized to inline by the compiler?

I missed the lack of an explicit inline tag when looking at the bug. gcc usually decides which functions to inline on its own, so there is little difference in practice. Let me know if I should clarify the changelog and resend it.

Arnd
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reviewed-by
#3 lore raw
Quoted 16 lines · Arnd Bergmann
Quoted 6 lines · Tomi Valkeinen
Quoted 6 lines
drivers/gpu/drm/bridge/tc358768.c +0 -0
index 1b39e8d37834..6650fe4cfc20 100644
@@ -178,6 +178,8 @@ static int tc358768_clear_error(struct tc358768_priv *priv)
 
Quoted 8 lines

drivers/gpu/drm/bridge/tc358768.c static int tc358768_clear_error(struct tc358768_priv *priv) · line 182

Quoted 4 lines
drivers/gpu/drm/bridge/tc358768.c +2 -0
   static void tc358768_write(struct tc358768_priv *priv, u32 reg, u32 val)
   {
+     /* work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */
+     int tmpval = val;

tc358768_write is not inline. What is the inline function here? Or is tc358768_write optimized to inline by the compiler?

Quoted 4 lines

I missed the lack of an explicit inline tag when looking at the bug. gcc usually decides which functions to inline on its own, so there is little difference in practice. Let me know if I should clarify the changelog and resend it.

Ok. I think this is fine.

Tomi

Signature · 6 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw
In reply to Arnd Bergmann

Hi Arnd.

Quoted 4 lines · Arnd Bergmann

Some older versions of gcc badly optimize code that passes an inline function argument into another function by reference, causing huge stack usage:

Quoted 8 lines

drivers/gpu/drm/bridge/tc358768.c: In function 'tc358768_bridge_pre_enable':
drivers/gpu/drm/bridge/tc358768.c:840:1: error: the frame size of 2256 bytes is larger than 2048 bytes [-Werror=frame-larger-than=]

Use a temporary variable as a workaround and add a comment pointing to the gcc bug.

Fixes ff1ca6397b1d ("drm/bridge: Add tc358768 driver")

Thanks, pushed to drm-misc-next with Tomi's r-b.

Sam

Quoted 33 lines
---
 drivers/gpu/drm/bridge/tc358768.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/tc358768.c +3 -1
index 1b39e8d37834..6650fe4cfc20 100644
@@ -178,6 +178,8 @@ static int tc358768_clear_error(struct tc358768_priv *priv)
 
 static void tc358768_write(struct tc358768_priv *priv, u32 reg, u32 val)
 {
+	/* work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */
+	int tmpval = val;
 	size_t count = 2;
 
 	if (priv->error)
@@ -187,7 +189,7 @@ static void tc358768_write(struct tc358768_priv *priv, u32 reg, u32 val)
 	if (reg < 0x100 || reg >= 0x600)
 		count = 1;
 
-	priv->error = regmap_bulk_write(priv->regmap, reg, &val, count);
+	priv->error = regmap_bulk_write(priv->regmap, reg, &tmpval, count);
 }
 
 static void tc358768_read(struct tc358768_priv *priv, u32 reg, u32 *val)
Signature · 6 lines
2.26.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel