summaryrefslogtreecommitdiff
path: root/drivers/char
diff options
context:
space:
mode:
authorHardik Arya <harya@codeaurora.org>2018-04-09 14:49:40 +0530
committerHardik Arya <harya@codeaurora.org>2018-08-07 17:54:41 +0530
commit280b89e72c92a4b6fc51ea0813ec270f379c5086 (patch)
treede2271b06cd44692829903117a19797c272ef364 /drivers/char
parent11ee621aea156ba9e1854335b0708f42fca975c7 (diff)
diag: Add missing protection while accessing session's info
Currently, mutex protection is missing while accessing md session's info via macro. The patch adds proper protection before accessing the same. Change-Id: I17b18183407279447229783fd0165337bd173423 Signed-off-by: Hardik Arya <harya@codeaurora.org>
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/diag/diag_masks.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/drivers/char/diag/diag_masks.c b/drivers/char/diag/diag_masks.c
index ad6805553998..94613a47eafa 100644
--- a/drivers/char/diag/diag_masks.c
+++ b/drivers/char/diag/diag_masks.c
@@ -27,10 +27,6 @@
#define DIAG_SET_FEATURE_MASK(x) (feature_bytes[(x)/8] |= (1 << (x & 0x7)))
-#define diag_check_update(x) \
- (!info || (info && (info->peripheral_mask & MD_PERIPHERAL_MASK(x))) \
- || (info && (info->peripheral_mask & MD_PERIPHERAL_PD_MASK(x)))) \
-
struct diag_mask_info msg_mask;
struct diag_mask_info msg_bt_mask;
struct diag_mask_info log_mask;
@@ -65,6 +61,22 @@ static const struct diag_ssid_range_t msg_mask_tbl[] = {
{ .ssid_first = MSG_SSID_25, .ssid_last = MSG_SSID_25_LAST }
};
+static int diag_check_update(int md_peripheral, int pid)
+{
+ int ret;
+ struct diag_md_session_t *info = NULL;
+
+ mutex_lock(&driver->md_session_lock);
+ info = diag_md_session_get_pid(pid);
+ ret = (!info || (info &&
+ (info->peripheral_mask & MD_PERIPHERAL_MASK(md_peripheral))) ||
+ (info && (info->peripheral_mask &
+ MD_PERIPHERAL_PD_MASK(md_peripheral))));
+ mutex_unlock(&driver->md_session_lock);
+
+ return ret;
+}
+
static int diag_apps_responds(void)
{
/*
@@ -838,7 +850,7 @@ static int diag_cmd_set_msg_mask(unsigned char *src_buf, int src_len,
mutex_unlock(&driver->msg_mask_lock);
mutex_unlock(&mask_info->lock);
mutex_unlock(&driver->md_session_lock);
- if (diag_check_update(APPS_DATA))
+ if (diag_check_update(APPS_DATA, pid))
diag_update_userspace_clients(MSG_MASKS_TYPE);
/*
@@ -860,7 +872,7 @@ static int diag_cmd_set_msg_mask(unsigned char *src_buf, int src_len,
memcpy(dest_buf + write_len, src_buf + header_len, mask_size);
write_len += mask_size;
for (i = 0; i < NUM_PERIPHERALS; i++) {
- if (!diag_check_update(i))
+ if (!diag_check_update(i, pid))
continue;
mutex_lock(&driver->md_session_lock);
diag_send_msg_mask_update(i, req->ssid_first, req->ssid_last);
@@ -928,7 +940,7 @@ static int diag_cmd_set_all_msg_mask(unsigned char *src_buf, int src_len,
mutex_unlock(&driver->msg_mask_lock);
mutex_unlock(&mask_info->lock);
mutex_unlock(&driver->md_session_lock);
- if (diag_check_update(APPS_DATA))
+ if (diag_check_update(APPS_DATA, pid))
diag_update_userspace_clients(MSG_MASKS_TYPE);
/*
@@ -944,7 +956,7 @@ static int diag_cmd_set_all_msg_mask(unsigned char *src_buf, int src_len,
write_len += header_len;
for (i = 0; i < NUM_PERIPHERALS; i++) {
- if (!diag_check_update(i))
+ if (!diag_check_update(i, pid))
continue;
mutex_lock(&driver->md_session_lock);
diag_send_msg_mask_update(i, ALL_SSID, ALL_SSID);
@@ -1032,7 +1044,7 @@ static int diag_cmd_update_event_mask(unsigned char *src_buf, int src_len,
mask_info->status = DIAG_CTRL_MASK_VALID;
mutex_unlock(&mask_info->lock);
mutex_unlock(&driver->md_session_lock);
- if (diag_check_update(APPS_DATA))
+ if (diag_check_update(APPS_DATA, pid))
diag_update_userspace_clients(EVENT_MASKS_TYPE);
/*
@@ -1049,7 +1061,7 @@ static int diag_cmd_update_event_mask(unsigned char *src_buf, int src_len,
write_len += mask_len;
for (i = 0; i < NUM_PERIPHERALS; i++) {
- if (!diag_check_update(i))
+ if (!diag_check_update(i, pid))
continue;
mutex_lock(&driver->md_session_lock);
diag_send_event_mask_update(i);
@@ -1098,7 +1110,7 @@ static int diag_cmd_toggle_events(unsigned char *src_buf, int src_len,
}
mutex_unlock(&mask_info->lock);
mutex_unlock(&driver->md_session_lock);
- if (diag_check_update(APPS_DATA))
+ if (diag_check_update(APPS_DATA, pid))
diag_update_userspace_clients(EVENT_MASKS_TYPE);
/*
@@ -1108,7 +1120,7 @@ static int diag_cmd_toggle_events(unsigned char *src_buf, int src_len,
header.cmd_code = DIAG_CMD_EVENT_TOGGLE;
header.padding = 0;
for (i = 0; i < NUM_PERIPHERALS; i++) {
- if (!diag_check_update(i))
+ if (!diag_check_update(i, pid))
continue;
mutex_lock(&driver->md_session_lock);
diag_send_event_mask_update(i);
@@ -1371,7 +1383,7 @@ static int diag_cmd_set_log_mask(unsigned char *src_buf, int src_len,
}
mutex_unlock(&mask_info->lock);
mutex_unlock(&driver->md_session_lock);
- if (diag_check_update(APPS_DATA))
+ if (diag_check_update(APPS_DATA, pid))
diag_update_userspace_clients(LOG_MASKS_TYPE);
/*
@@ -1400,7 +1412,7 @@ static int diag_cmd_set_log_mask(unsigned char *src_buf, int src_len,
write_len += payload_len;
for (i = 0; i < NUM_PERIPHERALS; i++) {
- if (!diag_check_update(i))
+ if (!diag_check_update(i, pid))
continue;
mutex_lock(&driver->md_session_lock);
diag_send_log_mask_update(i, req->equip_id);
@@ -1453,7 +1465,7 @@ static int diag_cmd_disable_log_mask(unsigned char *src_buf, int src_len,
}
mask_info->status = DIAG_CTRL_MASK_ALL_DISABLED;
mutex_unlock(&driver->md_session_lock);
- if (diag_check_update(APPS_DATA))
+ if (diag_check_update(APPS_DATA, pid))
diag_update_userspace_clients(LOG_MASKS_TYPE);
/*
@@ -1469,7 +1481,7 @@ static int diag_cmd_disable_log_mask(unsigned char *src_buf, int src_len,
memcpy(dest_buf, &header, sizeof(struct diag_log_config_rsp_t));
write_len += sizeof(struct diag_log_config_rsp_t);
for (i = 0; i < NUM_PERIPHERALS; i++) {
- if (!diag_check_update(i))
+ if (!diag_check_update(i, pid))
continue;
mutex_lock(&driver->md_session_lock);
diag_send_log_mask_update(i, ALL_EQUIP_ID);