Skip to contentSkip to conversation

fs: proc: Add error checking for d_hash_and_lookup()

PATCH In review Wang Ming 2 participants 2 messages Jul 13, 2023

Subsystems (2)
lore
Share & tools
lore

Wang Ming

author
#0 lore raw

PATCH 1/1 fs: proc: Add error checking for d_hash_and_lookup()

In case of failure, d_hash_and_lookup() returns NULL or an error pointer. The proc_fill_cache() needs to add the handling of the error pointer returned by d_hash_and_lookup().

---
 fs/proc/base.c | 2 ++
 1 file changed, 2 insertions(+)
fs/proc/base.c +2 -0
index bbc998fd2a2f..4c0e8329b318 100644
@@ -2071,6 +2071,8 @@ bool proc_fill_cache(struct file *file, struct dir_context *ctx,
 	ino_t ino = 1;
 
 	child = d_hash_and_lookup(dir, &qname);
+	if (IS_ERR(child))
+		goto end_instantiate;
 	if (!child) {
 		DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
 		child = d_alloc_parallel(dir, &qname, &wq);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 14 lines · Wang Ming

In case of failure, d_hash_and_lookup() returns NULL or an error pointer. The proc_fill_cache() needs to add the handling of the error pointer returned by d_hash_and_lookup().

---
 fs/proc/base.c | 2 ++
 1 file changed, 2 insertions(+)
fs/proc/base.c +0 -0
index bbc998fd2a2f..4c0e8329b318 100644

fs/proc/base.c bool proc_fill_cache(struct file *file, struct dir_context *ctx, · line 2075

Quoted 5 lines
fs/proc/base.c +2 -0
@@ -2071,6 +2071,8 @@ bool proc_fill_cache(struct file *file, struct dir_context *ctx,
 	ino_t ino = 1;
 
 	child = d_hash_and_lookup(dir, &qname);
+	if (IS_ERR(child))
+		goto end_instantiate;

As procfs doesn't have a separate dentry hash function this doesn't make much sense. It will always be either NULL or valid.