soc: qcom: bgcom: protect rsb events list for producer/consumer

Provides lock to protect rsb event list for producer/
consumer. A node can be added or removed at a time to avoid
list corruption.

Change-Id: Ib91e5339e0b9e1f60d595bf9ef4d83a57f867f90
Signed-off-by: Arjun Singh <arsingh@codeaurora.org>
diff --git a/drivers/soc/qcom/bgcom_spi.c b/drivers/soc/qcom/bgcom_spi.c
index b13f06d..c8d0fa4 100644
--- a/drivers/soc/qcom/bgcom_spi.c
+++ b/drivers/soc/qcom/bgcom_spi.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2017-2019, 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
@@ -106,6 +106,7 @@ static uint32_t g_slav_status_reg;
 static void send_input_events(struct work_struct *work);
 static struct list_head cb_head = LIST_HEAD_INIT(cb_head);
 static struct list_head pr_lst_hd = LIST_HEAD_INIT(pr_lst_hd);
+static DEFINE_SPINLOCK(lst_setup_lock);
 static enum bgcom_spi_state spi_state;
 
 
@@ -148,7 +149,9 @@ static void send_input_events(struct work_struct *work)
 		evnt = node->evnt;
 		bgrsb_send_input(evnt);
 		kfree(evnt);
+		spin_lock(&lst_setup_lock);
 		list_del(&node->list);
+		spin_unlock(&lst_setup_lock);
 		kfree(node);
 	}
 }
@@ -323,8 +326,9 @@ static void parse_fifo(uint8_t *data, union bgcom_event_data_type *event_data)
 
 			data_list = kmalloc(sizeof(*data_list), GFP_KERNEL);
 			data_list->evnt = evnt;
+			spin_lock(&lst_setup_lock);
 			list_add_tail(&data_list->list, &pr_lst_hd);
-
+			spin_unlock(&lst_setup_lock);
 		} else if (event_id == 0x0001) {
 			evnt_data = kmalloc(p_len, GFP_KERNEL);
 			if (evnt_data != NULL) {