[PATCH 1/9] workqueue: devres: Add device-managed allocate workqueue
Krzysztof Kozlowski
krzk at kernel.org
Mon Feb 23 02:44:42 PST 2026
On 23/02/2026 11:36, Danilo Krummrich wrote:
> 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().
devm-helpers.h disagree :), but I understand poor patterns spread all
over. I will use the release name.
>
>> + 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.
Andy pointed out EXPORT is not actually needed, so I will just drop it.
Best regards,
Krzysztof
More information about the linux-arm-kernel
mailing list