irqchip/tango: Add NULL check after memory operation
PATCH 1/1 irqchip/tango: Add NULL check after memory operation
Add NULL check after kzalloc operation.
Fix below issue reported by coccicheck ./drivers/irqchip/irq-tango.c:189:1-5: alloc with no test, possible model on line 193
--- drivers/irqchip/irq-tango.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/irqchip/irq-tango.c +2 -0
@@ -187,6 +187,8 @@ static int __init tangox_irq_init(void __iomem *base, struct resource *baseres,panic ("%pOFn: failed to get address" , node); chip =kzalloc (sizeof (*chip),GFP_KERNEL ); +if (!chip) +return -ENOMEM ; chip->ctl = res.start - baseres->start; chip->base = base;
Signature · 1 line
2.7.4
Quoted 17 lines · Hariprasad Kelam
Add NULL check after kzalloc operation.
Fix below issue reported by coccicheck ./drivers/irqchip/irq-tango.c:189:1-5: alloc with no test, possible model on line 193
Signed-off-by Hariprasad Kelam <[email protected]>--- drivers/irqchip/irq-tango.c | 2 ++ 1 file changed, 2 insertions(+)drivers/irqchip/irq-tango.c +0
-0
drivers/irqchip/irq-tango.c static int __init tangox_irq_init(void __iomem *base, struct resource *baseres, · line 194
Quoted 8 lines
drivers/irqchip/irq-tango.c +2
-0@@ -187,6 +187,8 @@ static int __init tangox_irq_init(void __iomem *base, struct resource *baseres,panic ("%pOFn: failed to get address" , node); chip =kzalloc (sizeof (*chip),GFP_KERNEL ); +if (!chip) +return -ENOMEM ; chip->ctl = res.start - baseres->start; chip->base = base;
Nothing checks the return value of that function, so bad things will still happen, only more confusing to debug. If you really want to "fix" this, you should either:
- Simply panic() like the other error cases. If anything here fails, the system will not work anyway.
- Replace the panic() calls with error returns and check the return value in tangox_of_irq_init(). The system will still end up unusable.
Signature · 1 line
Måns Rullgård