From patchwork Fri May 29 20:00:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11579543 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 84A8492A for ; Fri, 29 May 2020 20:01:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 75370214D8 for ; Fri, 29 May 2020 20:01:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728173AbgE2UBA (ORCPT ); Fri, 29 May 2020 16:01:00 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:58941 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728099AbgE2UAx (ORCPT ); Fri, 29 May 2020 16:00:53 -0400 Received: from threadripper.lan ([149.172.98.151]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.145]) with ESMTPA (Nemesis) id 1M3DBb-1jhmNw1fMT-003eXf; Fri, 29 May 2020 22:00:41 +0200 From: Arnd Bergmann To: Mauro Carvalho Chehab Cc: Sakari Ailus , linux-media@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, Arnd Bergmann Subject: [PATCH 5/9] staging: media: atomisp: fix stack overflow in init_pipe_defaults() Date: Fri, 29 May 2020 22:00:27 +0200 Message-Id: <20200529200031.4117841-5-arnd@arndb.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200529200031.4117841-1-arnd@arndb.de> References: <20200529200031.4117841-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:Wk4aB6MB00HUMVI+PYXcoWnTJNhnYs2ponKtL4wBtBdX22cXjgZ cvDEYQEE0jdp0PzAw1NnhAANObZJYZx66+ho+dnW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el.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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. Fixes: 6dc9a2568f84 ("media: atomisp: convert default struct values to use compound-literals with designated initializers") Signed-off-by: Arnd Bergmann Reviewed-by: Nathan Chancellor --- drivers/staging/media/atomisp/pci/sh_css.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/sh_css.c b/drivers/staging/media/atomisp/pci/sh_css.c index e91c6029c651..1e8b9d637116 100644 --- a/drivers/staging/media/atomisp/pci/sh_css.c +++ b/drivers/staging/media/atomisp/pci/sh_css.c @@ -2264,6 +2264,12 @@ static enum ia_css_err init_pipe_defaults(enum ia_css_pipe_mode mode, struct ia_css_pipe *pipe, bool copy_pipe) { + 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; + if (!pipe) { IA_CSS_ERROR("NULL pipe parameter"); @@ -2271,14 +2277,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) { @@ -2286,11 +2292,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; @@ -2300,7 +2306,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 IA_CSS_ERR_INVALID_ARGUMENTS;