From a43d831ff46da6e1f953fda260d16071074237de Mon Sep 17 00:00:00 2001 From: huangwenxuan Date: Mon, 8 Sep 2025 14:42:53 +0800 Subject: [PATCH] fix: dev_spi_core.c add check spi ops --- components/drivers/spi/dev_spi_core.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/components/drivers/spi/dev_spi_core.c b/components/drivers/spi/dev_spi_core.c index 53bb7284fa..1f48f183f0 100644 --- a/components/drivers/spi/dev_spi_core.c +++ b/components/drivers/spi/dev_spi_core.c @@ -26,6 +26,25 @@ extern rt_err_t rt_spi_bus_device_init(struct rt_spi_bus *bus, const char *name); extern rt_err_t rt_spidev_device_init(struct rt_spi_device *dev, const char *name); +static rt_err_t rt_spi_check_ops(const struct rt_spi_ops *ops) +{ + if(ops == RT_NULL) + { + return -RT_EINVAL; + } + + else if(ops->configure == RT_NULL || ops->xfer == RT_NULL) + { + return -RT_EINVAL; + } + + else + { + return RT_EOK; + } + +} + rt_err_t spi_bus_register(struct rt_spi_bus *bus, const char *name, const struct rt_spi_ops *ops) @@ -36,6 +55,11 @@ rt_err_t spi_bus_register(struct rt_spi_bus *bus, if (result != RT_EOK) return result; + /* check ops */ + result = rt_spi_check_ops(ops); + if(result) + return result; + /* initialize mutex lock */ rt_mutex_init(&(bus->lock), name, RT_IPC_FLAG_PRIO); /* set ops */ -- Gitee