From nobody Tue Apr 7 02:34:18 2026 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8005333E373 for ; Mon, 16 Mar 2026 18:03:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773684194; cv=none; b=ntu4XY6K19UclRmw8+RzRts6yrip8d5dX5qtlhY+xoSJ6aPaWMTzf6tXb5ZNkK2HaGM42J5Bm40rgZBp15tJRqTisddsendctioAPuzIJqKdSG+Gyz0RbWr/D2BPMUV32Cg/dekb4pm2OXOzXkbGgewu9H1seJl3t9M+eQpjWlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773684194; c=relaxed/simple; bh=1sitTvK/wF+qBAyQZ88ziQo/+GRDzDN48qgf/7fqFf0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=EvoEy82xmAcLDVxSza4DFwvUrOF0v/jHBfBH3rwSl6xBsftBdVEsTsyZwcIX4R7RTWOG53gPdLoxjIzlReTZkyG8cknYa/9b7EcCXHRAMn7+g/d/9hKFg8JCCRTCUfrWRe6bhsfes27sAkahhv411HIUXgfqEkGEh8tz5nV075g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=S5bOGY3o; arc=none smtp.client-ip=209.85.215.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="S5bOGY3o" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-c7382731edfso3419671a12.1 for ; Mon, 16 Mar 2026 11:03:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773684191; x=1774288991; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=p7WvB4XJ/puKUqH47jtR6TlayFTmh5yeLwAuJFAvG2M=; b=S5bOGY3o5NmGbvInXewBmdYO0FwAYVVc7vpAnzBNSEdMhMUPWOufaWzN8VyHis7EXC igkniCTBc5CfHpGaTJGG/Xmkfx3Dwqf/W6PqDae+TfRRMGPJu6wcGIU7qzNB2ncoApvo YN+qSL+uy8O8GZWD7MJ0eyr4mN9aIELm+LQNzR6YSAANumc3b059rZpD6FniNC8ZHaCl pV9/FQnz+4SkIg6KauVRiVcgHyrClcnC07Np2eC9ST+vTo2gY/P+6FrBD7aY93iiNziK thIb1LPBInkxxQmuVDxTAExqrGyztwZB5ClAziMs6JAMPyoIvxKzyVCFH+aHN1ZCtLG6 SL/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773684191; x=1774288991; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=p7WvB4XJ/puKUqH47jtR6TlayFTmh5yeLwAuJFAvG2M=; b=nasZQRCplcqABqYW+C6XyeH73o/Sx1pyzCLxlSOFyMjvxVIa9PEMRffizz/mKBKT1Z VTxWTbtGQT/tKuj6zVyMxuaQhImGHhfaU939vSP7JZVNb0+gq7giV2whfnSCcWuvUIKz xDR9guJpZ9kTUTJ33QWS1B1NG4bPF/XNtPkzXnmd/qnsNlz2KO00l7YjsuDi3bOG4UpQ eGNcxyExx3bJForoge157inhkTkgkZBE2C5oiEuuly9d7gsb1W5Sqj5av8c4Gfhjyp5q FwCuMPIvbME/UXZrG/bGeGqrHr3dahfIyvjjiYVMOFhUfRro4GvcR1n/6Nj3AtgofBvv +rEg== X-Gm-Message-State: AOJu0YxG+K7PKK6VjoJhhbmqhJhXp3MdDkIhTLBl1uMN6WrZm/yErEJ8 dBGrpGaf5B4BnfkKBLLr94rWl8YZxEYaQuWxoYVr5tZGXpAoj1pOF01jzw/YwKiZFV1I6Q== X-Gm-Gg: ATEYQzz96guuH1wTZ1AfL6DOG9Q4x0PzLLxXzudiJzvfNZuzPmdngIMU0IPvaPwf412 +1GOWf9Eh8l9asPYn8xTnywkYt7yrHEpXfrhFs978VuWKxbK5LtQt9wU4B4zIdOI3xg1wGte2Tk MHmZh2uOjmORbccAwI4wExjzvLA6orOGrZlp2XlENL9MpnmFREBKkvU39F8xJaTuBaOWEfe6v+t HFNKUKokqOTp31h7nPbTMAaKbrZK7Gd9kbFi21upTooKcQ7XusEisHp2L3fW6RAFYNC4RZmVwmb URCOVUhCXkxrb+s9WD6E4DlMLCFTQFSADaP9m6lN+P5cYVKCcPBU57WIBvRY0uVlPTvwJp9hrwJ nc5t4S4MSxXG7HYdQf8kx9Nx8mmaZkRIkg+QijXUbpONGGwo+gw7Q4Uefu+C/S3vQ0xk04Y4f2d f+mGqBQq/wpbPjGGCsZQfKnmiXf1aIWR5zSs8C X-Received: by 2002:a05:6a21:6190:b0:398:c351:aa0f with SMTP id adf61e73a8af0-398ecaa3e0amr12766158637.22.1773684191397; Mon, 16 Mar 2026 11:03:11 -0700 (PDT) Received: from DESKTOP-C3D0D2E.localdomain ([14.106.97.26]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c7400000532sm4890694a12.27.2026.03.16.11.03.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Mar 2026 11:03:10 -0700 (PDT) From: baichen To: linux-kernel@vger.kernel.org Cc: tj@kernel.org, jiangshanlai@gmail.com, baichen Subject: [PATCH] workqueue: check for NULL wq in queue_delayed_work_on() Date: Tue, 17 Mar 2026 02:03:00 +0800 Message-ID: <20260316180300.66423-1-ttdxba@gmail.com> X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If queue_delayed_work() is called with a NULL wq, the existing WARN_ON_ONCE(!wq) in __queue_delayed_work() only prints a warning but doesn't prevent the subsequent NULL pointer dereference when accessing wq->flags, causing a panic. Add a NULL check at the beginning of queue_delayed_work_on() to catch this error early, print a warning with stack dump, and return false to the caller instead of crashing later. Additionally, if the delay time is relatively long or there are too many kernel log prints in a short time, the previous warning message may be overwritten, making such issues difficult to debug. Relying on kernel log alone makes it impossible to diagnose this issue, and one must resort to fulldump to solve it. Cc: Tejun Heo , Lai Jiangshan , linux-kernel@vger.kernel.org Signed-off-by: baichen.zhang --- kernel/workqueue.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index cd5171208964..6cf0c5eefa07 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -2510,7 +2510,6 @@ static void __queue_delayed_work(int cpu, struct work= queue_struct *wq, struct timer_list *timer =3D &dwork->timer; struct work_struct *work =3D &dwork->work; =20 - WARN_ON_ONCE(!wq); WARN_ON_ONCE(timer->function !=3D delayed_work_timer_fn); WARN_ON_ONCE(timer_pending(timer)); WARN_ON_ONCE(!list_empty(&work->entry)); @@ -2569,6 +2568,14 @@ bool queue_delayed_work_on(int cpu, struct workqueue= _struct *wq, bool ret =3D false; unsigned long irq_flags; =20 + if (unlikely(!wq)) { + WARN_ON_ONCE(1); + pr_warn("workqueue: %s() called with NULL wq, dumping stack:\n", + __func__); + dump_stack(); + return false; + } + /* read the comment in __queue_work() */ local_irq_save(irq_flags); =20 --=20 2.52.0