Skip to contentSkip to conversation

powerpc: 8xx: fix a return value error in mpc8xx_pic_init

PATCH Applied Hangyu Hua 4 participants 9 messages Feb 23, 2022 – Mar 12, 2022

Subsystems (2)
lore
Share & tools
lore

Hangyu Hua

author
#0 lore raw

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.

Fixes cc76404feaed ("powerpc/8xx: Fix possible device node reference leak")
---
 arch/powerpc/platforms/8xx/pic.c | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/platforms/8xx/pic.c +1 -0
index f2ba837249d6..04a6abf14c29 100644
@@ -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
author
#1 lore raw

Ping?

Quoted 22 lines · Hangyu Hua

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.

Fixes cc76404feaed ("powerpc/8xx: Fix possible device node reference leak")
---
  arch/powerpc/platforms/8xx/pic.c | 1 +
  1 file changed, 1 insertion(+)
arch/powerpc/platforms/8xx/pic.c +1 -0
index f2ba837249d6..04a6abf14c29 100644
@@ -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;
Reviewed-by
#2 lore raw

Le 07/03/2022 à 02:41, Hangyu Hua a écrit :

Quoted 11 lines

Ping?

Quoted 8 lines · Hangyu Hua

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.

Fixes cc76404feaed ("powerpc/8xx: Fix possible device node reference

leak")

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
index f2ba837249d6..04a6abf14c29 100644
@@ -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;
#3 lore raw
In reply to Hangyu Hua

arch/powerpc/platforms/8xx/pic.c int __init mpc8xx_pic_init(void)

Quoted 15 lines · Hangyu Hua

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.

Fixes cc76404feaed ("powerpc/8xx: Fix possible device node reference leak")
---
 arch/powerpc/platforms/8xx/pic.c | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/platforms/8xx/pic.c +0 -0
index f2ba837249d6..04a6abf14c29 100644
@@ -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 -0
 	if (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

#4 lore raw

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 -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.

Fixes cc76404feaed ("powerpc/8xx: Fix possible device node reference leak")
---
  arch/powerpc/platforms/8xx/pic.c | 1 +
  1 file changed, 1 insertion(+)
arch/powerpc/platforms/8xx/pic.c +0 -0
index f2ba837249d6..04a6abf14c29 100644
@@ -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 -0
  	if (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() if irq_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

#5 lore raw
Quoted 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 -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.

Fixes cc76404feaed ("powerpc/8xx: Fix possible device node reference leak")
---
  arch/powerpc/platforms/8xx/pic.c | 1 +
  1 file changed, 1 insertion(+)
arch/powerpc/platforms/8xx/pic.c +0 -0
index f2ba837249d6..04a6abf14c29 100644
@@ -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 -0
  	if (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() if irq_domain_add_linear() fails.

Uh ...

If siu_reg is NULL, you get a serious problem when __do_irq() calls mpc8xx_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_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.

Yeah OK, that's becoming a bit of a larger cleanup. I'll take this patch as-is.

cheers

#6 lore raw

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 -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.

Fixes cc76404feaed ("powerpc/8xx: Fix possible device node reference leak")
---
   arch/powerpc/platforms/8xx/pic.c | 1 +
   1 file changed, 1 insertion(+)
arch/powerpc/platforms/8xx/pic.c +0 -0
index f2ba837249d6..04a6abf14c29 100644
@@ -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 -0
   	if (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.

Quoted 7 lines
Quoted 4 lines

Uh ...

If siu_reg is NULL, you get a serious problem when __do_irq() calls mpc8xx_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

#7 lore raw
Quoted 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 -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.

Fixes cc76404feaed ("powerpc/8xx: Fix possible device node reference leak")
---
   arch/powerpc/platforms/8xx/pic.c | 1 +
   1 file changed, 1 insertion(+)
arch/powerpc/platforms/8xx/pic.c +0 -0
index f2ba837249d6..04a6abf14c29 100644
@@ -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 -0
   	if (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() if irq_domain_add_linear() fails.

Uh ...

If siu_reg is NULL, you get a serious problem when __do_irq() calls mpc8xx_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 generic mpic_get_irq() which has a BUG_ON() in call mpic_primary is 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