[dm][serial] Fixup serial tty check

Just return if is not a tty device, don't assert

Signed-off-by: GuEe-GUI <2991707448@qq.com>
This commit is contained in:
GuEe-GUI
2025-12-13 01:51:42 +08:00
committed by R b b666
parent cb808f3a0e
commit 6394797471

View File

@@ -62,7 +62,11 @@ static char *alloc_device_name(struct rt_serial_device *serial)
* must be obtained using the serial_dev_set_name function,
* and it should begin with "uart".
*/
RT_ASSERT((strlen(serial_name) > strlen("uart")) && (strncmp(serial_name, "uart", 4) == 0));
if (!serial_name || rt_strlen(serial_name) < 4 || rt_strncmp(serial_name, "uart", 4))
{
return RT_NULL;
}
long digits_len = (sizeof(TTY_NAME_PREFIX) - 1) /* raw prefix */
+ strlen(serial_name + sizeof("uart") - 1) /* suffix of serial device name*/
+ 1; /* tailing \0 */