Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp602864pxx; Wed, 28 Oct 2020 12:09:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0tCbFeMDT+gMtr3OX/MrT2z5Hlb4ppERVfv4l/OARza3n9wglAL4I9b0UGyhlUocLWHs5 X-Received: by 2002:a17:906:51dd:: with SMTP id v29mr561230ejk.69.1603912184242; Wed, 28 Oct 2020 12:09:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603912184; cv=none; d=google.com; s=arc-20160816; b=TagCNb8yt1s0k1CTY7D5TcmQY6FZ73HRRhWsQmxQDYq+GtTDskNwE4Bt/IOyYAOgFL H7na3T2v3MeEr+0My40SXH4QsOyB8G+qRM9El232q82tFYuaYOx4ASN2S5M7Pgsfu/3v rJpkeV4Kj62twgbaaAIcDyQcLtkFGXCwPPNI3M1p5hA6BKWsNd8eIxtkeclWemFnwS1J l7rPYYbH4ANyo+U+Guulr3U0EsHQjpFraEE/qZw70AtgIsgh9sJyLN7JviZX3A3HsmMg Pk904O4NXuA5aYRqXwQPSXPsCC8LUNkMrF0N4SdHZOYvz04LQPjARgKu5EB4M/UtQePZ FP8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Zf6D3IGpLSSeZJf+Wo1AI03AxSc+8LEvkUK1IMelHwI=; b=RXireaZScZkBRHq41qyHkRS2x/P7trqEmKz4SRiYhXVvM3RGG1TFGWuD3aQQ5XnuPc 0ldD7bIcAZeeIHXg0NDCLb4yMqczVHhoxtSwz7HYoEixfKHTECNen9DjJiNwjEjSlDLs 3LjBvNCmYybrK7osZo1QNXD19Hqi7nNhm+L27CfXQFFwc72rurc8kwLZZrrkIEUlP2sp mJcKSxK/29xkwTBDsDu8nUQ3aaeTrVX3We7WX6vkENIx5GkeH3xxUtef+OFkFUG94r03 RyMYgVydZHd20FitSpe0Ow3FgzlPpe51psGmqD46sd9wivUyaljG6/FBOU5ETmWAhmq3 MSbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xkGhwyXQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id co4si129868edb.461.2020.10.28.12.09.21; Wed, 28 Oct 2020 12:09:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xkGhwyXQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1826310AbgJ0SSw (ORCPT + 99 others); Tue, 27 Oct 2020 14:18:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:52586 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754104AbgJ0OES (ORCPT ); Tue, 27 Oct 2020 10:04:18 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 34DC822264; Tue, 27 Oct 2020 14:04:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807457; bh=oj5HLCgTap0UE8B9NbqNauRQX8CuLpo1hR0Pot0m9Jg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xkGhwyXQyHnDz5X6HiVXXwE2RMMj0deH/tZ7tLxz3Jxkp2M6f1YlDhV7bT/TE4e/E m0/K2XXveUCZIhuZPlrJS5huuLW5EiGNIqFf/vMlHRwbCiA5DirPJQz2x6/6hxsHzf kuw2vhPLVIDJQbxQLHrvZ4ChBEsLzqU1cfJ/1yX4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann , Nathan Chancellor , Miquel Raynal , Sasha Levin Subject: [PATCH 4.9 060/139] mtd: lpddr: fix excessive stack usage with clang Date: Tue, 27 Oct 2020 14:49:14 +0100 Message-Id: <20201027134904.977602513@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134902.130312227@linuxfoundation.org> References: <20201027134902.130312227@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnd Bergmann [ Upstream commit 3e1b6469f8324bee5927b063e2aca30d3e56b907 ] 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 Reviewed-by: Nathan Chancellor Acked-by: Miquel Raynal Signed-off-by: Miquel Raynal Link: https://lore.kernel.org/linux-mtd/20200505140136.263461-1-arnd@arndb.de Signed-off-by: Sasha Levin --- drivers/mtd/lpddr/lpddr2_nvm.c | 35 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/drivers/mtd/lpddr/lpddr2_nvm.c b/drivers/mtd/lpddr/lpddr2_nvm.c index 2342277c9bcb0..5e36366d9b36d 100644 --- a/drivers/mtd/lpddr/lpddr2_nvm.c +++ b/drivers/mtd/lpddr/lpddr2_nvm.c @@ -408,6 +408,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 */ @@ -448,6 +459,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); @@ -459,22 +471,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)) { -- 2.25.1