diff --git a/rt-thread/src/kservice.c b/rt-thread/src/kservice.c index efcc362..a92d22e 100644 --- a/rt-thread/src/kservice.c +++ b/rt-thread/src/kservice.c @@ -746,19 +746,17 @@ rt_device_t rt_console_set_device(const char *name) /* check whether it's a same device */ if (new_device == old_device) return RT_NULL; - if (new_device != RT_NULL) + if (_console_device != RT_NULL) { - if (_console_device != RT_NULL) - { - /* close old console device */ - rt_device_close(_console_device); - } - - /* set new console device */ - rt_device_open(new_device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_STREAM); - _console_device = new_device; + /* close old console device */ + rt_device_close(_console_device); } + /* set new console device */ + if (new_device != RT_NULL) + rt_device_open(new_device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_STREAM); + _console_device = new_device; + return old_device; } RTM_EXPORT(rt_console_set_device);