public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2 1/2] interconnect: Add character pointer initialization
@ 2024-09-14 10:24 Yibin Ding
  2024-09-14 13:56 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Yibin Ding @ 2024-09-14 10:24 UTC (permalink / raw)
  To: djakov, gregkh, rafael
  Cc: yibin.ding01, niuzhiguo84, linux-pm, linux-kernel, Hao_hao.Wang,
	Ke.Wang

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 --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);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH V2 1/2] interconnect: Add character pointer initialization
  2024-09-14 10:24 [PATCH V2 1/2] interconnect: Add character pointer initialization Yibin Ding
@ 2024-09-14 13:56 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2024-09-14 13:56 UTC (permalink / raw)
  To: Yibin Ding
  Cc: djakov, rafael, yibin.ding01, niuzhiguo84, linux-pm, linux-kernel,
	Hao_hao.Wang, Ke.Wang

On Sat, Sep 14, 2024 at 06:24:35PM +0800, Yibin Ding wrote:
> 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.

But if no data is ever written this ends up being a memory leak.  Please
do not fix one bug just to introduce another one.

> Signed-off-by: Yibin Ding <Yibin.ding@unisoc.com>

also, your patches are not in a series together for some reason, and
there's no information below the --- line showing what changed from the
previous version where I pointed out this very problem :(

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-09-14 13:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-14 10:24 [PATCH V2 1/2] interconnect: Add character pointer initialization Yibin Ding
2024-09-14 13:56 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox