From patchwork Mon Mar 4 20:28:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 159607 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp4180256jad; Mon, 4 Mar 2019 12:29:10 -0800 (PST) X-Google-Smtp-Source: APXvYqzDl8Nx/9FQVKWL5b5vQdJmMnQ6pNlfs3684jQbcv7/pePSSaQFwXezhpiSpucO9UTW0aH0 X-Received: by 2002:a17:902:112c:: with SMTP id d41mr22223241pla.177.1551731350267; Mon, 04 Mar 2019 12:29:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551731350; cv=none; d=google.com; s=arc-20160816; b=iMzedeOTo5l16QNuOjm5PMBeGbJip8gJZ2HgKnkAw+L1V8WzGJytxfRvQ1ocOq/eYT wWPD3V7rwKyGDKq+dJYr9/br+lw5CzBOqXEEzBUntme5i69wvGBpwbu6+r0PCMCnbIQk CrmQJKlilOmgVWGY3FfcDqKlCNfkNfoY0QR/Ymq/ToAg+6xIgahMh2oXdqqisGo1x2mm 8V56NfOsl9/tOPW3Gy+kuloOtuUNyE8ofhakpV/4ARsL95ZHqbc1IPxPP2r8DvZSq53r hYqj6vrlFP1QAvO3lx1CJUn3RhUX1bfKSna0uxJZfXEAZ71XR/l+ydsJarve58WyTjII +lBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=1WvXKWpcfbHi8f7zGt5RSgqUKNQdtsiu2e70SIC19PM=; b=lCj4zhpFvpS+uwi1Mup6bCVk3YcI6fGRDg+u33eSdNQOIr4q5oFGrMRtKltZyNJnwz 6zkXtuTviKLgL9EpjgglRfOhpgi076Wpo0Lt9htB+gieOpgCj2X9/rQIFIkbAJjeC0/T +IMEujkbmwP3WyuJppvB/AU91ak+McHTIs8i/yOBPoqCyT7ixhxY2dYA0VCL9X9twnAj gqYDzYtFcYearFlD13ihZctRXn3ZK7otWl2DwejAlVruU5Ff2mliYoiwtMNlOjQUj3UB WyayqShBucNJs5pB8CBcIVJWqiudDgIDZdPyAOLC8nL2RCLR/6UgSUULodBkKpjw//d4 A6Cw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j3si5813129pfa.194.2019.03.04.12.29.09; Mon, 04 Mar 2019 12:29:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726540AbfCDU3I (ORCPT + 31 others); Mon, 4 Mar 2019 15:29:08 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:49111 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726054AbfCDU3I (ORCPT ); Mon, 4 Mar 2019 15:29:08 -0500 Received: from wuerfel.lan ([109.192.41.194]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.145]) with ESMTPA (Nemesis) id 1N49Qd-1h9OeE0Wgr-0103hE; Mon, 04 Mar 2019 21:28:55 +0100 From: Arnd Bergmann To: Sakari Ailus , Mauro Carvalho Chehab , Greg Kroah-Hartman Cc: Arnd Bergmann , Yong Zhi , Tian Shu Qiu , Bingbu Cao , linux-media@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH] media: staging/intel-ipu3-v4l: reduce kernel stack usage Date: Mon, 4 Mar 2019 21:28:42 +0100 Message-Id: <20190304202852.1833000-1-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 MIME-Version: 1.0 X-Provags-ID: V03:K1:DTlj0/rVijoM9kK6t0PrvaRFK2022Oky9Kc/yOJfbcKOO9qAWIJ X8C/zebAP/+NBSYcVXuNXlmae2mHew3qkPURCnZeC17ZscKN27HSdRRRksNIVpfySKfu0wZ BI+JHfA7KjS00ks99FDi+bqnLT8nIWDdmlCwTZlgFs33iLWsu+5uNNg8DAp7TdLhU8a7rod lUS/F9AlEZhU2fTJRYbGA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:FJPIl4G3zGQ=:Pn7LpDCY6fvYgCixLCyvmj RxO66Kb8+ts9jJDvAAZ2IG6LveFAbawBj8H8TyOWbzlyC7BNFFXiCedHtq9ZW4fzKQY1c83iu JR3q4UcljTeiHz9ae/UjKTqaPdl4wyBXsCS5yd+hWMZL96B67F0B3wjS0i8xbyaegI82AMMZX UozwxBg5BptCFA3K5cKUaGpiz7e41/6O+B0OPm+xQTxFW4Uia3Ti8u8Oj/ZISNaSsFjjkZXkA ZjukGgWkAZ2Feh1ZYz5fCe3GSAHYBGgAZbFzX8R1zdXMLr3/POxZIq1wQm3eS7KaaMeQ9/5mD X7FCDV0+vai7Mp3Dq6I7AwaF2Hy4r64Mw2izZ6bpu/4W5HU1erHM636ZjV3CksMM0aJiDB12B lglPa6UmlRD+/7QAkF/JmwmMPAP09sTCbmt/xDRug4FSKCrdzF+Kkql8lkKoIM6eVHFmKhJxO 6y3uW1OxOghYJBZW9k5s4kE8qfaUetuaI0UPyoky0KZiHOs6sqRtGwnFVgKAR/GXKJCJuuzsk 88ipPtuZ7WhXAmJD0uVraRUrVW2RWhUpStdTjGEiSpUoP+TYjzSAu541PtbDFBV+LBAk5AHDo KxrlSbXHqnuoSsC+Ji3G8Qkq4vTVpJ0e9tUGHAZG1qWvENCwWVKhmVpigrY8J5vZ4g3rI7t34 mC/QRm6sRTiCrdU96OKAJH2I3w7+SNH6mNcR7PEhB6XgxgPxRxR5pId+vPuFe4DwOOi87Yyvb hd0yovPsshy1rnsvlbPtINJf79DykpdJIdpEew== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The v4l2_pix_format_mplane structure is too large to be put on the kernel stack, as we can see in 32-bit builds: drivers/staging/media/ipu3/ipu3-v4l2.c: In function 'imgu_fmt': drivers/staging/media/ipu3/ipu3-v4l2.c:753:1: error: the frame size of 1028 bytes is larger than 1024 bytes [-Werror=frame-larger-than=] By dynamically allocating this array, the stack usage goes down to an acceptable 272 bytes for the same x86-32 configuration. Fixes: a0ca1627b450 ("media: staging/intel-ipu3: Add v4l2 driver based on media framework") Signed-off-by: Arnd Bergmann --- drivers/staging/media/ipu3/ipu3-v4l2.c | 40 ++++++++++++++++---------- 1 file changed, 25 insertions(+), 15 deletions(-) -- 2.20.0 diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c index 9c0352b193a7..c34b433539c4 100644 --- a/drivers/staging/media/ipu3/ipu3-v4l2.c +++ b/drivers/staging/media/ipu3/ipu3-v4l2.c @@ -664,12 +664,11 @@ static int imgu_fmt(struct imgu_device *imgu, unsigned int pipe, int node, struct v4l2_format *f, bool try) { struct device *dev = &imgu->pci_dev->dev; - struct v4l2_pix_format_mplane try_fmts[IPU3_CSS_QUEUES]; struct v4l2_pix_format_mplane *fmts[IPU3_CSS_QUEUES] = { NULL }; struct v4l2_rect *rects[IPU3_CSS_RECTS] = { NULL }; struct v4l2_mbus_framefmt pad_fmt; unsigned int i, css_q; - int r; + int ret; struct imgu_css_pipe *css_pipe = &imgu->css.pipes[pipe]; struct imgu_media_pipe *imgu_pipe = &imgu->imgu_pipe[pipe]; struct imgu_v4l2_subdev *imgu_sd = &imgu_pipe->imgu_sd; @@ -698,9 +697,13 @@ static int imgu_fmt(struct imgu_device *imgu, unsigned int pipe, int node, continue; if (try) { - try_fmts[i] = - imgu_pipe->nodes[inode].vdev_fmt.fmt.pix_mp; - fmts[i] = &try_fmts[i]; + fmts[i] = kmemdup(&imgu_pipe->nodes[inode].vdev_fmt.fmt.pix_mp, + sizeof(struct v4l2_pix_format_mplane), + GFP_KERNEL); + if (!fmts[i]) { + ret = -ENOMEM; + goto out; + } } else { fmts[i] = &imgu_pipe->nodes[inode].vdev_fmt.fmt.pix_mp; } @@ -730,26 +733,33 @@ static int imgu_fmt(struct imgu_device *imgu, unsigned int pipe, int node, * before we return success from this function, so set it here. */ css_q = imgu_node_to_queue(node); - if (fmts[css_q]) - *fmts[css_q] = f->fmt.pix_mp; - else - return -EINVAL; + if (!fmts[css_q]) { + ret = -EINVAL; + goto out; + } + *fmts[css_q] = f->fmt.pix_mp; if (try) - r = imgu_css_fmt_try(&imgu->css, fmts, rects, pipe); + ret = imgu_css_fmt_try(&imgu->css, fmts, rects, pipe); else - r = imgu_css_fmt_set(&imgu->css, fmts, rects, pipe); + ret = imgu_css_fmt_set(&imgu->css, fmts, rects, pipe); - /* r is the binary number in the firmware blob */ - if (r < 0) - return r; + /* ret is the binary number in the firmware blob */ + if (ret < 0) + goto out; if (try) f->fmt.pix_mp = *fmts[css_q]; else f->fmt = imgu_pipe->nodes[node].vdev_fmt.fmt; - return 0; +out: + if (try) { + for (i = 0; i < IPU3_CSS_QUEUES; i++) + kfree(fmts[i]); + } + + return ret; } static int imgu_try_fmt(struct file *file, void *fh, struct v4l2_format *f)