From b48f2d044c553724180cdb41ad75fb9925c6986a Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Mon, 17 Apr 2023 14:02:00 +0800 Subject: [PATCH] =?UTF-8?q?debug:=20=E7=A1=AE=E4=BF=9D=20`rt=5Fconsole=5Fs?= =?UTF-8?q?et=5Fdevice`=20=E5=8F=AF=E4=BB=A5=E5=B0=86=20`=5Fconsole=5Fdevi?= =?UTF-8?q?ce`=20=E7=BD=AE=E4=B8=BA=20NULL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: a1012112796 <1012112796@qq.com> --- rt-thread/src/kservice.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) 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);