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:
@@ -182,6 +182,10 @@ static int usb_serial_jtag_rx_char_no_driver(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
|
||||
@@ -226,6 +230,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;
|
||||
}
|
||||
assert(fd == USJ_LOCAL_FD);
|
||||
char *data_c = (char *) data;
|
||||
size_t received = 0;
|
||||
@@ -349,6 +357,10 @@ static int usb_serial_jtag_wait_tx_done_no_driver(int fd)
|
||||
|
||||
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);
|
||||
int r = s_ctx.fsync_func(fd);
|
||||
_lock_release_recursive(&s_ctx.write_lock);
|
||||
|
||||
Reference in New Issue
Block a user