Skip to contentSkip to conversation

irq: Fix uninitialized pointers

PATCH In review Gyeyoung Baek 2 participants 3 messages May 27, 2025 – Jun 12, 2025 IRQ

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 irq: Fix uninitialized pointers

Fix uninitialized ops member's pointers to avoid kernel Oops in irq_sim_request_resources().

---
 kernel/irq/irq_sim.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/irq/irq_sim.c +5 -1
index 1a3d483548e2..67fd1de5d197 100644
@@ -222,8 +222,12 @@ struct irq_domain *irq_domain_create_sim_full(struct fwnode_handle *fwnode,
 	work_ctx->pending = no_free_ptr(pending);
 	work_ctx->user_data = data;
 
-	if (ops)
+	if (ops) {
 		memcpy(&work_ctx->ops, ops, sizeof(*ops));
+	} else {
+		work_ctx->ops.irq_sim_irq_released = NULL;
+		work_ctx->ops.irq_sim_irq_requested = NULL;
+	}
 
 	return no_free_ptr(work_ctx)->domain;
 }
Signature · 1 line
2.43.0
#1 lore raw

On Tue, May 27 2025 at 18:35, Gyeyoung Baek wrote:

The subject line prefix is wrong. See

https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#patch-subject

Quoted 1 line

Fix uninitialized ops member's pointers to avoid kernel Oops in

You cannot fix an uninitialized pointer. You only can initialize it properly.

Quoted 1 line

irq_sim_request_resources().

No backticks required. fun() is clear on it's own.

Also please describe how this ends up with an oops in irq_sim_request_resources(). The point is that any dereference of an uninitialized pointer is resulting in a problem and it does not matter where.

Dereferencing an uninitialized pointer can cause an Ooops or worse it can call into some random code when the uninitialized memory contained a valid pointer, which is way harder to debug than a plain crash.

Quoted 4 lines

index 1a3d483548e2..67fd1de5d197 100644

kernel/irq/irq_sim.c struct irq_domain *irq_domain_create_sim_full(struct fwnode_handle *fwnode, · line 230

Quoted 10 lines
kernel/irq/irq_sim.c +5 -1
@@ -222,8 +222,12 @@ struct irq_domain *irq_domain_create_sim_full(struct fwnode_handle *fwnode,
 	work_ctx->pending = no_free_ptr(pending);
 	work_ctx->user_data = data;
 
-	if (ops)
+	if (ops) {
 		memcpy(&work_ctx->ops, ops, sizeof(*ops));
+	} else {
+		work_ctx->ops.irq_sim_irq_released = NULL;
+		work_ctx->ops.irq_sim_irq_requested = NULL;
+	}

The obvious fix is way more simple. Just allocate work_ctx with kzalloc() instead of kmalloc(), no?

Thanks,

tglx

#2 lore raw

Hi Thomas, thanks for your review.

Quoted 6 lines · Thomas Gleixner

On Tue, May 27 2025 at 18:35, Gyeyoung Baek wrote:

The subject line prefix is wrong. See

https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#patch-subject

Thank you for providing the guideline, I see now how to.

Quoted 4 lines
Quoted 1 line

Fix uninitialized ops member's pointers to avoid kernel Oops in

You cannot fix an uninitialized pointer. You only can initialize it properly.

Yes, I will update the subject to 'Initialize properly' in v2.

---

Quoted 4 lines

Also please describe how this ends up with an oops in irq_sim_request_resources(). The point is that any dereference of an uninitialized pointer is resulting in a problem and it does not matter where.

Yes, It looks good to just remove irq_sim_request_resources() from the commit message.

Quoted 3 lines

Dereferencing an uninitialized pointer can cause an Ooops or worse it can call into some random code when the uninitialized memory contained a valid pointer, which is way harder to debug than a plain crash.

Yes, then I will remove irq_sim_request_resources() from the commit message, and explain it consistently with the subject.

---

Quoted 10 lines

kernel/irq/irq_sim.c struct irq_domain *irq_domain_create_sim_full(struct fwnode_handle *fwnode, · line 230

Quoted 7 lines
kernel/irq/irq_sim.c +5 -1
-     if (ops)
+     if (ops) {
              memcpy(&work_ctx->ops, ops, sizeof(*ops));
+     } else {
+             work_ctx->ops.irq_sim_irq_released = NULL;
+             work_ctx->ops.irq_sim_irq_requested = NULL;
+     }

The obvious fix is way more simple. Just allocate work_ctx with kzalloc() instead of kmalloc(), no?

Yes, that's a much simpler and cleaner fix.
then I will send a v2 patch according to your reviews, Thank you.

--
Best Regards,
Gyeyoung