From 46a83e85920aa49c437c689154ee136eea91de1c Mon Sep 17 00:00:00 2001 From: Manoj Prabhu B Date: Wed, 11 May 2016 09:25:56 +0530 Subject: [PATCH] diag: Fix for possible stale task entries The task entries were cleared while closing the md session and hence are stale while notifying the client. This patch provides the protection on md session and also checks for the session pid and task pid being same. CRs-Fixed: 1008137 Change-Id: I999db2865d10464c7f1ab4a5a940d23c725ac033 Signed-off-by: Manoj Prabhu B --- drivers/char/diag/diagfwd_cntl.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/char/diag/diagfwd_cntl.c b/drivers/char/diag/diagfwd_cntl.c index 5d2381069df1..e9d025455382 100644 --- a/drivers/char/diag/diagfwd_cntl.c +++ b/drivers/char/diag/diagfwd_cntl.c @@ -117,19 +117,31 @@ void diag_notify_md_client(uint8_t peripheral, int data) if (driver->logging_mode != DIAG_MEMORY_DEVICE_MODE) return; + mutex_lock(&driver->md_session_lock); memset(&info, 0, sizeof(struct siginfo)); info.si_code = SI_QUEUE; info.si_int = (PERIPHERAL_MASK(peripheral) | data); info.si_signo = SIGCONT; if (driver->md_session_map[peripheral] && - driver->md_session_map[peripheral]->task) { - stat = send_sig_info(info.si_signo, &info, - driver->md_session_map[peripheral]->task); - if (stat) - pr_err("diag: Err sending signal to memory device client, signal data: 0x%x, stat: %d\n", - info.si_int, stat); + driver->md_session_map[peripheral]->task) { + if (driver->md_session_map[peripheral]->pid == + driver->md_session_map[peripheral]->task->tgid) { + DIAG_LOG(DIAG_DEBUG_PERIPHERALS, + "md_session %d pid = %d, md_session %d task tgid = %d\n", + peripheral, + driver->md_session_map[peripheral]->pid, + peripheral, + driver->md_session_map[peripheral]->task->tgid); + stat = send_sig_info(info.si_signo, &info, + driver->md_session_map[peripheral]->task); + if (stat) + pr_err("diag: Err sending signal to memory device client, signal data: 0x%x, stat: %d\n", + info.si_int, stat); + } else + pr_err("diag: md_session_map[%d] data is corrupted, signal data: 0x%x, stat: %d\n", + peripheral, info.si_int, stat); } - + mutex_unlock(&driver->md_session_lock); } static void process_pd_status(uint8_t *buf, uint32_t len,