Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 949dc4ed authored by Mohit Aggarwal's avatar Mohit Aggarwal
Browse files

diag: Add mutex protection while closing SMD



On receiving feature mask add mutex protection while closing
SMD and start reading from socket channel

CRs-Fixed: 980999
Change-Id: I01e5e8c9e0b03fa8b09f0ffd6857fe7e60a48091
Signed-off-by: default avatarSreelakshmi Gownipalli <sgownipa@codeaurora.org>
Signed-off-by: default avatarMohit Aggarwal <maggarwa@codeaurora.org>
parent 17d7bd58
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
/* Copyright (c) 2008-2015, The Linux Foundation. All rights reserved.
/* Copyright (c) 2008-2016, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -500,6 +500,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;
+1 −0
Original line number Diff line number Diff line
@@ -3298,6 +3298,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),
+3 −1
Original line number Diff line number Diff line
/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
/* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -646,6 +646,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;
@@ -664,6 +665,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]);
}
+9 −1
Original line number Diff line number Diff line
/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
/* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -929,7 +929,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;
	}

@@ -941,7 +943,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;
	}

@@ -1008,8 +1012,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 {
@@ -1022,7 +1028,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;
}