Merge "diag: Add mutex protection while closing SMD"

This commit is contained in:
Linux Build Service Account 2016-11-04 22:22:06 -07:00 committed by Gerrit - the friendly Code Review server
commit 115a8ef46d
4 changed files with 12 additions and 0 deletions

View file

@ -509,6 +509,7 @@ struct diagchar_dev {
struct list_head cmd_reg_list;
struct mutex cmd_reg_mutex;
uint32_t cmd_reg_count;
struct mutex diagfwd_channel_mutex;
/* Sizes that reflect memory pool sizes */
unsigned int poolsize;
unsigned int poolsize_hdlc;

View file

@ -3394,6 +3394,7 @@ static int __init diagchar_init(void)
mutex_init(&driver->diag_file_mutex);
mutex_init(&driver->delayed_rsp_mutex);
mutex_init(&apps_data_mutex);
mutex_init(&driver->diagfwd_channel_mutex);
init_waitqueue_head(&driver->wait_q);
INIT_WORK(&(driver->diag_drain_work), diag_drain_work_fn);
INIT_WORK(&(driver->update_user_clients),

View file

@ -657,6 +657,7 @@ void diagfwd_close_transport(uint8_t transport, uint8_t peripheral)
fwd_info = &early_init_info[transport][peripheral];
if (fwd_info->p_ops && fwd_info->p_ops->close)
fwd_info->p_ops->close(fwd_info->ctxt);
mutex_lock(&driver->diagfwd_channel_mutex);
fwd_info = &early_init_info[transport_open][peripheral];
dest_info = &peripheral_info[TYPE_CNTL][peripheral];
dest_info->inited = 1;
@ -677,6 +678,7 @@ void diagfwd_close_transport(uint8_t transport, uint8_t peripheral)
diagfwd_late_open(dest_info);
diagfwd_cntl_open(dest_info);
init_fn(peripheral);
mutex_unlock(&driver->diagfwd_channel_mutex);
diagfwd_queue_read(&peripheral_info[TYPE_DATA][peripheral]);
diagfwd_queue_read(&peripheral_info[TYPE_CMD][peripheral]);
}

View file

@ -959,7 +959,9 @@ static int diag_socket_read(void *ctxt, unsigned char *buf, int buf_len)
(info->data_ready > 0) || (!info->hdl) ||
(atomic_read(&info->diag_state) == 0));
if (err) {
mutex_lock(&driver->diagfwd_channel_mutex);
diagfwd_channel_read_done(info->fwd_ctxt, buf, 0);
mutex_unlock(&driver->diagfwd_channel_mutex);
return -ERESTARTSYS;
}
@ -971,7 +973,9 @@ static int diag_socket_read(void *ctxt, unsigned char *buf, int buf_len)
DIAG_LOG(DIAG_DEBUG_PERIPHERALS,
"%s closing read thread. diag state is closed\n",
info->name);
mutex_lock(&driver->diagfwd_channel_mutex);
diagfwd_channel_read_done(info->fwd_ctxt, buf, 0);
mutex_unlock(&driver->diagfwd_channel_mutex);
return 0;
}
@ -1038,8 +1042,10 @@ static int diag_socket_read(void *ctxt, unsigned char *buf, int buf_len)
if (total_recd > 0) {
DIAG_LOG(DIAG_DEBUG_PERIPHERALS, "%s read total bytes: %d\n",
info->name, total_recd);
mutex_lock(&driver->diagfwd_channel_mutex);
err = diagfwd_channel_read_done(info->fwd_ctxt,
buf, total_recd);
mutex_unlock(&driver->diagfwd_channel_mutex);
if (err)
goto fail;
} else {
@ -1052,7 +1058,9 @@ static int diag_socket_read(void *ctxt, unsigned char *buf, int buf_len)
return 0;
fail:
mutex_lock(&driver->diagfwd_channel_mutex);
diagfwd_channel_read_done(info->fwd_ctxt, buf, 0);
mutex_unlock(&driver->diagfwd_channel_mutex);
return -EIO;
}