summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYen-Chao Chen <davidycchen@google.com>2023-03-29 10:31:46 +0800
committerYen-Chao Chen <davidycchen@google.com>2023-03-29 15:50:24 +0800
commit9ce883f2336406ab653308f53db3a9522c35cd99 (patch)
tree3eb66da339cfd9865c49b8d3b8ebdeb017c381ef
parent7ab600322e6f16d213f9af7db1f42b642a0e43c5 (diff)
downloadsynaptics_touch-9ce883f2336406ab653308f53db3a9522c35cd99.tar.gz
synaptics: check heatmap_buff before using
Check heatmap_buff before using to avoid null pointer issue. Bug: 271332558 Test: touch works fine. Change-Id: Ide72bcaad7f2ecf5e38c5958cb93787726213eba Signed-off-by: Yen-Chao Chen <davidycchen@google.com>
-rw-r--r--syna_tcm2.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/syna_tcm2.c b/syna_tcm2.c
index e6d7610..5c6e1ea 100644
--- a/syna_tcm2.c
+++ b/syna_tcm2.c
@@ -1390,6 +1390,23 @@ static void syna_offload_report(void *handle,
ATRACE_END();
}
+static int syna_heatmap_alloc_check(struct syna_tcm *tcm)
+{
+ if (tcm->heatmap_buff)
+ return 0;
+
+ tcm->heatmap_buff = devm_kzalloc(&tcm->pdev->dev,
+ sizeof(u16) * tcm->tcm_dev->rows * tcm->tcm_dev->cols, GFP_KERNEL);
+ if (!tcm->heatmap_buff) {
+ LOGE("allocate heatmap_buff failed\n");
+ return -ENOMEM;
+ }
+ LOGI("Allocate heatmap memory, rows: %d, cols: %d\n", tcm->tcm_dev->rows,
+ tcm->tcm_dev->cols);
+
+ return 0;
+}
+
static int syna_dev_ptflib_decoder(struct syna_tcm *tcm, const u16 *in_array,
const int in_array_size, u16 *out_array,
const int out_array_max_size)
@@ -1476,6 +1493,9 @@ static void syna_populate_mutual_channel(struct syna_tcm *tcm,
TOUCH_OFFLOAD_FRAME_SIZE_2D(mutual_strength->rx_size,
mutual_strength->tx_size);
+ if (syna_heatmap_alloc_check(tcm) != 0)
+ return;
+
if (has_heatmap) {
/* for 'heat map' ($c3) report,
* report data has been stored at tcm->event_data.buf;
@@ -1606,6 +1626,9 @@ static bool v4l2_read_frame(struct v4l2_heatmap *v4l2)
memcpy(v4l2->frame, tcm->heatmap_buff,
tcm->v4l2.width * tcm->v4l2.height * sizeof(u16));
} else {
+ if (syna_heatmap_alloc_check(tcm) != 0)
+ return false;
+
/* for 'heat map' ($c3) report,
* report data has been stored at tcm->event_data.buf;
* while, tcm->event_data.data_length is the size of data
@@ -3183,15 +3206,8 @@ static int syna_dev_probe(struct platform_device *pdev)
tcm->offload.report_cb = syna_offload_report;
touch_offload_init(&tcm->offload);
- if (!tcm->heatmap_buff) {
- tcm->heatmap_buff = kmalloc(
- sizeof(u16) * tcm->tcm_dev->rows * tcm->tcm_dev->cols,
- GFP_KERNEL);
- if (!tcm->heatmap_buff) {
- LOGE("allocate heatmap_buff failed\n");
- goto err_connect;
- }
- }
+ if (syna_heatmap_alloc_check(tcm) != 0)
+ goto err_connect;
tcm->touch_offload_active_coords = 0;
#endif