Re: [PATCH 1/9] workqueue: devres: Add device-managed allocate workqueue

From: Andy Shevchenko

Date: Mon Feb 23 2026 - 06:36:06 EST


On Mon, Feb 23, 2026 at 11:18:41AM +0100, Krzysztof Kozlowski wrote:
> On 23/02/2026 09:56, Andy Shevchenko wrote:
> > On Mon, Feb 23, 2026 at 08:27:29AM +0100, Krzysztof Kozlowski wrote:

...

> >> + ptr = devres_alloc(devm_destroy_workqueue, sizeof(*ptr), GFP_KERNEL);
> >> + if (!ptr)
> >> + return NULL;
> >> +
> >> + va_start(args, max_active);
> >> + wq = alloc_workqueue(fmt, flags, max_active, args);
> >> + va_end(args);
> >> + if (wq) {
> >> + *ptr = wq;
> >> + devres_add(dev, ptr);
> >> + } else {
> >> + devres_free(ptr);
> >> + }
> >
> > Why not using devm_add_action_or_reset()?
>
> Where? Here? How the code would be simpler, exactly?

static void devm_workqueue(struct device *dev, void *wq)
{
destroy_workqueue(wq);
}
...
{
...

va_start(args, max_active);
wq = alloc_workqueue(fmt, flags, max_active, args);
va_end(args);
if (!wq)
return NULL; // or ERR_PTR(-ENOMEM) on your choice

ret = devm_add_action_or_reset(dev, ..., wq);
if (ret)
return NULL; // ERR_PTR(ret) on your choice

return wq;
}

Compare to yours :-)

...

> >> +void devm_destroy_workqueue(struct device *dev, void *res)
> >> +{
> >> + destroy_workqueue(*(struct workqueue_struct **)res);
> >> +}
> >> +EXPORT_SYMBOL_GPL(devm_destroy_workqueue);
> >
> > Is this going to be used?
>
> It is not used in this patchset, but most of devm-allocators have the
> cleanup.

--
With Best Regards,
Andy Shevchenko