powerpc: 8xx: fix a return value error in mpc8xx_pic_init
Subsystems (2)
PATCH 1/1 powerpc: 8xx: fix a return value error in mpc8xx_pic_init
mpc8xx_pic_init() should return -ENOMEM instead of 0 when irq_domain_add_linear() return NULL. This cause mpc8xx_pics_init to continue executing even if mpc8xx_pic_host is NULL.
--- arch/powerpc/platforms/8xx/pic.c | 1 + 1 file changed, 1 insertion(+)
arch/powerpc/platforms/8xx/pic.c +1 -0
@@ -153,6 +153,7 @@ int __init mpc8xx_pic_init(void)if (mpc8xx_pic_host ==NULL ) {printk (KERN_ERR "MPC8xx PIC: failed to allocate irq host!\n" ); ret = -ENOMEM ; + goto out; } ret =0 ;
Signature · 1 line
2.25.1
Ping?
Quoted 22 lines · Hangyu Hua
mpc8xx_pic_init()should return-ENOMEMinstead of 0 whenirq_domain_add_linear()return NULL. This causempc8xx_pics_initto continue executing even ifmpc8xx_pic_hostis NULL.Fixes cc76404feaed ("powerpc/8xx: Fix possible device node reference leak")Signed-off-by Hangyu Hua <[email protected]>--- arch/powerpc/platforms/8xx/pic.c | 1 + 1 file changed, 1 insertion(+)arch/powerpc/platforms/8xx/pic.c +1
-0@@ -153,6 +153,7 @@ int __init mpc8xx_pic_init(void)if (mpc8xx_pic_host ==NULL ) {printk (KERN_ERR "MPC8xx PIC: failed to allocate irq host!\n" ); ret = -ENOMEM ; + goto out; } ret =0 ;
Christophe Leroy
Reviewed-byLe 07/03/2022 à 02:41, Hangyu Hua a écrit :
Quoted 11 lines
Ping?
Quoted 8 lines · Hangyu Hua
mpc8xx_pic_init()should return-ENOMEMinstead of 0 whenirq_domain_add_linear()return NULL. This causempc8xx_pics_initto continue
executing even ifmpc8xx_pic_hostis NULL.Fixes cc76404feaed ("powerpc/8xx: Fix possible device node referenceleak")
Signed-off-by Hangyu Hua <[email protected]>
Quoted 16 lines
Quoted 16 lines
---
arch/powerpc/platforms/8xx/pic.c| 1 +1 file changed, 1 insertion(+)arch/powerpc/platforms/8xx/pic.c +1
-0@@ -153,6 +153,7 @@ int __init mpc8xx_pic_init(void) if (mpc8xx_pic_host == NULL) { printk(KERN_ERR "MPC8xx PIC: failed to allocate irq host!\n"); ret = -ENOMEM; + goto out; } ret = 0;
Michael Ellerman
reviewerarch/powerpc/platforms/8xx/pic.c int __init mpc8xx_pic_init(void)
Quoted 15 lines · Hangyu Hua
mpc8xx_pic_init()should return-ENOMEMinstead of 0 whenirq_domain_add_linear()return NULL. This causempc8xx_pics_initto continue executing even ifmpc8xx_pic_hostis NULL.Fixes cc76404feaed ("powerpc/8xx: Fix possible device node reference leak")Signed-off-by Hangyu Hua <[email protected]>--- arch/powerpc/platforms/8xx/pic.c | 1 + 1 file changed, 1 insertion(+)arch/powerpc/platforms/8xx/pic.c +0
-0@@ -153,6 +153,7 @@ int __init mpc8xx_pic_init(void)
Expanding the context:
siu_reg = ioremap(res.start, resource_size(&res));
if (siu_reg == NULL) {
ret = -EINVAL;
goto out;
}
mpc8xx_pic_host = irq_domain_add_linear(np, 64, &mpc8xx_pic_host_ops, NULL);arch/powerpc/platforms/8xx/pic.c int __init mpc8xx_pic_init(void) · line 159
Quoted 8 lines
arch/powerpc/platforms/8xx/pic.c +1
-0if (mpc8xx_pic_host ==NULL ) {printk (KERN_ERR "MPC8xx PIC: failed to allocate irq host!\n" ); ret = -ENOMEM ; + goto out; } ret =0 ;
out:
of_node_put(np); return ret; }
Proper error cleanup should also undo the ioremap() if irq_domain_add_linear() fails.
cheers
Le 09/03/2022 à 04:24, Michael Ellerman a écrit :
Quoted 35 lines
arch/powerpc/platforms/8xx/pic.c int __init mpc8xx_pic_init(void)
Quoted 15 lines · Hangyu Hua
mpc8xx_pic_init()should return-ENOMEMinstead of 0 whenirq_domain_add_linear()return NULL. This causempc8xx_pics_initto continue executing even ifmpc8xx_pic_hostis NULL.Fixes cc76404feaed ("powerpc/8xx: Fix possible device node reference leak")Signed-off-by Hangyu Hua <[email protected]>--- arch/powerpc/platforms/8xx/pic.c | 1 + 1 file changed, 1 insertion(+)arch/powerpc/platforms/8xx/pic.c +0
-0@@ -153,6 +153,7 @@ int __init mpc8xx_pic_init(void)Expanding the context:
siu_reg = ioremap(res.start, resource_size(&res)); if (siu_reg == NULL) { ret = -EINVAL; goto out; } mpc8xx_pic_host = irq_domain_add_linear(np, 64, &mpc8xx_pic_host_ops, NULL);arch/powerpc/platforms/8xx/pic.c int __init mpc8xx_pic_init(void) · line 159
Quoted 8 lines
arch/powerpc/platforms/8xx/pic.c +1
-0if (mpc8xx_pic_host ==NULL ) {printk (KERN_ERR "MPC8xx PIC: failed to allocate irq host!\n" ); ret = -ENOMEM ; + goto out; } ret =0 ;out:
Quoted 6 lines
of_node_put(np); return ret; }Proper error cleanup should also undo the
ioremap()ifirq_domain_add_linear()fails.
Uh ...
If siu_reg is NULL, you get a serious problem when __do_irq() calls mpc8xx_get_irq()
unsigned int mpc8xx_get_irq(void)
{
int irq;
/* For MPC8xx, read the SIVEC register and shift the bits down
* to get the irq number.
*/
irq = in_be32(&siu_reg->sc_sivec) >> 26;
if (irq == PIC_VEC_SPURRIOUS)
return 0;
return irq_linear_revmap(mpc8xx_pic_host, irq);}
So I'll leave siu_reg as is even if irq_domain_add_linear() fails.
Whatever, if we do something about that it should be done in another patch I think.
Christophe
Michael Ellerman
reviewerQuoted 40 lines · Christophe Leroy
Le 09/03/2022 à 04:24, Michael Ellerman a écrit :
Quoted 39 lines
arch/powerpc/platforms/8xx/pic.c int __init mpc8xx_pic_init(void)
Quoted 15 lines · Hangyu Hua
mpc8xx_pic_init()should return-ENOMEMinstead of 0 whenirq_domain_add_linear()return NULL. This causempc8xx_pics_initto continue executing even ifmpc8xx_pic_hostis NULL.Fixes cc76404feaed ("powerpc/8xx: Fix possible device node reference leak")Signed-off-by Hangyu Hua <[email protected]>--- arch/powerpc/platforms/8xx/pic.c | 1 + 1 file changed, 1 insertion(+)arch/powerpc/platforms/8xx/pic.c +0
-0@@ -153,6 +153,7 @@ int __init mpc8xx_pic_init(void)Expanding the context:
siu_reg = ioremap(res.start, resource_size(&res)); if (siu_reg == NULL) { ret = -EINVAL; goto out; } mpc8xx_pic_host = irq_domain_add_linear(np, 64, &mpc8xx_pic_host_ops, NULL);arch/powerpc/platforms/8xx/pic.c int __init mpc8xx_pic_init(void) · line 159
Quoted 8 lines
arch/powerpc/platforms/8xx/pic.c +1
-0if (mpc8xx_pic_host ==NULL ) {printk (KERN_ERR "MPC8xx PIC: failed to allocate irq host!\n" ); ret = -ENOMEM ; + goto out; } ret =0 ;out:
of_node_put(np); return ret; }
Quoted 7 lines
Quoted 2 lines
Proper error cleanup should also undo the
ioremap()ifirq_domain_add_linear()fails.Uh ...
If
siu_regis NULL, you get a serious problem when__do_irq()callsmpc8xx_get_irq()
Arguably it shouldn't be assigned to ppc_md.get_irq unless mpc8xx_pic_init() succeeds. See eg. xics_init().
Quoted 14 lines
unsigned int
mpc8xx_get_irq(void){ int irq; /* For MPC8xx, read the SIVEC register and shift the bits down * to get the irq number. */ irq = in_be32(&siu_reg->sc_sivec) >> 26; if (irq == PIC_VEC_SPURRIOUS) return 0; return irq_linear_revmap(mpc8xx_pic_host, irq);
Quoted 7 lines
}
So I'll leave
siu_regas is even ifirq_domain_add_linear()fails.Whatever, if we do something about that it should be done in another patch I think.
Yeah OK, that's becoming a bit of a larger cleanup. I'll take this patch as-is.
cheers
Le 09/03/2022 à 11:46, Michael Ellerman a écrit :
Quoted 44 lines
Quoted 43 lines · Christophe Leroy
Le 09/03/2022 à 04:24, Michael Ellerman a écrit :
Quoted 41 lines
arch/powerpc/platforms/8xx/pic.c int __init mpc8xx_pic_init(void)
Quoted 15 lines · Hangyu Hua
mpc8xx_pic_init()should return-ENOMEMinstead of 0 whenirq_domain_add_linear()return NULL. This causempc8xx_pics_initto continue executing even ifmpc8xx_pic_hostis NULL.Fixes cc76404feaed ("powerpc/8xx: Fix possible device node reference leak")Signed-off-by Hangyu Hua <[email protected]>--- arch/powerpc/platforms/8xx/pic.c | 1 + 1 file changed, 1 insertion(+)arch/powerpc/platforms/8xx/pic.c +0
-0@@ -153,6 +153,7 @@ int __init mpc8xx_pic_init(void)Expanding the context:
siu_reg = ioremap(res.start, resource_size(&res)); if (siu_reg == NULL) { ret = -EINVAL; goto out; } mpc8xx_pic_host = irq_domain_add_linear(np, 64, &mpc8xx_pic_host_ops, NULL);arch/powerpc/platforms/8xx/pic.c int __init mpc8xx_pic_init(void) · line 159
Quoted 8 lines
arch/powerpc/platforms/8xx/pic.c +1
-0if (mpc8xx_pic_host ==NULL ) {printk (KERN_ERR "MPC8xx PIC: failed to allocate irq host!\n" ); ret = -ENOMEM ; + goto out; } ret =0 ;out:
of_node_put(np); return ret; }Proper error cleanup should also undo the
ioremap()ifirq_domain_add_linear()fails.
Quoted 7 lines
Quoted 4 lines
Uh ...
If
siu_regis NULL, you get a serious problem when__do_irq()callsmpc8xx_get_irq()Arguably it shouldn't be assigned to ppc_md.get_irq unless
mpc8xx_pic_init()succeeds. See eg.xics_init().
I agree with that, but it's a huge work I guess. Most platforms set .get_irq in ppc_md() at buildtime. See the generic mpic_get_irq() which has a BUG_ON() in call mpic_primary is NULL. There are 50 platforms with buildtime assignment.
That would however be a good opportunity to switch get_irq() to a static call. I'll open a github issue to follow it.
Christophe
Michael Ellerman
reviewerQuoted 50 lines · Christophe Leroy
Le 09/03/2022 à 11:46, Michael Ellerman a écrit :
Quoted 49 lines
Quoted 47 lines · Christophe Leroy
Le 09/03/2022 à 04:24, Michael Ellerman a écrit :
Quoted 35 lines
arch/powerpc/platforms/8xx/pic.c int __init mpc8xx_pic_init(void)
Quoted 15 lines · Hangyu Hua
mpc8xx_pic_init()should return-ENOMEMinstead of 0 whenirq_domain_add_linear()return NULL. This causempc8xx_pics_initto continue executing even ifmpc8xx_pic_hostis NULL.Fixes cc76404feaed ("powerpc/8xx: Fix possible device node reference leak")Signed-off-by Hangyu Hua <[email protected]>--- arch/powerpc/platforms/8xx/pic.c | 1 + 1 file changed, 1 insertion(+)arch/powerpc/platforms/8xx/pic.c +0
-0@@ -153,6 +153,7 @@ int __init mpc8xx_pic_init(void)Expanding the context:
siu_reg = ioremap(res.start, resource_size(&res)); if (siu_reg == NULL) { ret = -EINVAL; goto out; } mpc8xx_pic_host = irq_domain_add_linear(np, 64, &mpc8xx_pic_host_ops, NULL);arch/powerpc/platforms/8xx/pic.c int __init mpc8xx_pic_init(void) · line 159
Quoted 8 lines
arch/powerpc/platforms/8xx/pic.c +1
-0if (mpc8xx_pic_host ==NULL ) {printk (KERN_ERR "MPC8xx PIC: failed to allocate irq host!\n" ); ret = -ENOMEM ; + goto out; } ret =0 ;out:
Quoted 6 lines
of_node_put(np); return ret; }Proper error cleanup should also undo the
ioremap()ifirq_domain_add_linear()fails.Uh ...
If
siu_regis NULL, you get a serious problem when__do_irq()callsmpc8xx_get_irq()
Quoted 7 lines
Quoted 2 lines
Arguably it shouldn't be assigned to ppc_md.get_irq unless
mpc8xx_pic_init()succeeds. See eg.xics_init().I agree with that, but it's a huge work I guess. Most platforms set .get_irq in
ppc_md()at buildtime. See the genericmpic_get_irq()which has aBUG_ON()in callmpic_primaryis NULL. There are 50 platforms with buildtime assignment.
Yes I agree. And __do_irq() will just oops if ppc_md.get_irq() is NULL, so it's a bit of a mess.
Quoted 2 lines
That would however be a good opportunity to switch
get_irq()to a static call. I'll open a github issue to follow it.
Thanks.
cheers
Michael Ellerman
AppliedQuoted 5 lines · Hangyu Hua
mpc8xx_pic_init()should return-ENOMEMinstead of 0 whenirq_domain_add_linear()return NULL. This causempc8xx_pics_initto continue executing even ifmpc8xx_pic_hostis NULL.
Applied to powerpc/next.
[1/1] powerpc: 8xx: fix a return value error in mpc8xx_pic_init
https://git.kernel.org/powerpc/c/3fd46e551f67f4303c3276a0d6cd20baf2d192c4
cheers