Polish console validation checks

This commit is contained in:
copilot-swe-agent[bot]
2026-06-09 06:57:24 +00:00
committed by GitHub
parent 546190e0c4
commit 910af82963
2 changed files with 7 additions and 4 deletions
+3 -2
View File
@@ -57,6 +57,7 @@ struct test_console_context
};
static char _console_name[RT_NAME_MAX + 1];
static rt_atomic_t _device_sequence;
static rt_err_t test_console_open(rt_device_t dev, rt_uint16_t oflag)
{
@@ -108,9 +109,9 @@ static const struct rt_device_ops test_console_ops =
static void make_test_device_name(char *name, rt_size_t size, const char *prefix)
{
static rt_uint32_t sequence;
rt_uint32_t sequence = (rt_uint32_t)rt_atomic_add(&_device_sequence, 1);
rt_snprintf(name, size, "%s%u", prefix, sequence++);
rt_snprintf(name, size, "%s%u", prefix, sequence);
}
static void init_test_console_device(struct rt_device *device,
+4 -2
View File
@@ -170,6 +170,7 @@ static rt_err_t _console_get_open_flags(rt_device_t device, rt_uint16_t *oflag)
{
rt_err_t result;
rt_uint16_t console_oflag = RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM;
rt_uint16_t access_mode;
RT_ASSERT(device != RT_NULL);
RT_ASSERT(oflag != RT_NULL);
@@ -191,8 +192,9 @@ static rt_err_t _console_get_open_flags(rt_device_t device, rt_uint16_t *oflag)
}
}
if ((console_oflag & RT_DEVICE_OFLAG_RDWR) != RT_DEVICE_OFLAG_WRONLY &&
(console_oflag & RT_DEVICE_OFLAG_RDWR) != RT_DEVICE_OFLAG_RDWR)
access_mode = console_oflag & RT_DEVICE_OFLAG_RDWR;
if (access_mode != RT_DEVICE_OFLAG_WRONLY &&
access_mode != RT_DEVICE_OFLAG_RDWR)
{
LOG_W("refuse to set device %.*s as console: invalid open flags 0x%04x",
RT_NAME_MAX, device->parent.name, console_oflag);