Skip to content

Commit 21f1c80

Browse files
clegofficbroonie
authored andcommitted
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: fee6816 ("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>
1 parent e4feefa commit 21f1c80

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

drivers/spi/spi-stm32.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2089,9 +2089,15 @@ static int stm32_spi_probe(struct platform_device *pdev)
20892089
struct resource *res;
20902090
struct reset_control *rst;
20912091
struct device_node *np = pdev->dev.of_node;
2092+
const struct stm32_spi_cfg *cfg;
20922093
bool device_mode;
20932094
int ret;
2094-
const struct stm32_spi_cfg *cfg = of_device_get_match_data(&pdev->dev);
2095+
2096+
cfg = of_device_get_match_data(&pdev->dev);
2097+
if (!cfg) {
2098+
dev_err(&pdev->dev, "Failed to get match data for platform\n");
2099+
return -ENODEV;
2100+
}
20952101

20962102
device_mode = of_property_read_bool(np, "spi-slave");
20972103
if (!cfg->has_device_mode && device_mode) {

0 commit comments

Comments
 (0)