diff mbox series

[V2,1/2] interconnect: Add character pointer initialization

Message ID 20240914102435.3879355-1-Yibin.Ding@unisoc.com
State New
Headers show
Series [V2,1/2] interconnect: Add character pointer initialization | expand

Commit Message

Yibin Ding Sept. 14, 2024, 10:24 a.m. UTC
From: Yibin Ding <Yibin.ding@unisoc.com>

When accessing a node whose data type is a character pointer and has not
been initialized, a crash will occur due to accessing a null pointer. So
it is necessary to add the operation of initializing the character pointer.
Since the debugfs_write_file_str() function performs a kfree() operation
on the node data, memory is allocated to the node pointer during
initialization will be released when data is written to the node.

Signed-off-by: Yibin Ding <Yibin.ding@unisoc.com>
---
 drivers/interconnect/debugfs-client.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/interconnect/debugfs-client.c b/drivers/interconnect/debugfs-client.c
index bc3fd8a7b9eb..a1c99b9d3b9a 100644
--- a/drivers/interconnect/debugfs-client.c
+++ b/drivers/interconnect/debugfs-client.c
@@ -147,8 +147,13 @@  int icc_debugfs_client_init(struct dentry *icc_dir)
 
 	client_dir = debugfs_create_dir("test_client", icc_dir);
 
-	debugfs_create_str("src_node", 0600, client_dir, &src_node);
-	debugfs_create_str("dst_node", 0600, client_dir, &dst_node);
+	src_node = kzalloc(sizeof(src_node), GFP_KERNEL);
+	dst_node = kzalloc(sizeof(dst_node), GFP_KERNEL);
+
+	if (src_node)
+		debugfs_create_str("src_node", 0600, client_dir, &src_node);
+	if (dst_node)
+		debugfs_create_str("dst_node", 0600, client_dir, &dst_node);
 	debugfs_create_file("get", 0200, client_dir, NULL, &icc_get_fops);
 	debugfs_create_u32("avg_bw", 0600, client_dir, &avg_bw);
 	debugfs_create_u32("peak_bw", 0600, client_dir, &peak_bw);