Skip to contentSkip to conversation

workqueue: Don't call va_start / va_end twice

PATCH Applied Matthew Brost 2 participants 2 messages Aug 20, 2024 Workqueue

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 workqueue: Don't call va_start / va_end twice

Calling va_start / va_end multiple times is undefined and causes problems with certain compiler / platforms.

Change alloc_ordered_workqueue_lockdep_map to a macro and updated __alloc_workqueue to take a va_list argument.

Cc Sergey Senozhatsky <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Lai Jiangshan <[email protected]>
---
 include/linux/workqueue.h | 16 ++--------------
 kernel/workqueue.c        |  6 +-----
 2 files changed, 3 insertions(+), 19 deletions(-)
include/linux/workqueue.h +2 -14
index 8ccbf510880b..57a49cc3976a 100644
@@ -543,20 +543,8 @@ alloc_workqueue_lockdep_map(const char *fmt, unsigned int flags, int max_active,
  * RETURNS:
  * Pointer to the allocated workqueue on success, %NULL on failure.
  */
-__printf(1, 4) static inline struct workqueue_struct *
-alloc_ordered_workqueue_lockdep_map(const char *fmt, unsigned int flags,
-				    struct lockdep_map *lockdep_map, ...)
-{
-	struct workqueue_struct *wq;
-	va_list args;
-
-	va_start(args, lockdep_map);
-	wq = alloc_workqueue_lockdep_map(fmt, WQ_UNBOUND | __WQ_ORDERED | flags,
-					 1, lockdep_map, args);
-	va_end(args);
-
-	return wq;
-}
+#define alloc_ordered_workqueue_lockdep_map(fmt, flags, lockdep_map, args...)	\
+	alloc_workqueue_lockdep_map(fmt, WQ_UNBOUND | __WQ_ORDERED | (flags), 1, lockdep_map, ##args)
 #endif
 
 /**
kernel/workqueue.c +1 -5
index f4b50a995e99..4824056b0a0e 100644
@@ -5619,12 +5619,10 @@ static void wq_adjust_max_active(struct workqueue_struct *wq)
 	} while (activated);
 }
 
-__printf(1, 4)
 static struct workqueue_struct *__alloc_workqueue(const char *fmt,
 						  unsigned int flags,
-						  int max_active, ...)
+						  int max_active, va_list args)
 {
-	va_list args;
 	struct workqueue_struct *wq;
 	size_t wq_size;
 	int name_len;
@@ -5656,9 +5654,7 @@ static struct workqueue_struct *__alloc_workqueue(const char *fmt,
 			goto err_free_wq;
 	}
 
-	va_start(args, max_active);
 	name_len = vsnprintf(wq->name, sizeof(wq->name), fmt, args);
-	va_end(args);
 
 	if (name_len >= WQ_NAME_LEN)
 		pr_warn_once("workqueue: name exceeds WQ_NAME_LEN. Truncating to: %s\n",
Signature · 1 line
2.34.1
maintainer Applied
#1 lore raw
Quoted 10 lines · Matthew Brost

Calling va_start / va_end multiple times is undefined and causes problems with certain compiler / platforms.

Change alloc_ordered_workqueue_lockdep_map to a macro and updated __alloc_workqueue to take a va_list argument.

Cc Sergey Senozhatsky <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Lai Jiangshan <[email protected]>

Applied to wq/for-6.12.

Thanks.

Signature · 1 line
tejun