spi: stm32: Check for cfg availability in stm32_spi_probe
authorClément Le Goffic <clement.legoffic@foss.st.com>
Mon, 16 Jun 2025 09:21:03 +0000 (11:21 +0200)
committerMark Brown <broonie@kernel.org>
Tue, 24 Jun 2025 15:42:59 +0000 (16:42 +0100)
commit21f1c800f6620e43f31dfd76709dbac8ebaa5a16
tree62030d4289bc1ebb6ceef272d3becfac55ac9f44
parente4feefa5c71912ebfcb97a3dbe2b021fd1cea9d1
spi: stm32: Check for cfg availability in stm32_spi_probe

The stm32_spi_probe function now includes a check to ensure that the
pointer returned by of_device_get_match_data is not NULL before
accessing its members. This resolves a warning where a potential NULL
pointer dereference could occur when accessing cfg->has_device_mode.

Before accessing the 'has_device_mode' member, we verify that 'cfg' is
not NULL. If 'cfg' is NULL, an error message is logged.

This change ensures that the driver does not attempt to access
configuration data if it is not available, thus preventing a potential
system crash due to a NULL pointer dereference.

Signed-off-by: Clément Le Goffic <clement.legoffic@foss.st.com>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202310191831.MLwx1c6x-lkp@intel.com/
Fixes: fee681646fc8 ("spi: stm32: disable device mode with st,stm32f4-spi compatible")
Link: https://patch.msgid.link/20250616-spi-upstream-v1-2-7e8593f3f75d@foss.st.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-stm32.c