[PATCH net v4 3/5] net: dsa: microchip: Ensure a ksz_irq is initialized before freeing it

Bastien Curutchet (Schneider Electric) posted 5 patches 2 weeks ago
There is a newer version of this series
[PATCH net v4 3/5] net: dsa: microchip: Ensure a ksz_irq is initialized before freeing it
Posted by Bastien Curutchet (Schneider Electric) 2 weeks ago
If something goes wrong at setup, ksz_irq_free() can be called on
uninitialized ksz_irq (for example when ksz_ptp_irq_setup() fails). It
leads to freeing uninitialized IRQ numbers and/or domains.

Ensure that the ksz_irq is initialized before calling ksz_irq_free().

Fixes: cc13ab18b201 ("net: dsa: microchip: ptp: enable interrupt for timestamping")
Signed-off-by: Bastien Curutchet (Schneider Electric) <bastien.curutchet@bootlin.com>
--
Regarding the Fixes tag here, IMO before cc13ab18b201 it was safe to
not check the domain and the IRQ number because I don't see any path
where ksz_irq_free() would be called on a non-initialized ksz_irq
---
 drivers/net/dsa/microchip/ksz_common.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index c724f5af5d98bf3ff784e36393dd5b3fa7b37c13..a622416d966330187ee062b2f44051ddf4ce2a78 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -3078,9 +3078,12 @@ static int ksz_setup(struct dsa_switch *ds)
 		dsa_switch_for_each_user_port(dp, dev->ds)
 			ksz_ptp_irq_free(ds, dp->index);
 out_pirq:
-	if (dev->irq > 0)
-		dsa_switch_for_each_user_port(dp, dev->ds)
-			ksz_irq_free(&dev->ports[dp->index].pirq);
+	if (dev->irq > 0) {
+		dsa_switch_for_each_user_port(dp, dev->ds) {
+			if (dev->ports[dp->index].pirq.domain)
+				ksz_irq_free(&dev->ports[dp->index].pirq);
+		}
+	}
 out_girq:
 	if (dev->irq > 0)
 		ksz_irq_free(&dev->girq);

-- 
2.51.1