From 55f5069a5eda16382edecadc0b0ebb636dc4623d Mon Sep 17 00:00:00 2001 From: "dzzxzz@gmail.com" Date: Tue, 15 May 2012 10:44:39 +0000 Subject: [PATCH] fixed the return value in rt_spi_bus_attach_device() git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2118 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- components/drivers/spi/spi_core.c | 11 +++++++++-- components/drivers/spi/spi_dev.c | 8 ++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/components/drivers/spi/spi_core.c b/components/drivers/spi/spi_core.c index fc9f70797..342549845 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 afb17dafd..1b3a9f193 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); }