Skip to content

Commit 89f3b31

Browse files
arndbmchehab
authored andcommitted
media: staging: media: atomisp: fix stack overflow in init_pipe_defaults()
When building with clang, multiple copies of the structures to be initialized are passed around on the stack and copied locally, using an insane amount of stack space: drivers/staging/media/atomisp/pci/sh_css.c:2371:1: error: stack frame size of 26864 bytes in function 'create_pipe' [-Werror,-Wframe-larger-than=] Use constantly-allocated variables plus an explicit memcpy() to avoid that. Co-authored-by: Mauro Carvalho Chehab <[email protected]> Fixes: 6dc9a25 ("media: atomisp: convert default struct values to use compound-literals with designated initializers") Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 5b552b1 commit 89f3b31

File tree

9 files changed

+46
-42
lines changed

9 files changed

+46
-42
lines changed

drivers/staging/media/atomisp/pci/ia_css_frame_public.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ struct ia_css_frame_info {
122122
struct ia_css_crop_info crop_info;
123123
};
124124

125-
#define IA_CSS_BINARY_DEFAULT_FRAME_INFO \
126-
(struct ia_css_frame_info) { \
125+
#define IA_CSS_BINARY_DEFAULT_FRAME_INFO { \
127126
.format = IA_CSS_FRAME_FORMAT_NUM, \
128127
.raw_bayer_order = IA_CSS_BAYER_ORDER_NUM, \
129128
}
@@ -185,8 +184,7 @@ struct ia_css_frame {
185184
info.format */
186185
};
187186

188-
#define DEFAULT_FRAME \
189-
(struct ia_css_frame) { \
187+
#define DEFAULT_FRAME { \
190188
.info = IA_CSS_BINARY_DEFAULT_FRAME_INFO, \
191189
.dynamic_queue_id = SH_CSS_INVALID_QUEUE_ID, \
192190
.buf_type = IA_CSS_BUFFER_TYPE_INVALID, \

drivers/staging/media/atomisp/pci/ia_css_pipe.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ struct ia_css_preview_settings {
4040
struct ia_css_pipe *acc_pipe;
4141
};
4242

43-
#define IA_CSS_DEFAULT_PREVIEW_SETTINGS \
44-
(struct ia_css_preview_settings) { \
43+
#define IA_CSS_DEFAULT_PREVIEW_SETTINGS { \
4544
.copy_binary = IA_CSS_BINARY_DEFAULT_SETTINGS, \
4645
.preview_binary = IA_CSS_BINARY_DEFAULT_SETTINGS, \
4746
.vf_pp_binary = IA_CSS_BINARY_DEFAULT_SETTINGS, \
@@ -65,8 +64,7 @@ struct ia_css_capture_settings {
6564
unsigned int num_yuv_scaler;
6665
};
6766

68-
#define IA_CSS_DEFAULT_CAPTURE_SETTINGS \
69-
(struct ia_css_capture_settings) { \
67+
#define IA_CSS_DEFAULT_CAPTURE_SETTINGS { \
7068
.copy_binary = IA_CSS_BINARY_DEFAULT_SETTINGS, \
7169
.primary_binary = {IA_CSS_BINARY_DEFAULT_SETTINGS}, \
7270
.pre_isp_binary = IA_CSS_BINARY_DEFAULT_SETTINGS, \
@@ -91,8 +89,7 @@ struct ia_css_video_settings {
9189
unsigned int num_yuv_scaler;
9290
};
9391

94-
#define IA_CSS_DEFAULT_VIDEO_SETTINGS \
95-
(struct ia_css_video_settings) { \
92+
#define IA_CSS_DEFAULT_VIDEO_SETTINGS { \
9693
.copy_binary = IA_CSS_BINARY_DEFAULT_SETTINGS, \
9794
.video_binary = IA_CSS_BINARY_DEFAULT_SETTINGS, \
9895
.vf_pp_binary = IA_CSS_BINARY_DEFAULT_SETTINGS, \
@@ -108,8 +105,7 @@ struct ia_css_yuvpp_settings {
108105
unsigned int num_output;
109106
};
110107

111-
#define IA_CSS_DEFAULT_YUVPP_SETTINGS \
112-
(struct ia_css_yuvpp_settings) { \
108+
#define IA_CSS_DEFAULT_YUVPP_SETTINGS { \
113109
.copy_binary = IA_CSS_BINARY_DEFAULT_SETTINGS, \
114110
}
115111

@@ -157,8 +153,7 @@ struct ia_css_pipe {
157153
unsigned int pipe_num;
158154
};
159155

160-
#define IA_CSS_DEFAULT_PIPE \
161-
(struct ia_css_pipe) { \
156+
#define IA_CSS_DEFAULT_PIPE { \
162157
.config = DEFAULT_PIPE_CONFIG, \
163158
.info = DEFAULT_PIPE_INFO, \
164159
.mode = IA_CSS_PIPE_ID_ACC, /* (pipe_id) */ \

drivers/staging/media/atomisp/pci/ia_css_pipe_public.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ struct ia_css_pipe_config {
149149
/**
150150
* Default settings for newly created pipe configurations.
151151
*/
152-
#define DEFAULT_PIPE_CONFIG \
153-
(struct ia_css_pipe_config) { \
152+
#define DEFAULT_PIPE_CONFIG { \
154153
.mode = IA_CSS_PIPE_MODE_PREVIEW, \
155154
.isp_pipe_version = 1, \
156155
.output_info = {IA_CSS_BINARY_DEFAULT_FRAME_INFO}, \
@@ -203,8 +202,7 @@ struct ia_css_pipe_info {
203202
/**
204203
* Defaults for ia_css_pipe_info structs.
205204
*/
206-
#define DEFAULT_PIPE_INFO \
207-
(struct ia_css_pipe_info) { \
205+
#define DEFAULT_PIPE_INFO {\
208206
.output_info = {IA_CSS_BINARY_DEFAULT_FRAME_INFO}, \
209207
.vf_output_info = {IA_CSS_BINARY_DEFAULT_FRAME_INFO}, \
210208
.raw_output_info = IA_CSS_BINARY_DEFAULT_FRAME_INFO, \

drivers/staging/media/atomisp/pci/ia_css_types.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,7 @@ struct ia_css_grid_info {
392392
};
393393

394394
/* defaults for ia_css_grid_info structs */
395-
#define DEFAULT_GRID_INFO \
396-
(struct ia_css_grid_info) { \
395+
#define DEFAULT_GRID_INFO { \
397396
.dvs_grid = DEFAULT_DVS_GRID_INFO, \
398397
.vamem_type = IA_CSS_VAMEM_TYPE_1 \
399398
}
@@ -485,8 +484,7 @@ struct ia_css_capture_config {
485484
};
486485

487486
/* default settings for ia_css_capture_config structs */
488-
#define DEFAULT_CAPTURE_CONFIG \
489-
(struct ia_css_capture_config) { \
487+
#define DEFAULT_CAPTURE_CONFIG { \
490488
.mode = IA_CSS_CAPTURE_MODE_PRIMARY, \
491489
}
492490

drivers/staging/media/atomisp/pci/isp/kernels/sdis/common/ia_css_sdis_common_types.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,11 @@ struct ia_css_dvs_stat_grid_info {
197197

198198
/* DVS statistics generated by accelerator default grid info
199199
*/
200-
#define DEFAULT_DVS_GRID_INFO \
201-
(union ia_css_dvs_grid_u) { \
202-
.dvs_stat_grid_info = (struct ia_css_dvs_stat_grid_info) { \
200+
#define DEFAULT_DVS_GRID_INFO { \
201+
.dvs_stat_grid_info = { \
203202
.fe_roi_cfg = { \
204-
[1] = (struct dvs_stat_public_dvs_level_fe_roi_cfg) { \
205-
.x_start = 4 \
203+
[1] = { \
204+
.x_start = 4 \
206205
} \
207206
} \
208207
} \

drivers/staging/media/atomisp/pci/runtime/binary/interface/ia_css_binary.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ struct ia_css_binary {
144144
struct ia_css_isp_param_css_segments css_params;
145145
};
146146

147-
#define IA_CSS_BINARY_DEFAULT_SETTINGS \
148-
(struct ia_css_binary) { \
147+
#define IA_CSS_BINARY_DEFAULT_SETTINGS { \
149148
.input_format = ATOMISP_INPUT_FORMAT_YUV420_8_LEGACY, \
150149
.in_frame_info = IA_CSS_BINARY_DEFAULT_FRAME_INFO, \
151150
.internal_frame_info = IA_CSS_BINARY_DEFAULT_FRAME_INFO, \

drivers/staging/media/atomisp/pci/runtime/pipeline/interface/ia_css_pipeline.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ struct ia_css_pipeline {
5757
u32 pipe_qos_config;
5858
};
5959

60-
#define DEFAULT_PIPELINE \
61-
(struct ia_css_pipeline) { \
60+
#define DEFAULT_PIPELINE { \
6261
.pipe_id = IA_CSS_PIPE_ID_PREVIEW, \
6362
.in_frame = DEFAULT_FRAME, \
6463
.out_frame = {DEFAULT_FRAME}, \

drivers/staging/media/atomisp/pci/runtime/pipeline/src/pipeline.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,8 @@ static int pipeline_stage_create(
665665
return err;
666666
}
667667

668+
static const struct ia_css_frame ia_css_default_frame = DEFAULT_FRAME;
669+
668670
static void pipeline_init_defaults(
669671
struct ia_css_pipeline *pipeline,
670672
enum ia_css_pipe_id pipe_id,
@@ -677,10 +679,15 @@ static void pipeline_init_defaults(
677679
pipeline->stages = NULL;
678680
pipeline->stop_requested = false;
679681
pipeline->current_stage = NULL;
680-
pipeline->in_frame = DEFAULT_FRAME;
682+
683+
memcpy(&pipeline->in_frame, &ia_css_default_frame,
684+
sizeof(ia_css_default_frame));
685+
681686
for (i = 0; i < IA_CSS_PIPE_MAX_OUTPUT_STAGE; i++) {
682-
pipeline->out_frame[i] = DEFAULT_FRAME;
683-
pipeline->vf_frame[i] = DEFAULT_FRAME;
687+
memcpy(&pipeline->out_frame[i], &ia_css_default_frame,
688+
sizeof(ia_css_default_frame));
689+
memcpy(&pipeline->vf_frame[i], &ia_css_default_frame,
690+
sizeof(ia_css_default_frame));
684691
}
685692
pipeline->num_execs = -1;
686693
pipeline->acquire_isp_each_stage = true;

drivers/staging/media/atomisp/pci/sh_css.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,37 +2233,44 @@ create_host_pipeline(struct ia_css_stream *stream) {
22332233
return err;
22342234
}
22352235

2236+
static const struct ia_css_pipe default_pipe = IA_CSS_DEFAULT_PIPE;
2237+
static const struct ia_css_preview_settings preview = IA_CSS_DEFAULT_PREVIEW_SETTINGS;
2238+
static const struct ia_css_capture_settings capture = IA_CSS_DEFAULT_CAPTURE_SETTINGS;
2239+
static const struct ia_css_video_settings video = IA_CSS_DEFAULT_VIDEO_SETTINGS;
2240+
static const struct ia_css_yuvpp_settings yuvpp = IA_CSS_DEFAULT_YUVPP_SETTINGS;
2241+
22362242
static int
22372243
init_pipe_defaults(enum ia_css_pipe_mode mode,
22382244
struct ia_css_pipe *pipe,
22392245
bool copy_pipe) {
2246+
22402247
if (!pipe)
22412248
{
22422249
IA_CSS_ERROR("NULL pipe parameter");
22432250
return -EINVAL;
22442251
}
22452252

22462253
/* Initialize pipe to pre-defined defaults */
2247-
*pipe = IA_CSS_DEFAULT_PIPE;
2254+
memcpy(pipe, &default_pipe, sizeof(default_pipe));
22482255

22492256
/* TODO: JB should not be needed, but temporary backward reference */
22502257
switch (mode)
22512258
{
22522259
case IA_CSS_PIPE_MODE_PREVIEW:
22532260
pipe->mode = IA_CSS_PIPE_ID_PREVIEW;
2254-
pipe->pipe_settings.preview = IA_CSS_DEFAULT_PREVIEW_SETTINGS;
2261+
memcpy(&pipe->pipe_settings.preview, &preview, sizeof(preview));
22552262
break;
22562263
case IA_CSS_PIPE_MODE_CAPTURE:
22572264
if (copy_pipe) {
22582265
pipe->mode = IA_CSS_PIPE_ID_COPY;
22592266
} else {
22602267
pipe->mode = IA_CSS_PIPE_ID_CAPTURE;
22612268
}
2262-
pipe->pipe_settings.capture = IA_CSS_DEFAULT_CAPTURE_SETTINGS;
2269+
memcpy(&pipe->pipe_settings.capture, &capture, sizeof(capture));
22632270
break;
22642271
case IA_CSS_PIPE_MODE_VIDEO:
22652272
pipe->mode = IA_CSS_PIPE_ID_VIDEO;
2266-
pipe->pipe_settings.video = IA_CSS_DEFAULT_VIDEO_SETTINGS;
2273+
memcpy(&pipe->pipe_settings.video, &video, sizeof(video));
22672274
break;
22682275
case IA_CSS_PIPE_MODE_ACC:
22692276
pipe->mode = IA_CSS_PIPE_ID_ACC;
@@ -2273,7 +2280,7 @@ init_pipe_defaults(enum ia_css_pipe_mode mode,
22732280
break;
22742281
case IA_CSS_PIPE_MODE_YUVPP:
22752282
pipe->mode = IA_CSS_PIPE_ID_YUVPP;
2276-
pipe->pipe_settings.yuvpp = IA_CSS_DEFAULT_YUVPP_SETTINGS;
2283+
memcpy(&pipe->pipe_settings.yuvpp, &yuvpp, sizeof(yuvpp));
22772284
break;
22782285
default:
22792286
return -EINVAL;
@@ -8771,12 +8778,16 @@ sh_css_init_host_sp_control_vars(void) {
87718778
}
87728779

87738780
/*
8774-
* create the internal structures and fill in the configuration data
8775-
*/
8781+
* create the internal structures and fill in the configuration data
8782+
*/
8783+
8784+
static const struct
8785+
ia_css_pipe_config ia_css_pipe_default_config = DEFAULT_PIPE_CONFIG;
8786+
87768787
void ia_css_pipe_config_defaults(struct ia_css_pipe_config *pipe_config)
87778788
{
87788789
ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "ia_css_pipe_config_defaults()\n");
8779-
*pipe_config = DEFAULT_PIPE_CONFIG;
8790+
memcpy(pipe_config, &ia_css_pipe_default_config, sizeof(*pipe_config));
87808791
}
87818792

87828793
void

0 commit comments

Comments
 (0)