Skip to content

Commit

Permalink
[fix]:fix log format and reopen with a different oflag issue (RT-Thre…
Browse files Browse the repository at this point in the history
…ad#9452)

fix log format and reopen with a different oflag issue
  • Loading branch information
milo-9 authored and rcitach committed Nov 1, 2024
1 parent 8355b19 commit c8ae5fa
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions components/drivers/core/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}
Expand All @@ -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)
{
Expand Down

0 comments on commit c8ae5fa

Please sign in to comment.