| From 13116967c2bef46ab490f332fd6b29e036ac6b07 Mon Sep 17 00:00:00 2001 |
| From: Sasha Levin <sashal@kernel.org> |
| Date: Thu, 12 Feb 2026 20:41:40 +0800 |
| Subject: spi: wpcm-fiu: Fix potential NULL pointer dereference in |
| wpcm_fiu_probe() |
| MIME-Version: 1.0 |
| Content-Type: text/plain; charset=UTF-8 |
| Content-Transfer-Encoding: 8bit |
| |
| From: Felix Gu <ustc.gu@gmail.com> |
| |
| [ Upstream commit 888a0a802c467bbe34a42167bdf9d7331333440a ] |
| |
| 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: 9838c182471e ("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> |
| Signed-off-by: Sasha Levin <sashal@kernel.org> |
| --- |
| drivers/spi/spi-wpcm-fiu.c | 2 +- |
| 1 file changed, 1 insertion(+), 1 deletion(-) |
| |
| diff --git a/drivers/spi/spi-wpcm-fiu.c b/drivers/spi/spi-wpcm-fiu.c |
| index a9aee2a6c7dcb..c47b56f0933f1 100644 |
| --- a/drivers/spi/spi-wpcm-fiu.c |
| +++ b/drivers/spi/spi-wpcm-fiu.c |
| @@ -459,11 +459,11 @@ static int wpcm_fiu_probe(struct platform_device *pdev) |
| |
| res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "memory"); |
| fiu->memory = devm_ioremap_resource(dev, res); |
| - fiu->memory_size = min_t(size_t, resource_size(res), MAX_MEMORY_SIZE_TOTAL); |
| if (IS_ERR(fiu->memory)) |
| return dev_err_probe(dev, PTR_ERR(fiu->memory), |
| "Failed to map flash memory window\n"); |
| |
| + fiu->memory_size = min_t(size_t, resource_size(res), MAX_MEMORY_SIZE_TOTAL); |
| fiu->shm_regmap = syscon_regmap_lookup_by_phandle_optional(dev->of_node, "nuvoton,shm"); |
| |
| wpcm_fiu_hw_init(fiu); |
| -- |
| 2.51.0 |
| |