public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] spi: wpcm-fiu: Fix potential NULL pointer dereference in wpcm_fiu_probe()
@ 2026-02-12 12:41 Felix Gu
  2026-02-13  8:54 ` Markus Elfring
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Felix Gu @ 2026-02-12 12:41 UTC (permalink / raw)
  To: Jonathan Neuschäfer, Mark Brown
  Cc: openbmc, linux-spi, linux-kernel, Felix Gu

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>
---
 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 0e3ee5516587..0e26ff178505 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);

---
base-commit: 9152bc8cebcb14dc16b03ec81f2377ee8ce12268
change-id: 20260212-wpcm-d86f76761645

Best regards,
-- 
Felix Gu <ustc.gu@gmail.com>


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] spi: wpcm-fiu: Fix potential NULL pointer dereference in wpcm_fiu_probe()
  2026-02-12 12:41 [PATCH] spi: wpcm-fiu: Fix potential NULL pointer dereference in wpcm_fiu_probe() Felix Gu
@ 2026-02-13  8:54 ` Markus Elfring
  2026-02-13 11:00 ` J. Neuschäfer
  2026-02-16 18:08 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2026-02-13  8:54 UTC (permalink / raw)
  To: Felix Gu, linux-spi, openbmc, Jonathan Neuschäfer,
	Mark Brown
  Cc: LKML, kernel-janitors

> 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.

Were any source code analysis tools involved here?

Regards,
Markus

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] spi: wpcm-fiu: Fix potential NULL pointer dereference in wpcm_fiu_probe()
  2026-02-12 12:41 [PATCH] spi: wpcm-fiu: Fix potential NULL pointer dereference in wpcm_fiu_probe() Felix Gu
  2026-02-13  8:54 ` Markus Elfring
@ 2026-02-13 11:00 ` J. Neuschäfer
  2026-02-16 18:08 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: J. Neuschäfer @ 2026-02-13 11:00 UTC (permalink / raw)
  To: Felix Gu; +Cc: Mark Brown, openbmc, linux-spi, linux-kernel

On Thu, Feb 12, 2026 at 08:41:40PM +0800, Felix Gu wrote:
> 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>
> ---

Seems reasonable.

Reviewed-by: J. Neuschäfer <j.ne@posteo.net>

Thanks!

>  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 0e3ee5516587..0e26ff178505 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);
> 
> ---
> base-commit: 9152bc8cebcb14dc16b03ec81f2377ee8ce12268
> change-id: 20260212-wpcm-d86f76761645
> 
> Best regards,
> -- 
> Felix Gu <ustc.gu@gmail.com>
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] spi: wpcm-fiu: Fix potential NULL pointer dereference in wpcm_fiu_probe()
  2026-02-12 12:41 [PATCH] spi: wpcm-fiu: Fix potential NULL pointer dereference in wpcm_fiu_probe() Felix Gu
  2026-02-13  8:54 ` Markus Elfring
  2026-02-13 11:00 ` J. Neuschäfer
@ 2026-02-16 18:08 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2026-02-16 18:08 UTC (permalink / raw)
  To: Jonathan Neuschäfer, Felix Gu; +Cc: openbmc, linux-spi, linux-kernel

On Thu, 12 Feb 2026 20:41:40 +0800, Felix Gu wrote:
> 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.
> 
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/1] spi: wpcm-fiu: Fix potential NULL pointer dereference in wpcm_fiu_probe()
      commit: 888a0a802c467bbe34a42167bdf9d7331333440a

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-02-16 18:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-12 12:41 [PATCH] spi: wpcm-fiu: Fix potential NULL pointer dereference in wpcm_fiu_probe() Felix Gu
2026-02-13  8:54 ` Markus Elfring
2026-02-13 11:00 ` J. Neuschäfer
2026-02-16 18:08 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox