From 19a07ca81743605d98976481cf43a719bf583a27 Mon Sep 17 00:00:00 2001 From: Sonal Aggarwal Date: Fri, 13 May 2022 14:51:45 +0530 Subject: [PATCH] tzlog : Add check to avoid null pointer dereferencing Do not assign address to structure and then do not traverse private member at structure without checking if its null or not. Hence, add the check to avoid it. Change-Id: Ia1d38cb25ea880004954d1bfb7ed439db84abc2f Signed-off-by: Sonal Aggarwal --- drivers/firmware/qcom/tz_log.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/qcom/tz_log.c b/drivers/firmware/qcom/tz_log.c index d346d5576807..e8697d7b2bf6 100644 --- a/drivers/firmware/qcom/tz_log.c +++ b/drivers/firmware/qcom/tz_log.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved. + * Copyright (c) 2022, Qualcomm Innovation Center, Inc. All rights reserved. */ #include #include @@ -1238,8 +1239,15 @@ static ssize_t tzdbgfs_read(struct file *file, char __user *buf, struct seq_file *seq = file->private_data; int tz_id = TZDBG_STATS_MAX; - if (seq) - tz_id = *(int *)(seq->private); + if (seq) { + if (seq->private) + tz_id = *(int *)(seq->private); + else { + pr_err("%s: Seq data private null unable to proceed\n", + __func__); + return 0; + } + } else { pr_err("%s: Seq data null unable to proceed\n", __func__); return 0;