mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yibin Ding <Yibin.Ding@unisoc.com>
To: <djakov@kernel.org>, <gregkh@linuxfoundation.org>, <rafael@kernel.org>
Cc: <yibin.ding01@gmail.com>, <niuzhiguo84@gmail.com>,
	<linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<Hao_hao.Wang@unisoc.com>, <Ke.Wang@unisoc.com>
Subject: [PATCH 1/2] interconnect: Add character pointer initialization
Date: Fri, 30 Aug 2024 18:22:44 +0800	[thread overview]
Message-ID: <20240830102244.409058-1-Yibin.Ding@unisoc.com> (raw)

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 | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/interconnect/debugfs-client.c b/drivers/interconnect/debugfs-client.c
index bc3fd8a7b9eb..d62ba56b7bbe 100644
--- a/drivers/interconnect/debugfs-client.c
+++ b/drivers/interconnect/debugfs-client.c
@@ -16,6 +16,7 @@
 #undef INTERCONNECT_ALLOW_WRITE_DEBUGFS
 
 #if defined(INTERCONNECT_ALLOW_WRITE_DEBUGFS) && defined(CONFIG_DEBUG_FS)
+#define INITNODE_SIZE 1
 
 static LIST_HEAD(debugfs_paths);
 static DEFINE_MUTEX(debugfs_lock);
@@ -147,8 +148,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(INITNODE_SIZE, GFP_KERNEL);
+	dst_node = kzalloc(INITNODE_SIZE, 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);
-- 
2.25.1


             reply	other threads:[~2024-08-30 10:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-30 10:22 Yibin Ding [this message]
2024-08-30 10:35 ` Greg KH
     [not found]   ` <CAC6ZDY_V1w92gg=ZugbHhWfBJpVqNpuTdgvURk0WYVnzqMKkjA@mail.gmail.com>
2024-09-02  6:10     ` Greg KH
     [not found]       ` <CAC6ZDY8KuBV5YDFJayCELkPEf6w_cMttEfa5fgQW85Zs9UnQtQ@mail.gmail.com>
2024-09-03  8:00         ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240830102244.409058-1-Yibin.Ding@unisoc.com \
    --to=yibin.ding@unisoc.com \
    --cc=Hao_hao.Wang@unisoc.com \
    --cc=Ke.Wang@unisoc.com \
    --cc=djakov@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=niuzhiguo84@gmail.com \
    --cc=rafael@kernel.org \
    --cc=yibin.ding01@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®