Skip to contentSkip to conversation

xen/irq: Propagate the error from init_one_desc_irq() in init_irq_data()

PATCH Superseded Julien Grall 4 participants 6 messages Nov 19, 2020 – Nov 28, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/irq: Propagate the error from init_one_desc_irq() in init_irq_data()

From: Julien Grall <[email protected]>

init_one_desc_irq() can return an error if it is unable to allocate memory. While this is unlikely to happen during boot (called from init_irq_data()), it is better to harden the code by propagting the return value.

Spotted by coverity.

CID: 106529

---
 xen/arch/arm/irq.c | 7 ++++++-
 xen/arch/x86/irq.c | 7 ++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)
xen/arch/arm/irq.c +6 -1
index 3877657a5277..279d221a2b85 100644
@@ -88,7 +88,12 @@ static int __init init_irq_data(void)
     for ( irq = NR_LOCAL_IRQS; irq < NR_IRQS; irq++ )
     {
         struct irq_desc *desc = irq_to_desc(irq);
-        init_one_irq_desc(desc);
+        int rc;
+
+        rc = init_one_irq_desc(desc);
+        if ( rc )
+            return rc;
+
         desc->irq = irq;
         desc->action  = NULL;
     }
xen/arch/x86/irq.c +6 -1
index 45966947919e..3ebd684415ac 100644
@@ -428,9 +428,14 @@ int __init init_irq_data(void)
 
     for ( irq = 0; irq < nr_irqs_gsi; irq++ )
     {
+        int rc;
+
         desc = irq_to_desc(irq);
         desc->irq = irq;
-        init_one_irq_desc(desc);
+
+        rc = init_one_irq_desc(desc);
+        if ( rc )
+            return rc;
     }
     for ( ; irq < nr_irqs; irq++ )
         irq_to_desc(irq)->irq = irq;
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 9 lines · Julien Grall

From: Julien Grall <[email protected]>

init_one_desc_irq() can return an error if it is unable to allocate memory. While this is unlikely to happen during boot (called from init_irq_data()), it is better to harden the code by propagting the return value.

Quoted 5 lines

Spotted by coverity.

CID: 106529

Cheers
Bertrand

Quoted 47 lines

---
xen/arch/arm/irq.c | 7 ++++++-
xen/arch/x86/irq.c | 7 ++++++-

2 files changed, 12 insertions(+), 2 deletions(-)
xen/arch/arm/irq.c +6 -1
index 3877657a5277..279d221a2b85 100644
@@ -88,7 +88,12 @@ static int __init init_irq_data(void)
    for ( irq = NR_LOCAL_IRQS; irq < NR_IRQS; irq++ )
    {
        struct irq_desc *desc = irq_to_desc(irq);
-        init_one_irq_desc(desc);
+        int rc;
+
+        rc = init_one_irq_desc(desc);
+        if ( rc )
+            return rc;
+
        desc->irq = irq;
        desc->action  = NULL;
    }
xen/arch/x86/irq.c +6 -1
index 45966947919e..3ebd684415ac 100644
@@ -428,9 +428,14 @@ int __init init_irq_data(void)
 
    for ( irq = 0; irq < nr_irqs_gsi; irq++ )
    {
+        int rc;
+
        desc = irq_to_desc(irq);
        desc->irq = irq;
-        init_one_irq_desc(desc);
+
+        rc = init_one_irq_desc(desc);
+        if ( rc )
+            return rc;
    }
    for ( ; irq < nr_irqs; irq++ )
        irq_to_desc(irq)->irq = irq;
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#2 lore raw
In reply to Julien Grall
Quoted 7 lines · Julien Grall

From: Julien Grall <[email protected]>

init_one_desc_irq() can return an error if it is unable to allocate memory. While this is unlikely to happen during boot (called from init_irq_data()), it is better to harden the code by propagting the return value.

Quoted 8 lines

Spotted by coverity.

CID: 106529

---
 xen/arch/x86/irq.c | 7 ++++++-

Fox x86:

Quoted 7 lines
 2 files changed, 12 insertions(+), 2 deletions(-)
xen/arch/arm/irq.c +0 -0
index 3877657a5277..279d221a2b85 100644

xen/arch/arm/irq.c static int __init init_irq_data(void) · line 93

Quoted 7 lines
xen/arch/arm/irq.c +3 -1
@@ -88,7 +88,12 @@ static int __init init_irq_data(void)
     for ( irq = NR_LOCAL_IRQS; irq < NR_IRQS; irq++ )
     {
         struct irq_desc *desc = irq_to_desc(irq);
-        init_one_irq_desc(desc);
+        int rc;
+
+        rc = init_one_irq_desc(desc);

You could init rc at definition.

Thanks, Roger.

#3 lore raw

Hi Roger,

Quoted 12 lines · Roger Pau Monné
Quoted 11 lines · Julien Grall

From: Julien Grall <[email protected]>

init_one_desc_irq() can return an error if it is unable to allocate memory. While this is unlikely to happen during boot (called from init_irq_data()), it is better to harden the code by propagting the return value.

Spotted by coverity.

CID: 106529

Quoted 7 lines
Quoted 4 lines
---
  xen/arch/x86/irq.c | 7 ++++++-

Fox x86:

Thank you!

Quoted 17 lines
Quoted 8 lines
  2 files changed, 12 insertions(+), 2 deletions(-)
xen/arch/arm/irq.c +0 -0
index 3877657a5277..279d221a2b85 100644

xen/arch/arm/irq.c static int __init init_irq_data(void) · line 93

Quoted 7 lines
xen/arch/arm/irq.c +3 -1
@@ -88,7 +88,12 @@ static int __init init_irq_data(void)
      for ( irq = NR_LOCAL_IRQS; irq < NR_IRQS; irq++ )
      {
          struct irq_desc *desc = irq_to_desc(irq);
-        init_one_irq_desc(desc);
+        int rc;
+
+        rc = init_one_irq_desc(desc);

You could init rc at definition.

I need to send a new version, so I have merged the two line together.

Cheers,

Signature · 1 line
Julien Grall
#4 lore raw
In reply to Julien Grall
Quoted 7 lines · Julien Grall

From: Julien Grall <[email protected]>

init_one_desc_irq() can return an error if it is unable to allocate memory. While this is unlikely to happen during boot (called from init_irq_data()), it is better to harden the code by propagting the return value.

Quoted 5 lines

Spotted by coverity.

CID: 106529

Hi Julien,

Thanks for the patch. I was about to commit it when I realized there is one more caller: xen/arch/arm/irq.c:init_local_irq_data

Should we change that too to check for the return error?

Quoted 46 lines
---
 xen/arch/arm/irq.c | 7 ++++++-
 xen/arch/x86/irq.c | 7 ++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)
xen/arch/arm/irq.c +6 -1
index 3877657a5277..279d221a2b85 100644
@@ -88,7 +88,12 @@ static int __init init_irq_data(void)
     for ( irq = NR_LOCAL_IRQS; irq < NR_IRQS; irq++ )
     {
         struct irq_desc *desc = irq_to_desc(irq);
-        init_one_irq_desc(desc);
+        int rc;
+
+        rc = init_one_irq_desc(desc);
+        if ( rc )
+            return rc;
+
         desc->irq = irq;
         desc->action  = NULL;
     }
xen/arch/x86/irq.c +6 -1
index 45966947919e..3ebd684415ac 100644
@@ -428,9 +428,14 @@ int __init init_irq_data(void)
 
     for ( irq = 0; irq < nr_irqs_gsi; irq++ )
     {
+        int rc;
+
         desc = irq_to_desc(irq);
         desc->irq = irq;
-        init_one_irq_desc(desc);
+
+        rc = init_one_irq_desc(desc);
+        if ( rc )
+            return rc;
     }
     for ( ; irq < nr_irqs; irq++ )
         irq_to_desc(irq)->irq = irq;
Signature · 1 line
2.17.1
#5 lore raw
Quoted 8 lines · Stefano Stabellini
Quoted 7 lines · Julien Grall

From: Julien Grall <[email protected]>

init_one_desc_irq() can return an error if it is unable to allocate memory. While this is unlikely to happen during boot (called from init_irq_data()), it is better to harden the code by propagting the return value.

Quoted 7 lines
Quoted 5 lines

Spotted by coverity.

CID: 106529

Hi Julien,

Hi Stefano,

Quoted 4 lines

Thanks for the patch. I was about to commit it when I realized there is one more caller: xen/arch/arm/irq.c:init_local_irq_data

Should we change that too to check for the return error?

We should change too. I will send a new version.

Cheers,

Signature · 1 line
Julien Grall