From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E15DA380FE7 for ; Tue, 14 Jul 2026 11:42:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784029329; cv=none; b=ektogCtKb/oUpiFI3jm8mOHY7tQ8eG7B7+SVYiEBWwfO/ZF62oOxkwlOpLHXZCtTfZ7JqUSrCdoC6AqoRhMMq+Mis3TKzofeT2KanHX3fcE8+NI5xKEs7IxUVPs7cYIK/ht5tED8FqA6Ba2rhzskGH7zC595W3YkyjGygZhvAHs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784029329; c=relaxed/simple; bh=IUQTz2+psDeV1/AxvWu1Lsau7o6+qUlb/z/Goewyy10=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=n5SWRmjV4OCnrojES5650WzafeDVEVzp2wbB62vbOesii6K+8q69kv+VQOk0cXmHSNkoGkkM+D2wWV3U3i1jBtnIxZEtpqrowX+oiy8htV7ezPn3vIFzpm7e2mveJLsXh/5Alk6Twr0/y+QO/7SJetw9j1uHKCA1xwFkmHC0s2o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=oeGQrkUQ; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="oeGQrkUQ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=qv0L7we4jR4Ig+KGVqf/QIewzjKaDetknOtoVRS+Pd0=; b=oeGQrkUQBepuWZw0vRhV7xNFub /2wiLkYLzdAH/RXXR6AaC+Bn8ATW9OUhWQKtgZoe/e9OE7/QZ9nYspL2Vr+wMGWLiXxdHQusx0UAN A4gF3BeSI1rA9Uuy4gBrgl2Qrsm4k+/xga0hPARggxr+875G3EMoZXJmE8Vw+8iM6CXPuUr4grjlL Tibe2R/0zihAIlcJkIoUYCb9ZgD57m/P98CAErTtlURnurvemZQQB6ZZuoWSzM/K2rNl1Ccm6Sk4b 6zSl81ybSR6ufIxZQqIDSs8VVNowXjCXi8hHgyVo4hos3fDPPeTYq/j9cFXTBXiMHjKVagIIchliH fDuHBd3A==; Received: from authenticated-user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1wjbWV-002FZZ-1N; Tue, 14 Jul 2026 11:42:03 +0000 From: Breno Leitao Date: Tue, 14 Jul 2026 04:41:49 -0700 Subject: [PATCH RFC 3/3] workqueue: factor out alloc_and_link_percpu_pwqs() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260714-tejun1-v1-3-024d59241386@debian.org> References: <20260714-tejun1-v1-0-024d59241386@debian.org> In-Reply-To: <20260714-tejun1-v1-0-024d59241386@debian.org> To: Tejun Heo , Lai Jiangshan Cc: linux-kernel@vger.kernel.org, marco.crivellari@suse.com, frederic@kernel.org, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.16-dev-d5d98 X-Developer-Signature: v=1; a=openpgp-sha256; l=2170; i=leitao@debian.org; h=from:subject:message-id; bh=IUQTz2+psDeV1/AxvWu1Lsau7o6+qUlb/z/Goewyy10=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqViB9gIE8W7oGcqx2eOi/CLNTej1442Gi1my7p tYlt2eilPuJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCalYgfQAKCRA1o5Of/Hh3 bU5vD/0RmxD6vbahzIDh6gS9VG0INB7bDstGuVgC3xyj7arxfxxHDALEwKta00GiN1Ydia67F4x ZDafZQ5yhgGrQ2KTtow8YWcLba0Do2/FYZsNxHXAGdK6ioe23THT/uWK92GN8ci15EE5rvgFnYv crrjBjaHQ4AL86HXxS+L4kLX3FL/JptUhrCV3Wyg+jAZu3Sz30utaHXrmTO4u2hcNQWg0vItOiS VaITOI0aeRmc95dL70hS3+BKThXWZ2e0LbxRSwSaXZbQHg5w0acpc6+x/iA/5DOD86tMcDH/Nfx NH1/XNEGnhlmyFywQwdJhCvikuHKVGNN8+xPVrzvFPaY+kApWuB59j6luAzVpNCvCX+H+ugr7Du HMwE2EnninUZFSldmDxruKXze32PUjfeeoEGoi5xqsupewfk6ewQzJNMkY+ZHzJ3wk+UpIy8uQs odnRcYwBRN5jN+pM4QC8KM+xiG4M7mPkk9upM34sYpggcgoh0Dzf2kS5MHibWvLlSjr7aiD0OZJ TS942OxjCVd0Rs1BNsYth83bVVq0+71BhVBT97dB2KM60iPxkW8FYBhtLUeLXctEkHC7VFWDerk aV4GLsrUGDwDSEB2JlRIvbqWJcEQvQqdgw+Kbdc2R/oD6VHvnSmNByltV0DNyv+pkuOO1iSsBQl msQrEEczLvQfY/g== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Move the per-cpu pwq allocation loop out of alloc_and_link_pwqs() into a helper. The inner allocation-failure path now returns -ENOMEM and the caller jumps to the existing enomem cleanup, equivalent to the previous goto. Now that the per-cpu branch returns a value through the helper, the per-cpu, ordered and unbound cases can share a single error-handling tail. Turn the separate per-cpu block and the ordered/unbound if/else into one if/else-if/else chain, dropping the early return and the duplicated goto. No functional change. Signed-off-by: Breno Leitao --- kernel/workqueue.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 50baf4fe5fcf5..411e4bd105576 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -5689,6 +5689,24 @@ static void unbound_wq_update_pwq(struct workqueue_struct *wq, int cpu) put_pwq_unlocked(old_pwq); } +static int alloc_and_link_percpu_pwqs(struct workqueue_struct *wq) +{ + int cpu; + + for_each_possible_cpu(cpu) { + struct pool_workqueue **pwq_p = per_cpu_ptr(wq->cpu_pwq, cpu); + + *pwq_p = alloc_pwq(wq, cpu, NULL); + if (!*pwq_p) + return -ENOMEM; + + mutex_lock(&wq->mutex); + link_pwq(*pwq_p); + mutex_unlock(&wq->mutex); + } + return 0; +} + static int alloc_and_link_pwqs(struct workqueue_struct *wq) { bool highpri = wq->flags & WQ_HIGHPRI; @@ -5701,21 +5719,8 @@ static int alloc_and_link_pwqs(struct workqueue_struct *wq) goto enomem; if (!(wq->flags & WQ_UNBOUND)) { - for_each_possible_cpu(cpu) { - struct pool_workqueue **pwq_p = per_cpu_ptr(wq->cpu_pwq, cpu); - - *pwq_p = alloc_pwq(wq, cpu, NULL); - if (!*pwq_p) - goto enomem; - - mutex_lock(&wq->mutex); - link_pwq(*pwq_p); - mutex_unlock(&wq->mutex); - } - return 0; - } - - if (wq->flags & __WQ_ORDERED) { + ret = alloc_and_link_percpu_pwqs(wq); + } else if (wq->flags & __WQ_ORDERED) { struct pool_workqueue *dfl_pwq; ret = apply_workqueue_attrs_locked(wq, ordered_wq_attrs[highpri]); -- 2.53.0-Meta