fix(esp_driver_usb_serial_jtag): check USJ accessibility before read/write

Add connection checks to usb_serial_jtag_write and usb_serial_jtag_read
functions to return -EIO error code when the USB Serial JTAG is not
connected.
This commit is contained in:
wuzhenghui
2025-10-13 15:49:23 +08:00
parent 4eb4a52f62
commit 454d1ac65d

View File

@@ -176,6 +176,10 @@ static int usb_serial_jtag_rx_char(int fd)
static ssize_t usb_serial_jtag_write(int fd, const void * data, size_t size)
{
if (!usb_serial_jtag_is_connected()) {
// TODO: IDF-14303
return -1;
}
const char *data_c = (const char *)data;
/* Even though newlib does stream locking on each individual stream, we need
* a dedicated lock if two streams (stdout and stderr) point to the
@@ -220,6 +224,10 @@ static void usb_serial_jtag_return_char(int fd, int c)
static ssize_t usb_serial_jtag_read(int fd, void* data, size_t size)
{
if (!usb_serial_jtag_is_connected()) {
// TODO: IDF-14303
return -1;
}
char *data_c = (char *) data;
size_t received = 0;
size_t available_size = 0;
@@ -323,6 +331,10 @@ static int usb_serial_jtag_fcntl(int fd, int cmd, int arg)
static int usb_serial_jtag_fsync(int fd)
{
if (!usb_serial_jtag_is_connected()) {
// TODO: IDF-14303
return -1;
}
_lock_acquire_recursive(&s_ctx.write_lock);
usb_serial_jtag_ll_txfifo_flush();
//Wait for the host to have picked up the buffer, but honour the timeout in