]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
media: staging: media: atomisp: fix stack overflow in init_pipe_defaults()
authorArnd Bergmann <arnd@arndb.de>
Fri, 29 May 2020 20:00:27 +0000 (22:00 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Thu, 11 Jun 2020 17:03:03 +0000 (19:03 +0200)
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 <mchehab+huawei@kernel.org>
Fixes: 6dc9a2568f84 ("media: atomisp: convert default struct values to use compound-literals with designated initializers")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/staging/media/atomisp/pci/ia_css_frame_public.h
drivers/staging/media/atomisp/pci/ia_css_pipe.h
drivers/staging/media/atomisp/pci/ia_css_pipe_public.h
drivers/staging/media/atomisp/pci/ia_css_types.h
drivers/staging/media/atomisp/pci/isp/kernels/sdis/common/ia_css_sdis_common_types.h
drivers/staging/media/atomisp/pci/runtime/binary/interface/ia_css_binary.h
drivers/staging/media/atomisp/pci/runtime/pipeline/interface/ia_css_pipeline.h
drivers/staging/media/atomisp/pci/runtime/pipeline/src/pipeline.c
drivers/staging/media/atomisp/pci/sh_css.c

index d822aa235ffe322d210592469c7cdc77555b77de..96c86f0dc81c38ebc558782e88b3dd10ab4dec3b 100644 (file)
@@ -122,8 +122,7 @@ struct ia_css_frame_info {
        struct ia_css_crop_info crop_info;
 };
 
-#define IA_CSS_BINARY_DEFAULT_FRAME_INFO \
-(struct ia_css_frame_info) { \
+#define IA_CSS_BINARY_DEFAULT_FRAME_INFO { \
        .format                 = IA_CSS_FRAME_FORMAT_NUM,  \
        .raw_bayer_order        = IA_CSS_BAYER_ORDER_NUM, \
 }
@@ -185,8 +184,7 @@ struct ia_css_frame {
                       info.format */
 };
 
-#define DEFAULT_FRAME \
-(struct ia_css_frame) { \
+#define DEFAULT_FRAME { \
        .info                   = IA_CSS_BINARY_DEFAULT_FRAME_INFO, \
        .dynamic_queue_id       = SH_CSS_INVALID_QUEUE_ID, \
        .buf_type               = IA_CSS_BUFFER_TYPE_INVALID, \
index 9c0c4ccf4571a4a519a3f5f771cb974d9143f58a..bb0abf9bffb157e99a153444895a3c3ab3606b03 100644 (file)
@@ -40,8 +40,7 @@ struct ia_css_preview_settings {
        struct ia_css_pipe *acc_pipe;
 };
 
-#define IA_CSS_DEFAULT_PREVIEW_SETTINGS \
-(struct ia_css_preview_settings) { \
+#define IA_CSS_DEFAULT_PREVIEW_SETTINGS { \
        .copy_binary    = IA_CSS_BINARY_DEFAULT_SETTINGS, \
        .preview_binary = IA_CSS_BINARY_DEFAULT_SETTINGS, \
        .vf_pp_binary   = IA_CSS_BINARY_DEFAULT_SETTINGS, \
@@ -65,8 +64,7 @@ struct ia_css_capture_settings {
        unsigned int num_yuv_scaler;
 };
 
-#define IA_CSS_DEFAULT_CAPTURE_SETTINGS \
-(struct ia_css_capture_settings) { \
+#define IA_CSS_DEFAULT_CAPTURE_SETTINGS { \
        .copy_binary            = IA_CSS_BINARY_DEFAULT_SETTINGS, \
        .primary_binary         = {IA_CSS_BINARY_DEFAULT_SETTINGS}, \
        .pre_isp_binary         = IA_CSS_BINARY_DEFAULT_SETTINGS, \
@@ -91,8 +89,7 @@ struct ia_css_video_settings {
        unsigned int num_yuv_scaler;
 };
 
-#define IA_CSS_DEFAULT_VIDEO_SETTINGS \
-(struct ia_css_video_settings) { \
+#define IA_CSS_DEFAULT_VIDEO_SETTINGS { \
        .copy_binary    = IA_CSS_BINARY_DEFAULT_SETTINGS, \
        .video_binary   = IA_CSS_BINARY_DEFAULT_SETTINGS, \
        .vf_pp_binary   = IA_CSS_BINARY_DEFAULT_SETTINGS, \
@@ -108,8 +105,7 @@ struct ia_css_yuvpp_settings {
        unsigned int num_output;
 };
 
-#define IA_CSS_DEFAULT_YUVPP_SETTINGS \
-(struct ia_css_yuvpp_settings) { \
+#define IA_CSS_DEFAULT_YUVPP_SETTINGS { \
        .copy_binary    = IA_CSS_BINARY_DEFAULT_SETTINGS, \
 }
 
@@ -157,8 +153,7 @@ struct ia_css_pipe {
        unsigned int pipe_num;
 };
 
-#define IA_CSS_DEFAULT_PIPE \
-(struct ia_css_pipe) { \
+#define IA_CSS_DEFAULT_PIPE { \
        .config                 = DEFAULT_PIPE_CONFIG, \
        .info                   = DEFAULT_PIPE_INFO, \
        .mode                   = IA_CSS_PIPE_ID_ACC, /* (pipe_id) */ \
index 17b0941382bf25c0893c03d6cc98a880a11ae051..4affd21f9e3f047383e9e70f8a966159488f59ff 100644 (file)
@@ -149,8 +149,7 @@ struct ia_css_pipe_config {
 /**
  * Default settings for newly created pipe configurations.
  */
-#define DEFAULT_PIPE_CONFIG \
-(struct ia_css_pipe_config) { \
+#define DEFAULT_PIPE_CONFIG { \
        .mode                   = IA_CSS_PIPE_MODE_PREVIEW, \
        .isp_pipe_version       = 1, \
        .output_info            = {IA_CSS_BINARY_DEFAULT_FRAME_INFO}, \
@@ -203,8 +202,7 @@ struct ia_css_pipe_info {
 /**
  * Defaults for ia_css_pipe_info structs.
  */
-#define DEFAULT_PIPE_INFO \
-(struct ia_css_pipe_info) { \
+#define DEFAULT_PIPE_INFO {\
        .output_info            = {IA_CSS_BINARY_DEFAULT_FRAME_INFO}, \
        .vf_output_info         = {IA_CSS_BINARY_DEFAULT_FRAME_INFO}, \
        .raw_output_info        = IA_CSS_BINARY_DEFAULT_FRAME_INFO, \
index bac0a41add9222910f3310653e2a99e64d9386a1..6e34d401f9dfbc481986f7da2ecfaeb376b828cd 100644 (file)
@@ -392,8 +392,7 @@ struct ia_css_grid_info {
 };
 
 /* defaults for ia_css_grid_info structs */
-#define DEFAULT_GRID_INFO \
-(struct ia_css_grid_info) { \
+#define DEFAULT_GRID_INFO { \
        .dvs_grid       = DEFAULT_DVS_GRID_INFO, \
        .vamem_type     = IA_CSS_VAMEM_TYPE_1 \
 }
@@ -485,8 +484,7 @@ struct ia_css_capture_config {
 };
 
 /* default settings for ia_css_capture_config structs */
-#define DEFAULT_CAPTURE_CONFIG \
-(struct ia_css_capture_config) { \
+#define DEFAULT_CAPTURE_CONFIG { \
        .mode   = IA_CSS_CAPTURE_MODE_PRIMARY, \
 }
 
index c92f5836059bcebb50a24517cc4a1c697355553c..c2ec30b4abd41dbdd0319d6c245befe0c5c82894 100644 (file)
@@ -197,12 +197,11 @@ struct ia_css_dvs_stat_grid_info {
 
 /* DVS statistics generated by accelerator default grid info
  */
-#define DEFAULT_DVS_GRID_INFO \
-(union ia_css_dvs_grid_u) { \
-       .dvs_stat_grid_info = (struct ia_css_dvs_stat_grid_info) { \
+#define DEFAULT_DVS_GRID_INFO { \
+       .dvs_stat_grid_info = { \
                .fe_roi_cfg = { \
-                       [1] = (struct dvs_stat_public_dvs_level_fe_roi_cfg) { \
-                               .x_start = 4 \
+                       [1] = { \
+                           .x_start = 4 \
                        } \
                } \
        } \
index 560580023b295e223651c1fa19c74c3d411d1270..b44099dbdacd47b4c912ba5284503ac4cc99c61b 100644 (file)
@@ -144,8 +144,7 @@ struct ia_css_binary {
        struct ia_css_isp_param_css_segments  css_params;
 };
 
-#define IA_CSS_BINARY_DEFAULT_SETTINGS \
-(struct ia_css_binary) { \
+#define IA_CSS_BINARY_DEFAULT_SETTINGS { \
        .input_format           = ATOMISP_INPUT_FORMAT_YUV420_8_LEGACY, \
        .in_frame_info          = IA_CSS_BINARY_DEFAULT_FRAME_INFO, \
        .internal_frame_info    = IA_CSS_BINARY_DEFAULT_FRAME_INFO, \
index 1f4afd163ffa23a6e97cc5178ad266db5978f68a..18a7d18e197e48466d160a5ceba7040968ec0ed2 100644 (file)
@@ -57,8 +57,7 @@ struct ia_css_pipeline {
        u32 pipe_qos_config;
 };
 
-#define DEFAULT_PIPELINE \
-(struct ia_css_pipeline) { \
+#define DEFAULT_PIPELINE { \
        .pipe_id                = IA_CSS_PIPE_ID_PREVIEW, \
        .in_frame               = DEFAULT_FRAME, \
        .out_frame              = {DEFAULT_FRAME}, \
index 29207fe120a0794203afc14c9a3518b3bc6d5f6e..4b8e85bc21229d2e8592617f02be7f0ae3c195ce 100644 (file)
@@ -665,6 +665,8 @@ ERR:
        return err;
 }
 
+static const struct ia_css_frame ia_css_default_frame = DEFAULT_FRAME;
+
 static void pipeline_init_defaults(
     struct ia_css_pipeline *pipeline,
     enum ia_css_pipe_id pipe_id,
@@ -677,10 +679,15 @@ static void pipeline_init_defaults(
        pipeline->stages = NULL;
        pipeline->stop_requested = false;
        pipeline->current_stage = NULL;
-       pipeline->in_frame = DEFAULT_FRAME;
+
+       memcpy(&pipeline->in_frame, &ia_css_default_frame,
+              sizeof(ia_css_default_frame));
+
        for (i = 0; i < IA_CSS_PIPE_MAX_OUTPUT_STAGE; i++) {
-               pipeline->out_frame[i] = DEFAULT_FRAME;
-               pipeline->vf_frame[i] = DEFAULT_FRAME;
+               memcpy(&pipeline->out_frame[i], &ia_css_default_frame,
+                      sizeof(ia_css_default_frame));
+               memcpy(&pipeline->vf_frame[i], &ia_css_default_frame,
+                      sizeof(ia_css_default_frame));
        }
        pipeline->num_execs = -1;
        pipeline->acquire_isp_each_stage = true;
index c2e8d7e0b2331625ed60a850b9ac21e7f6f1445e..5fd1daa71bf9d5fc805cbe787371aaabc3f0e56d 100644 (file)
@@ -2233,10 +2233,17 @@ ERR:
        return err;
 }
 
+static const struct ia_css_pipe default_pipe = IA_CSS_DEFAULT_PIPE;
+static const struct ia_css_preview_settings preview = IA_CSS_DEFAULT_PREVIEW_SETTINGS;
+static const struct ia_css_capture_settings capture = IA_CSS_DEFAULT_CAPTURE_SETTINGS;
+static const struct ia_css_video_settings video = IA_CSS_DEFAULT_VIDEO_SETTINGS;
+static const struct ia_css_yuvpp_settings yuvpp = IA_CSS_DEFAULT_YUVPP_SETTINGS;
+
 static int
 init_pipe_defaults(enum ia_css_pipe_mode mode,
                   struct ia_css_pipe *pipe,
                   bool copy_pipe) {
+
        if (!pipe)
        {
                IA_CSS_ERROR("NULL pipe parameter");
@@ -2244,14 +2251,14 @@ init_pipe_defaults(enum ia_css_pipe_mode mode,
        }
 
        /* Initialize pipe to pre-defined defaults */
-       *pipe = IA_CSS_DEFAULT_PIPE;
+       memcpy(pipe, &default_pipe, sizeof(default_pipe));
 
        /* TODO: JB should not be needed, but temporary backward reference */
        switch (mode)
        {
        case IA_CSS_PIPE_MODE_PREVIEW:
                pipe->mode = IA_CSS_PIPE_ID_PREVIEW;
-               pipe->pipe_settings.preview = IA_CSS_DEFAULT_PREVIEW_SETTINGS;
+               memcpy(&pipe->pipe_settings.preview, &preview, sizeof(preview));
                break;
        case IA_CSS_PIPE_MODE_CAPTURE:
                if (copy_pipe) {
@@ -2259,11 +2266,11 @@ init_pipe_defaults(enum ia_css_pipe_mode mode,
                } else {
                        pipe->mode = IA_CSS_PIPE_ID_CAPTURE;
                }
-               pipe->pipe_settings.capture = IA_CSS_DEFAULT_CAPTURE_SETTINGS;
+               memcpy(&pipe->pipe_settings.capture, &capture, sizeof(capture));
                break;
        case IA_CSS_PIPE_MODE_VIDEO:
                pipe->mode = IA_CSS_PIPE_ID_VIDEO;
-               pipe->pipe_settings.video = IA_CSS_DEFAULT_VIDEO_SETTINGS;
+               memcpy(&pipe->pipe_settings.video, &video, sizeof(video));
                break;
        case IA_CSS_PIPE_MODE_ACC:
                pipe->mode = IA_CSS_PIPE_ID_ACC;
@@ -2273,7 +2280,7 @@ init_pipe_defaults(enum ia_css_pipe_mode mode,
                break;
        case IA_CSS_PIPE_MODE_YUVPP:
                pipe->mode = IA_CSS_PIPE_ID_YUVPP;
-               pipe->pipe_settings.yuvpp = IA_CSS_DEFAULT_YUVPP_SETTINGS;
+               memcpy(&pipe->pipe_settings.yuvpp, &yuvpp, sizeof(yuvpp));
                break;
        default:
                return -EINVAL;
@@ -8771,12 +8778,16 @@ sh_css_init_host_sp_control_vars(void) {
 }
 
 /*
-    * create the internal structures and fill in the configuration data
-    */
+ * create the internal structures and fill in the configuration data
+ */
+
+static const struct
+ia_css_pipe_config ia_css_pipe_default_config = DEFAULT_PIPE_CONFIG;
+
 void ia_css_pipe_config_defaults(struct ia_css_pipe_config *pipe_config)
 {
        ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "ia_css_pipe_config_defaults()\n");
-       *pipe_config = DEFAULT_PIPE_CONFIG;
+       memcpy(pipe_config, &ia_css_pipe_default_config, sizeof(*pipe_config));
 }
 
 void