From 85ceda00dacffd235156bc811cc42d21267c48f2 Mon Sep 17 00:00:00 2001 From: wuyangyong Date: Tue, 27 Dec 2011 05:41:04 +0000 Subject: fixed rt_device_init issues. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1882 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- src/device.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'src/device.c') diff --git a/src/device.c b/src/device.c index f164b17852..7f44227af0 100644 --- a/src/device.c +++ b/src/device.c @@ -146,26 +146,29 @@ rt_device_t rt_device_find(const char *name) */ rt_err_t rt_device_init(rt_device_t dev) { - rt_err_t result; + rt_err_t result = RT_EOK; rt_err_t (*init)(rt_device_t dev); RT_ASSERT(dev != RT_NULL); /* get device init handler */ init = dev->init; - if (init != RT_NULL && !(dev->flag & RT_DEVICE_FLAG_ACTIVATED)) - { - result = init(dev); - if (result != RT_EOK) - { - rt_kprintf("To initialize device:%s failed. The error code is %d\n", - dev->parent.name, result); - } - else - { - dev->flag |= RT_DEVICE_FLAG_ACTIVATED; - } - } + if (init != RT_NULL) + { + if(!(dev->flag & RT_DEVICE_FLAG_ACTIVATED)) + { + result = init(dev); + if (result != RT_EOK) + { + rt_kprintf("To initialize device:%s failed. The error code is %d\n", + dev->parent.name, result); + } + else + { + dev->flag |= RT_DEVICE_FLAG_ACTIVATED; + } + } + } else result = -RT_ENOSYS; return result; -- cgit v1.3.1