Skip to content

Commit 888a0a8

Browse files
outman119broonie
authored andcommitted
spi: wpcm-fiu: Fix potential NULL pointer dereference in wpcm_fiu_probe()
platform_get_resource_byname() can return NULL, which would cause a crash when passed the pointer to resource_size(). Move the fiu->memory_size assignment after the error check for devm_ioremap_resource() to prevent the potential NULL pointer dereference. Fixes: 9838c18 ("spi: wpcm-fiu: Add direct map support") Signed-off-by: Felix Gu <ustc.gu@gmail.com> Reviewed-by: J. Neuschäfer <j.ne@posteo.net> Link: https://patch.msgid.link/20260212-wpcm-v1-1-5b7c4f526aac@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 5af56f3 commit 888a0a8

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

drivers/spi/spi-wpcm-fiu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,11 @@ static int wpcm_fiu_probe(struct platform_device *pdev)
459459

460460
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "memory");
461461
fiu->memory = devm_ioremap_resource(dev, res);
462-
fiu->memory_size = min_t(size_t, resource_size(res), MAX_MEMORY_SIZE_TOTAL);
463462
if (IS_ERR(fiu->memory))
464463
return dev_err_probe(dev, PTR_ERR(fiu->memory),
465464
"Failed to map flash memory window\n");
466465

466+
fiu->memory_size = min_t(size_t, resource_size(res), MAX_MEMORY_SIZE_TOTAL);
467467
fiu->shm_regmap = syscon_regmap_lookup_by_phandle_optional(dev->of_node, "nuvoton,shm");
468468

469469
wpcm_fiu_hw_init(fiu);

0 commit comments

Comments
 (0)