Skip to content

Commit 3e1b646

Browse files
arndbmiquelraynal
authored andcommitted
mtd: lpddr: fix excessive stack usage with clang
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: 96ba9dd ("mtd: lpddr: add driver for LPDDR2-NVM PCM memories") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Reviewed-by: Nathan Chancellor <natechancellor@gmail.com> Acked-by: Miquel Raynal <miquel.raynal@bootlin.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/20200505140136.263461-1-arnd@arndb.de
1 parent 1d0e5eb commit 3e1b646

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

drivers/mtd/lpddr/lpddr2_nvm.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,17 @@ static int lpddr2_nvm_lock(struct mtd_info *mtd, loff_t start_add,
393393
return lpddr2_nvm_do_block_op(mtd, start_add, len, LPDDR2_NVM_LOCK);
394394
}
395395

396+
static const struct mtd_info lpddr2_nvm_mtd_info = {
397+
.type = MTD_RAM,
398+
.writesize = 1,
399+
.flags = (MTD_CAP_NVRAM | MTD_POWERUP_LOCK),
400+
._read = lpddr2_nvm_read,
401+
._write = lpddr2_nvm_write,
402+
._erase = lpddr2_nvm_erase,
403+
._unlock = lpddr2_nvm_unlock,
404+
._lock = lpddr2_nvm_lock,
405+
};
406+
396407
/*
397408
* lpddr2_nvm driver probe method
398409
*/
@@ -433,6 +444,7 @@ static int lpddr2_nvm_probe(struct platform_device *pdev)
433444
.pfow_base = OW_BASE_ADDRESS,
434445
.fldrv_priv = pcm_data,
435446
};
447+
436448
if (IS_ERR(map->virt))
437449
return PTR_ERR(map->virt);
438450

@@ -444,22 +456,13 @@ static int lpddr2_nvm_probe(struct platform_device *pdev)
444456
return PTR_ERR(pcm_data->ctl_regs);
445457

446458
/* Populate mtd_info data structure */
447-
*mtd = (struct mtd_info) {
448-
.dev = { .parent = &pdev->dev },
449-
.name = pdev->dev.init_name,
450-
.type = MTD_RAM,
451-
.priv = map,
452-
.size = resource_size(add_range),
453-
.erasesize = ERASE_BLOCKSIZE * pcm_data->bus_width,
454-
.writesize = 1,
455-
.writebufsize = WRITE_BUFFSIZE * pcm_data->bus_width,
456-
.flags = (MTD_CAP_NVRAM | MTD_POWERUP_LOCK),
457-
._read = lpddr2_nvm_read,
458-
._write = lpddr2_nvm_write,
459-
._erase = lpddr2_nvm_erase,
460-
._unlock = lpddr2_nvm_unlock,
461-
._lock = lpddr2_nvm_lock,
462-
};
459+
*mtd = lpddr2_nvm_mtd_info;
460+
mtd->dev.parent = &pdev->dev;
461+
mtd->name = pdev->dev.init_name;
462+
mtd->priv = map;
463+
mtd->size = resource_size(add_range);
464+
mtd->erasesize = ERASE_BLOCKSIZE * pcm_data->bus_width;
465+
mtd->writebufsize = WRITE_BUFFSIZE * pcm_data->bus_width;
463466

464467
/* Verify the presence of the device looking for PFOW string */
465468
if (!lpddr2_nvm_pfow_present(map)) {

0 commit comments

Comments
 (0)