From patchwork Tue May 5 14:01:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 186200 Delivered-To: patch@linaro.org Received: by 2002:a92:8d81:0:0:0:0:0 with SMTP id w1csp1165186ill; Tue, 5 May 2020 07:02:08 -0700 (PDT) X-Google-Smtp-Source: APiQypJy6cT+TgTeObZIbj2oqodsYow2NZ35ESRbeeD7qpLRcxVfAa7Q0/KoddHphp7IDFYCuXFB X-Received: by 2002:a62:7e8e:: with SMTP id z136mr3150033pfc.151.1588687328690; Tue, 05 May 2020 07:02:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588687328; cv=none; d=google.com; s=arc-20160816; b=bQ1UR18zC2EAmIM3Y25MLQGfIcSXtPe7+IRWKvTBvxX5zuhhmGE8lWMuZ5MnYa1KGL PGSITm18BzmpqXXGh0UvpVClvMyacTwBGQ3U6jjSQbiIAgRsCET0hnR0aGqraNEmqMjp 0cKC9/n2j3TSL6Gzoy53JG36BAdwJ+0gEbalN8IzmZe4WR2YMQGvwxLPPJXaAYnGr9xJ K5jGsSCh3ITPXlYXqw7cf+XdXvWXBmq1hNt/V0KqGXKVFSJVbkyU2xrtyAe2i8V0oyiV jxN1hz6UjmToaK26VPsZXdEF4oe3OK4pHa7SqXjDwWRlP+lcRtvCMnXEYI8CGZBSNQkZ iDuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:message-id:date:subject:to:from :dkim-signature; bh=vxnd+L2MuIpg1qgZB+NXM49U8VEtqKJlegRoAQcTuIc=; b=XBlg4+pAOdnICHy4cieIrM80DaXsIUc98vhuAln9S2MAwjMko/2blN1JgcyX5YjmHj 5R7LW6g4ww6/hq/utpwJNB4Fj4H0R4zOEOonQ3P1tOfMv1spV4t9gMjD4FSMyxaXFJBg q0BQ0n9l2D2kqCjiFxPCqdikScysW8mkDtqDhCjgdsBtIgpkn5F0QmbeRuQKXWxQrn62 DD59RnKUjYy5HokS1j/luD0FJQ5r/WuU1AA5Qyw7VuynZ6SW65HVXqMmA1cfN/Y4CEYB SkrA+vASkFEx2RWh1AnechgtcYfb2ewynOgLw7DOVA56ZleEQv+ZuoAHqkEt8qN0ZBhe 73fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=kJKOq9Ue; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org" Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id z11si1397959pln.6.2020.05.05.07.02.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 07:02:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=kJKOq9Ue; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=vxnd+L2MuIpg1qgZB+NXM49U8VEtqKJlegRoAQcTuIc=; b=kJKOq9Ue+LnKZU svcSFH4WMvVJoFoOv+xzCeXbUo9GtP6dNZV3sEZ1FuNgnuuPJ4yoT2WhNoZHQC7fdfruTYG3f6jhU 4agmxjzrJPAkgQ27wbIdu6xPurVn09Ia+wTc3eY0zlRm7UG28tB57Qgy24GB1PuLmA5xVMgmoXPGv nMjCPzfynA9qwiVzeqXOB4sCOp3bjfeqEy0mY3wrrkauvJWnmhjy0RrPsRgHUm//ChGk8TKCok3bE 3Gy6jX7qxFMwDaGY3jMJLNrLPEvqIVWwUm90eWjxF/4SlAThOlkYgnvC/tJiZDf1lfdbfss2oACLq xGErUyMgcZRcC+udz22A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jVy8z-0001g3-4N; Tue, 05 May 2020 14:01:57 +0000 Received: from mout.kundenserver.de ([212.227.17.24]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jVy8v-0001eT-SJ for linux-mtd@lists.infradead.org; Tue, 05 May 2020 14:01:55 +0000 Received: from localhost.localdomain ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.145]) with ESMTPA (Nemesis) id 1MuDsZ-1jHTUl1QxZ-00uWRX; Tue, 05 May 2020 16:01:38 +0200 From: Arnd Bergmann To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Vincenzo Aliberti , Brian Norris Subject: [PATCH] mtd: lpddr: fix excessive stack usage with clang Date: Tue, 5 May 2020 16:01:16 +0200 Message-Id: <20200505140136.263461-1-arnd@arndb.de> X-Mailer: git-send-email 2.26.0 MIME-Version: 1.0 X-Provags-ID: V03:K1:iaIPMXhwT+Ozi6/EpaDCzPQ6tOZ0YRFJlPmWlpkMXIOGy4GtadE 2Z+LvOLt48OWBL8tlphxtG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+KV3yWk= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200505_070154_211081_28F71512 X-CRM114-Status: GOOD ( 15.19 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [212.227.17.24 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [212.227.17.24 listed in wl.mailspike.net] 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Fontana , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Arnd Bergmann , clang-built-linux@googlegroups.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org Building lpddr2_nvm with clang can result in a giant stack usage in one function: drivers/mtd/lpddr/lpddr2_nvm.c:399:12: error: stack frame size of 1144 bytes in function 'lpddr2_nvm_probe' [-Werror,-Wframe-larger-than=] The problem is that clang decides to build a copy of the mtd_info structure on the stack and then do a memcpy() into the actual version. It shouldn't really do it that way, but it's not strictly a bug either. As a workaround, use a static const version of the structure to assign most of the members upfront and then only set the few members that require runtime knowledge at probe time. Fixes: 96ba9dd65788 ("mtd: lpddr: add driver for LPDDR2-NVM PCM memories") Signed-off-by: Arnd Bergmann --- drivers/mtd/lpddr/lpddr2_nvm.c | 35 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) -- 2.26.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ Reviewed-by: Nathan Chancellor Acked-by: Miquel Raynal diff --git a/drivers/mtd/lpddr/lpddr2_nvm.c b/drivers/mtd/lpddr/lpddr2_nvm.c index 0f1547f09d08..72f5c7b30079 100644 --- a/drivers/mtd/lpddr/lpddr2_nvm.c +++ b/drivers/mtd/lpddr/lpddr2_nvm.c @@ -393,6 +393,17 @@ static int lpddr2_nvm_lock(struct mtd_info *mtd, loff_t start_add, return lpddr2_nvm_do_block_op(mtd, start_add, len, LPDDR2_NVM_LOCK); } +static const struct mtd_info lpddr2_nvm_mtd_info = { + .type = MTD_RAM, + .writesize = 1, + .flags = (MTD_CAP_NVRAM | MTD_POWERUP_LOCK), + ._read = lpddr2_nvm_read, + ._write = lpddr2_nvm_write, + ._erase = lpddr2_nvm_erase, + ._unlock = lpddr2_nvm_unlock, + ._lock = lpddr2_nvm_lock, +}; + /* * lpddr2_nvm driver probe method */ @@ -433,6 +444,7 @@ static int lpddr2_nvm_probe(struct platform_device *pdev) .pfow_base = OW_BASE_ADDRESS, .fldrv_priv = pcm_data, }; + if (IS_ERR(map->virt)) return PTR_ERR(map->virt); @@ -444,22 +456,13 @@ static int lpddr2_nvm_probe(struct platform_device *pdev) return PTR_ERR(pcm_data->ctl_regs); /* Populate mtd_info data structure */ - *mtd = (struct mtd_info) { - .dev = { .parent = &pdev->dev }, - .name = pdev->dev.init_name, - .type = MTD_RAM, - .priv = map, - .size = resource_size(add_range), - .erasesize = ERASE_BLOCKSIZE * pcm_data->bus_width, - .writesize = 1, - .writebufsize = WRITE_BUFFSIZE * pcm_data->bus_width, - .flags = (MTD_CAP_NVRAM | MTD_POWERUP_LOCK), - ._read = lpddr2_nvm_read, - ._write = lpddr2_nvm_write, - ._erase = lpddr2_nvm_erase, - ._unlock = lpddr2_nvm_unlock, - ._lock = lpddr2_nvm_lock, - }; + *mtd = lpddr2_nvm_mtd_info; + mtd->dev.parent = &pdev->dev; + mtd->name = pdev->dev.init_name; + mtd->priv = map; + mtd->size = resource_size(add_range); + mtd->erasesize = ERASE_BLOCKSIZE * pcm_data->bus_width; + mtd->writebufsize = WRITE_BUFFSIZE * pcm_data->bus_width; /* Verify the presence of the device looking for PFOW string */ if (!lpddr2_nvm_pfow_present(map)) {