mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-10-02 14:23:19 +08:00
Polish console validation checks
This commit is contained in:
@@ -57,6 +57,7 @@ struct test_console_context
|
|||||||
};
|
};
|
||||||
|
|
||||||
static char _console_name[RT_NAME_MAX + 1];
|
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)
|
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 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,
|
static void init_test_console_device(struct rt_device *device,
|
||||||
|
|||||||
+4
-2
@@ -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_err_t result;
|
||||||
rt_uint16_t console_oflag = RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM;
|
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(device != RT_NULL);
|
||||||
RT_ASSERT(oflag != 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 &&
|
access_mode = console_oflag & RT_DEVICE_OFLAG_RDWR;
|
||||||
(console_oflag & RT_DEVICE_OFLAG_RDWR) != 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",
|
LOG_W("refuse to set device %.*s as console: invalid open flags 0x%04x",
|
||||||
RT_NAME_MAX, device->parent.name, console_oflag);
|
RT_NAME_MAX, device->parent.name, console_oflag);
|
||||||
|
|||||||
Reference in New Issue
Block a user