From 2a8aba4c8b8c5a9f415cfa24316eba8a5573cc4a Mon Sep 17 00:00:00 2001 From: milo <1569491816@qq.com> Date: Thu, 19 Sep 2024 18:15:55 +0800 Subject: [PATCH] [fix]:fix log format and reopen with a different oflag issue (#9452) fix log format and reopen with a different oflag issue --- components/drivers/core/device.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/components/drivers/core/device.c b/components/drivers/core/device.c index 49b428a577..5dfd0c4653 100644 --- a/components/drivers/core/device.c +++ b/components/drivers/core/device.c @@ -13,6 +13,8 @@ * 2013-07-09 Grissiom add ref_count support * 2016-04-02 Bernard fix the open_flag initialization issue. * 2021-03-19 Meco Man remove rt_device_init_all() + * 2024-09-15 milo fix log format issue + * fix reopen with a different oflag issue */ #include @@ -195,8 +197,8 @@ rt_err_t rt_device_init(rt_device_t dev) result = device_init(dev); if (result != RT_EOK) { - LOG_E("To initialize device:%s failed. The error code is %d", - dev->parent.name, result); + LOG_E("To initialize device:%.*s failed. The error code is %d", + RT_NAME_MAX, dev->parent.name, result); } else { @@ -233,8 +235,8 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag) result = device_init(dev); if (result != RT_EOK) { - LOG_E("To initialize device:%s failed. The error code is %d", - dev->parent.name, result); + LOG_E("To initialize device:%.*s failed. The error code is %d", + RT_NAME_MAX, dev->parent.name, result); return result; } @@ -252,7 +254,7 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag) /* device is not opened or opened by other oflag, call device_open interface */ if (!(dev->open_flag & RT_DEVICE_OFLAG_OPEN) || - ((dev->open_flag & RT_DEVICE_OFLAG_MASK) != (oflag & RT_DEVICE_OFLAG_MASK))) + ((dev->open_flag & RT_DEVICE_OFLAG_MASK) != ((oflag & RT_DEVICE_OFLAG_MASK) | RT_DEVICE_OFLAG_OPEN))) { if (device_open != RT_NULL) {