Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp186933pxx; Wed, 28 Oct 2020 02:05:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPH3xZDOAQ4WSQm/oiNlxJtPTekqY+K8YXQMxQy1AlcWkOZIv/fMsp4hDFZZdrCB0+Q6ot X-Received: by 2002:a17:906:b084:: with SMTP id x4mr6790773ejy.374.1603875957765; Wed, 28 Oct 2020 02:05:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603875957; cv=none; d=google.com; s=arc-20160816; b=im0MOFMKJZjUmi2e6wC7L39wdaBth+j6NXLthu0YOep7/74HhBqzWEYNpkO5HeMjBi RIxubijSMRLrmd1QtrDmOg1W3iFYVZ/lNkWlt8wMGoot7JeLskUj9E3FRybEG9zmT0QO NmKc/+agX1ohZnaCcv0SLt7gHdAyoaY/RJxg6SmuRneoe5S4cwQr7hIOZw7iuQai8XWO FkITTpj/VJ//JQbMVkRcaDvf7nXQNI1HMwel5FxLm6AEhjzShA+LdCt/3emGSUPeTOk6 Bf4+rOJxdAO6fbH5wNiJbhnJb6XCKyfc8iX20IxumohTSNCiJ15Z+3lzu9FWAI/UTIuu VyjA== 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=0kTF1THht7oBIi3LFqPwPOcZoizFBt0DGQUVHoDMQF0DdVIzsSt4QEmMZQkCD9ugxn vIwUl6LWAMpu9gAdruZvMpmrntt7gx2dxcVFQU5O3cJJS2yyx+7bhaoTBeB1E7crtpyJ tpQAc9wpCTEcqdz+TgZhOhvtjxAHfM4ribOspLJCpWt5zd8jiGYOPTS6YUJ5ktrHCxcH 7oE8dh3IQohS25vvJDvquU+D65g4PaG6L2k4G6DK0PjuouoOejrOycBo71JxX3Atrwmx Swyht6Vf3zF+7BEjULaDQ95IQoW7v8hWuhVD1OWQo+2y/k1yjVCpYv4s8Vu51XrS4QyM vJBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=P3peQ0gk; 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 s16si2897729edy.300.2020.10.28.02.05.36; Wed, 28 Oct 2020 02:05:57 -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=P3peQ0gk; 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 S1757069AbgJ0OQG (ORCPT + 99 others); Tue, 27 Oct 2020 10:16:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:60920 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756205AbgJ0OMA (ORCPT ); Tue, 27 Oct 2020 10:12:00 -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 5A51B223AB; Tue, 27 Oct 2020 14:11:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807917; bh=oj5HLCgTap0UE8B9NbqNauRQX8CuLpo1hR0Pot0m9Jg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P3peQ0gkQfRFxce51n28KAZX/B7+L3JgJ7pt/MZUP5EQLDwVtcomjCi4y36pQVU3P ccyOco3rdcC+ZeNF3J/aZ+AUrjkhXRdw5+QrIbst2gSu+LZ7jzzGDuDqhlCf4k3xpa n5ngiggnfp9ED6fHVHPnbKWzFn4RybAPUcKrAxRw= 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.14 089/191] mtd: lpddr: fix excessive stack usage with clang Date: Tue, 27 Oct 2020 14:49:04 +0100 Message-Id: <20201027134913.976351668@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134909.701581493@linuxfoundation.org> References: <20201027134909.701581493@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