diff --git a/components/drivers/spi/spi_core.c b/components/drivers/spi/spi_core.c index fc9f707979..3425498451 100644 --- a/components/drivers/spi/spi_core.c +++ b/components/drivers/spi/spi_core.c @@ -8,7 +8,8 @@ rt_err_t rt_spi_bus_register(struct rt_spi_bus* bus, const char* name, const str rt_err_t result; result = rt_spi_bus_device_init(bus, name); - if (result != RT_EOK) return result; + if (result != RT_EOK) + return result; /* initialize mutex lock */ rt_mutex_init(&(bus->lock), name, RT_IPC_FLAG_FIFO); @@ -22,6 +23,7 @@ rt_err_t rt_spi_bus_register(struct rt_spi_bus* bus, const char* name, const str rt_err_t rt_spi_bus_attach_device(struct rt_spi_device* device, const char* name, const char* bus_name, void* user_data) { + rt_err_t result; rt_device_t bus; /* get physical spi bus */ @@ -31,9 +33,14 @@ rt_err_t rt_spi_bus_attach_device(struct rt_spi_device* device, const char* name device->bus = (struct rt_spi_bus*)bus; /* initialize spidev device */ - rt_spidev_device_init(device, name); + result = rt_spidev_device_init(device, name); + if (result != RT_EOK) + return result; + rt_memset(&device->config, 0, sizeof(device->config)); device->parent.user_data = user_data; + + return RT_EOK; } /* not found the host bus */ diff --git a/components/drivers/spi/spi_dev.c b/components/drivers/spi/spi_dev.c index afb17dafde..1b3a9f193f 100644 --- a/components/drivers/spi/spi_dev.c +++ b/components/drivers/spi/spi_dev.c @@ -70,9 +70,7 @@ rt_err_t rt_spi_bus_device_init(struct rt_spi_bus* bus, const char* name) device->control = _spi_bus_device_control; /* register to device manager */ - rt_device_register(device, name, RT_DEVICE_FLAG_RDWR); - - return RT_EOK; + return rt_device_register(device, name, RT_DEVICE_FLAG_RDWR); } /* SPI Dev device interface, compatible with RT-Thread 0.3.x/1.0.x */ @@ -143,7 +141,5 @@ rt_err_t rt_spidev_device_init(struct rt_spi_device* dev, const char* name) device->control = _spidev_device_control; /* register to device manager */ - rt_device_register(device, name, RT_DEVICE_FLAG_RDWR); - - return RT_EOK; + return rt_device_register(device, name, RT_DEVICE_FLAG_RDWR); }