Re: [PATCH 3/9] power: supply: max77705: Free allocated workqueue and fix removal order

From: Andy Shevchenko

Date: Mon Feb 23 2026 - 04:00:13 EST


On Mon, Feb 23, 2026 at 08:27:31AM +0100, Krzysztof Kozlowski wrote:
> Use devm interface for allocating workqueue to fix two bugs at the same
> time:
>
> 1. Driver leaks the memory on remove(), because the workqueue is not
> destroyed.
>
> 2. Driver allocates workqueue and then registers interrupt handlers
> with devm interface. This means that probe error paths will not use a
> reversed order, but first the destroy workqueue and then, via devm
> release handlers, free the interrupt.
>
> The interrupt handler schedules work on this exact workqueue, thus if
> interrupt is hit in this short time window - after destroying
> workqueue, but before devm() frees the interrupt, the work scheduling
> will lead to use of freed memory.

...

> ret = devm_request_threaded_irq(dev, regmap_irq_get_virq(irq_data, MAX77705_CHGIN_I),
> NULL, max77705_chgin_irq,
> IRQF_TRIGGER_NONE,
> "chgin-irq", chg);
> - if (ret) {
> - dev_err_probe(dev, ret, "Failed to Request chgin IRQ\n");
> - goto destroy_wq;
> - }
> + if (ret)
> + return dev_err_probe(dev, ret, "Failed to Request chgin IRQ\n");

This should be just

return ret;


devm_*_irq() prints the message. No need to repeat this in the caller(s).

...

> ret = devm_request_threaded_irq(dev, regmap_irq_get_virq(irq_data, MAX77705_AICL_I),
> NULL, max77705_aicl_irq,
> IRQF_TRIGGER_NONE,
> "aicl-irq", chg);
> - if (ret) {
> - dev_err_probe(dev, ret, "Failed to Request aicl IRQ\n");
> - goto destroy_wq;
> - }
> + if (ret)
> + return dev_err_probe(dev, ret, "Failed to Request aicl IRQ\n");

Ditto.

--
With Best Regards,
Andy Shevchenko