Skip to contentSkip to conversation

irqchip/atmel-aic5: Free SMR cache on init failure

PATCH In review Yuho Choi 2 participants 3 messages May 13 – May 17

Subsystems (2)
lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH 1/1 irqchip/atmel-aic5: Free SMR cache on init failure

sama5d2_aic5_of_init() allocates the SMR cache before calling aic5_of_init(). If that fails, the cache is left allocated even though no IRQ domain was installed and the cache will not be used.

Free the cache on the failure path and clear the global pointer.

Fixes a50ac562ef48 ("irqchip/atmel-aic5: Handle suspend to RAM")
---
 drivers/irqchip/irq-atmel-aic5.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/irqchip/irq-atmel-aic5.c +10 -1
index 1f14b401f71d..58650eb16880 100644
@@ -358,13 +358,22 @@ static int __init sama5d2_aic5_of_init(struct device_node *node,
 				       struct device_node *parent)
 {
 #ifdef CONFIG_PM
+	int rc = 0;
 	smr_cache = kcalloc(DIV_ROUND_UP(NR_SAMA5D2_IRQS, 32) * 32,
 			    sizeof(*smr_cache), GFP_KERNEL);
 	if (!smr_cache)
 		return -ENOMEM;
-#endif
 
+	rc = aic5_of_init(node, parent, NR_SAMA5D2_IRQS);
+	if (rc) {
+		kfree(smr_cache);
+		smr_cache = NULL;
+	}
+
+	return rc;
+#else
 	return aic5_of_init(node, parent, NR_SAMA5D2_IRQS);
+#endif
 }
 IRQCHIP_DECLARE(sama5d2_aic5, "atmel,sama5d2-aic", sama5d2_aic5_of_init);
 
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 5 lines · Yuho Choi

sama5d2_aic5_of_init() allocates the SMR cache before calling aic5_of_init(). If that fails, the cache is left allocated even though no IRQ domain was installed and the cache will not be used.

Free the cache on the failure path and clear the global pointer.

No aic5 = no viable system to run on: I'm not sure it's worth considering the case.

Quoted 37 lines
Fixes a50ac562ef48 ("irqchip/atmel-aic5: Handle suspend to RAM")
---
  drivers/irqchip/irq-atmel-aic5.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
drivers/irqchip/irq-atmel-aic5.c +10 -2
index 1f14b401f71d..58650eb16880 100644
@@ -358,13 +358,22 @@ static int __init sama5d2_aic5_of_init(struct device_node *node,
                                        struct device_node *parent)
  {
  #ifdef CONFIG_PM
+       int rc = 0;
         smr_cache = kcalloc(DIV_ROUND_UP(NR_SAMA5D2_IRQS, 32) * 32,
                             sizeof(*smr_cache), GFP_KERNEL);
         if (!smr_cache)
                 return -ENOMEM;
-#endif
 
+       rc = aic5_of_init(node, parent, NR_SAMA5D2_IRQS);
+       if (rc) {
+               kfree(smr_cache);
+               smr_cache = NULL;
+       }
+
+       return rc;
+#else
         return aic5_of_init(node, parent, NR_SAMA5D2_IRQS);
+#endif
  }
  IRQCHIP_DECLARE(sama5d2_aic5, "atmel,sama5d2-aic", sama5d2_aic5_of_init);
 
--

2.43.0

author
#2 lore raw

Fair point. I submitted this from a general code hygiene perspective. Thanks for taking the time to review it.

Best regards,
Yuho Choi

Quoted 49 lines · Nicolas Ferre
Quoted 5 lines · Yuho Choi

sama5d2_aic5_of_init() allocates the SMR cache before calling aic5_of_init(). If that fails, the cache is left allocated even though no IRQ domain was installed and the cache will not be used.

Free the cache on the failure path and clear the global pointer.

No aic5 = no viable system to run on: I'm not sure it's worth considering the case.

Quoted 37 lines
Fixes a50ac562ef48 ("irqchip/atmel-aic5: Handle suspend to RAM")
---
  drivers/irqchip/irq-atmel-aic5.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
drivers/irqchip/irq-atmel-aic5.c +10 -2
index 1f14b401f71d..58650eb16880 100644
@@ -358,13 +358,22 @@ static int __init sama5d2_aic5_of_init(struct device_node *node,
                                        struct device_node *parent)
  {
  #ifdef CONFIG_PM
+       int rc = 0;
         smr_cache = kcalloc(DIV_ROUND_UP(NR_SAMA5D2_IRQS, 32) * 32,
                             sizeof(*smr_cache), GFP_KERNEL);
         if (!smr_cache)
                 return -ENOMEM;
-#endif
 
+       rc = aic5_of_init(node, parent, NR_SAMA5D2_IRQS);
+       if (rc) {
+               kfree(smr_cache);
+               smr_cache = NULL;
+       }
+
+       return rc;
+#else
         return aic5_of_init(node, parent, NR_SAMA5D2_IRQS);
+#endif
  }
  IRQCHIP_DECLARE(sama5d2_aic5, "atmel,sama5d2-aic", sama5d2_aic5_of_init);
 
--

2.43.0