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

From: Danilo Krummrich

Date: Mon Feb 23 2026 - 05:36:37 EST


On Mon Feb 23, 2026 at 8:27 AM CET, Krzysztof Kozlowski wrote:
> +__printf(2, 5) struct workqueue_struct *
> +devm_alloc_workqueue(struct device *dev, const char *fmt, unsigned int flags,
> + int max_active, ...)
> +{
> + struct workqueue_struct **ptr, *wq;
> + va_list args;
> +
> + ptr = devres_alloc(devm_destroy_workqueue, sizeof(*ptr), GFP_KERNEL);

The function pointer passed to devres_alloc() is commonly named *_release().

> + 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);
> + }
> +
> + return wq;
> +}
> +EXPORT_SYMBOL_GPL(devm_alloc_workqueue);

<snip>

> +void devm_destroy_workqueue(struct device *dev, void *res)
> +{
> + destroy_workqueue(*(struct workqueue_struct **)res);
> +}
> +EXPORT_SYMBOL_GPL(devm_destroy_workqueue);

I assume you did not mean to export the release callback (which doesn't seem to
be useful), but a function that calls devres_destroy(), i.e. something analogous
to devm_remove_action().

If you don't actually need it, I would prefer not to add something that calls
devres_destroy() for now.