summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormilo <[email protected]>2024-09-19 18:15:55 +0800
committerGitHub <[email protected]>2024-09-19 18:15:55 +0800
commit2a8aba4c8b8c5a9f415cfa24316eba8a5573cc4a (patch)
tree985dd8da69af3f0ae1d285c91fbc90f36317d767
parent29c0357ff8f9143f742b05de7f9189f707bc673f (diff)
[fix]:fix log format and reopen with a different oflag issue (#9452)
fix log format and reopen with a different oflag issue
-rw-r--r--components/drivers/core/device.c12
1 files 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 <rtthread.h>
@@ -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)
{