Skip to contentSkip to conversation

staging: fbtft: reduce stack usage

PATCH In review Arnd Bergmann 2 participants 2 messages Jun 10, 2025

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

PATCH v2 1/1 staging: fbtft: reduce stack usage

From: Arnd Bergmann <[email protected]>

The use of vararg function pointers combined with a huge number of arguments causes some configurations to exceed the stack size warning limit:

drivers/staging/fbtft/fbtft-core.c:863:12: error: stack frame size (1512) exceeds limit (1280) in 'fbtft_init_display_from_property' [-Werror,-Wframe-larger-than]

drivers/staging/fbtft/fb_ssd1331.c:131:30: error: stack frame size (1392) exceeds limit (1280) in 'set_gamma' [-Werror,-Wframe-larger-than]

                  ^

drivers/staging/fbtft/fb_ssd1351.c:120:30: error: stack frame size (1392) exceeds limit (1280) in 'set_gamma' [-Werror,-Wframe-larger-than]

Move the varargs handling into a separate noinline function so each individual function stays below the limit. A better approach might be to replace the varargs function with one that takes an array of arguments, but that would be a much larger rework of the other callers.

---
v2: use u32 types consistently, suggested by Andy Shevchenko

---
 drivers/staging/fbtft/fb_ssd1331.c | 36 ++++++++++++------
 drivers/staging/fbtft/fb_ssd1351.c | 42 +++++++++++---------
 drivers/staging/fbtft/fbtft-core.c | 61 +++++++++++++-----------------
 3 files changed, 74 insertions(+), 65 deletions(-)
drivers/staging/fbtft/fb_ssd1331.c +24 -12
index 06b7056d6c71..f43ee3249175 100644
@@ -107,6 +107,28 @@ static void write_reg8_bus8(struct fbtft_par *par, int len, ...)
 	va_end(args);
 }
 
+static noinline_for_stack void write_gamma_reg(struct fbtft_par *par,
+					       u32 gamma[63])
+{
+	write_reg(par, 0xB8,
+		  gamma[0],  gamma[1],  gamma[2],  gamma[3],
+		  gamma[4],  gamma[5],  gamma[6],  gamma[7],
+		  gamma[8],  gamma[9],  gamma[10], gamma[11],
+		  gamma[12], gamma[13], gamma[14], gamma[15],
+		  gamma[16], gamma[17], gamma[18], gamma[19],
+		  gamma[20], gamma[21], gamma[22], gamma[23],
+		  gamma[24], gamma[25], gamma[26], gamma[27],
+		  gamma[28], gamma[29], gamma[30], gamma[31],
+		  gamma[32], gamma[33], gamma[34], gamma[35],
+		  gamma[36], gamma[37], gamma[38], gamma[39],
+		  gamma[40], gamma[41], gamma[42], gamma[43],
+		  gamma[44], gamma[45], gamma[46], gamma[47],
+		  gamma[48], gamma[49], gamma[50], gamma[51],
+		  gamma[52], gamma[53], gamma[54], gamma[55],
+		  gamma[56], gamma[57], gamma[58], gamma[59],
+		  gamma[60], gamma[61], gamma[62]);
+}
+
 /*
  * Grayscale Lookup Table
  * GS1 - GS63
@@ -130,7 +152,7 @@ static void write_reg8_bus8(struct fbtft_par *par, int len, ...)
  */
 static int set_gamma(struct fbtft_par *par, u32 *curves)
 {
-	unsigned long tmp[GAMMA_NUM * GAMMA_LEN];
+	u32 tmp[GAMMA_NUM * GAMMA_LEN];
 	int i, acc = 0;
 
 	for (i = 0; i < 63; i++) {
@@ -150,17 +172,7 @@ static int set_gamma(struct fbtft_par *par, u32 *curves)
 		}
 	}
 
-	write_reg(par, 0xB8,
-		  tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5], tmp[6],
-		  tmp[7], tmp[8], tmp[9], tmp[10], tmp[11], tmp[12], tmp[13],
-		  tmp[14], tmp[15], tmp[16], tmp[17], tmp[18], tmp[19], tmp[20],
-		  tmp[21], tmp[22], tmp[23], tmp[24], tmp[25], tmp[26],	tmp[27],
-		  tmp[28], tmp[29], tmp[30], tmp[31], tmp[32], tmp[33], tmp[34],
-		  tmp[35], tmp[36], tmp[37], tmp[38], tmp[39], tmp[40], tmp[41],
-		  tmp[42], tmp[43], tmp[44], tmp[45], tmp[46], tmp[47], tmp[48],
-		  tmp[49], tmp[50], tmp[51], tmp[52], tmp[53], tmp[54], tmp[55],
-		  tmp[56], tmp[57], tmp[58], tmp[59], tmp[60], tmp[61],
-		  tmp[62]);
+	write_gamma_reg(par, tmp);
 
 	return 0;
 }
drivers/staging/fbtft/fb_ssd1351.c +24 -18

60 lines not on this page · raw message

drivers/staging/fbtft/fbtft-core.c +26 -35

85 lines not on this page · raw message

Signature · 1 line
2.39.5
#1 lore raw

drivers/staging/fbtft/fbtft-core.c EXPORT_SYMBOL(fbtft_unregister_framebuffer); · line 869

Quoted 7 lines · Arnd Bergmann

{

drivers/staging/fbtft/fbtft-core.c +1 -1
 	struct device *dev = par->info->device;
-	int buf[64], count, index, i, j, ret;
+	u32 buf[64], count, index, i, j, ret;
 	u32 *values;
 	u32 val;

I was too quick to update this one, please ignore v2 and wait for v3 after I've tested it some more with the (hopefully) correct version:

@@ -842,7 +864,8 @@ EXPORT_SYMBOL(fbtft_unregister_framebuffer);
static int fbtft_init_display_from_property(struct fbtft_par *par)

 {
        struct device *dev = par->info->device;
-       int buf[64], count, index, i, j, ret;
+       int count, index, i, j, ret;
+       u32 buf[64];
        u32 *values;
        u32 val;


     Arnd