mv88e639x_pcs_setup_irq() may successfully request an irq. If enabling the checker fails, the PCS structure is freed without freeing the irq, potentially causing a use-after-free. Free the irq on error path if it was successfully requested. Found by a self-developed static analysis tool and compile- test passed. Fixes: e5b732a275f5 ("net: dsa: mv88e6xxx: convert 88e639x to phylink_pcs") Signed-off-by: Wanhui Fu <fuwh…@163.com> --- drivers/net/dsa/mv88e6xxx/pcs-639x.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/mv88e6xxx/pcs-639x.c b/drivers/net/dsa/mv88e6xxx/pcs-639x.c index a5fd187a7bf3..299b4b4b3243 100644 --- a/drivers/net/dsa/mv88e6xxx/pcs-639x.c +++ b/drivers/net/dsa/mv88e6xxx/pcs-639x.c @@ -581,12 +581,15 @@ static int mv88e6390_pcs_init(struct mv88e6xxx_chip *chip, int port) */ err = mv88e6390_pcs_enable_checker(mpcs); if (err) - goto err_free; + goto err_free_irq; chip->ports[port].pcs_private = mpcs; return 0; +err_free_irq: + if (mpcs->irq) + free_irq(mpcs->irq, mpcs); err_free: kfree(mpcs); return err;
-- 2.25.1