From 64212c3f1e8bdae6a1612741da1ad90ccff44ac2 Mon Sep 17 00:00:00 2001 From: zuoqian Date: Tue, 3 Jun 2025 10:52:51 +0800 Subject: [PATCH] spi: phytium: Add NULL check for gpiod to avoid crash API devm_gpiod_get_index_optional() will return NULL when DSDT describes cs-gpios in SPI but use an not exist _CSR of gpio pin. So add NULL check after devm_gpiod_get_index_optional(). Signed-off-by: zuoqian Signed-off-by: liutianyu1250 --- drivers/spi/spi-phytium-plat-v2.c | 8 ++++++-- drivers/spi/spi-phytium-plat.c | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-phytium-plat-v2.c b/drivers/spi/spi-phytium-plat-v2.c index 73fc2e5f09a..0cd8240b951 100644 --- a/drivers/spi/spi-phytium-plat-v2.c +++ b/drivers/spi/spi-phytium-plat-v2.c @@ -239,8 +239,12 @@ static int spi_phyt_probe(struct platform_device *pdev) goto out; } - cs_gpio = desc_to_gpio(gpiod); - cs[i] = cs_gpio; + if (gpiod) { + cs_gpio = desc_to_gpio(gpiod); + cs[i] = cs_gpio; + } else { + cs[i] = -ENOENT; + } } } diff --git a/drivers/spi/spi-phytium-plat.c b/drivers/spi/spi-phytium-plat.c index 2b2517c6f90..840523df515 100644 --- a/drivers/spi/spi-phytium-plat.c +++ b/drivers/spi/spi-phytium-plat.c @@ -131,8 +131,12 @@ static int phytium_spi_probe(struct platform_device *pdev) goto out; } - cs_gpio = desc_to_gpio(gpiod); - cs[i] = cs_gpio; + if (gpiod) { + cs_gpio = desc_to_gpio(gpiod); + cs[i] = cs_gpio; + } else { + cs[i] = -ENOENT; + } } } -- Gitee