Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp224214pxx; Wed, 28 Oct 2020 03:20:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQSdxPIwEalbODyw9DgwygSq5xzQqH331ve3xVVoPGd2aN5OgJyfLlbYtkGp/BByetSkju X-Received: by 2002:a17:906:3397:: with SMTP id v23mr6728207eja.212.1603880400020; Wed, 28 Oct 2020 03:20:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603880400; cv=none; d=google.com; s=arc-20160816; b=uLhwv3ZHo16rOwLWTcQud69EXM7bydXOMa1AYAKm6gEYx8251gdJ//BH1kRZgXgZAx 8F06HfMBiboMJ6I48Y8JNWArrjfvqo/BqderSq1BKr8pOoR82k80NJBGwGBQ9E86Pr4c oJ2kbEN0Lb7YcOUZHoyHylrx4ahjbMmFi6ZTfSTzGAIiAJdaiMJDRPNcOggDj7PzkXd3 vkHZk63kooV+syQAoOY24Tc5HDTqoMY5lVV/laZOjGLiQEHZJruxZTaydArPDNogpLdN Qd3okHM++YBYU4E4MY65YdM4tVE03JNKsJycderqVMX2TO+eoZwyju7QTQVRK97BTa9z Ff/g== 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=HgUs0eAr62/uASwpwXTMBtl5VO6AXIA1bGXmV3XSxZw=; b=InSMyrj+PpcybLGIFXgpZnjVz/wo9h30WMLDUzUoh7bhjTNlnf7+UMW+kOX1zT0p2z cq6HrbfK2tPxEuhzSUGe8v9AP2br0Li12hNFgp646ZUI3UWHzdpAGMbffa5n9XFmQqhP jlFhwAr3PKRFkGkAzDCTkScLZe6kjVx2KtU9W3x850QPk71bvS8AVW283XWHicuNmtAl e6+TDv5XN+SPsr1GRIKiz/mvzHUo2KAevEm+Aa96ovukxbVeDq4EOlBL8qhKRLkBE8QS yExLTfow+OFTP7BP4S7I3ejVkdk4Dpw1VgazjU1kjjBxcDMgbJRut2A8Ugp4ZKUG7Dle tigg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NmqhZhCu; 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 q18si2524555edb.466.2020.10.28.03.19.38; Wed, 28 Oct 2020 03:20:00 -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=NmqhZhCu; 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 S1761057AbgJ0Ohs (ORCPT + 99 others); Tue, 27 Oct 2020 10:37:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:36754 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761026AbgJ0Ohk (ORCPT ); Tue, 27 Oct 2020 10:37:40 -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 BB2BA206B2; Tue, 27 Oct 2020 14:37:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809459; bh=2pAFCnSnHthtt5kihnUSeHNxZ0KWtqapg7ske1jDZF4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NmqhZhCuUD9BRxVCV4iaWwFlmPKOinv9p40TI7L4ZtDTxJ4jt4MvTk1fd6ymwjBhV 1xMfRt7yCyiVDPSOptEEhfeO4k2RzMikY1dJV8atVzoEOju95cMmqLfxznc5tqHv59 CQKqyvLYmzUx85vYZ1tvEypHkQKgWSOADFoZjz4c= 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 5.4 203/408] mtd: lpddr: fix excessive stack usage with clang Date: Tue, 27 Oct 2020 14:52:21 +0100 Message-Id: <20201027135504.515646261@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@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 0f1547f09d08b..72f5c7b300790 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)) { -- 2.25.1