From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793213158; b=MssgmyDJOEeW7X5XLrHCe/BM3I3NlmNRsmkK4Qk63KPXDrbWnttkLxbUMyAKe46M6t55 BjAP7xOvJcye/TeOJe1cs0QoD4TxLxiWnRurAUBH+H94lbf5aqVZYF+MxOAC9zOX3qgU4 2x1e4OngbraAoGoxNLest3Q/KBBpU/Fzn95/5BxLHMlKBV1f2sjbSf/OtMXdQyCsbIObV OiUTe9086cmbp2BdZgZpe8cG7EkqbCqknQEfcjd3qyS6XnzOq/y+HKuxO6FbwqGWQZwJx tHdcIDPaqqehCOCgJWMm8Q3k56BUZkiygCRp2xlsFjt8Ml5xBnmaKculMSgv12LwxSg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793213158; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=T9V72xkF+lFWxEgslF7FOPHSp7H+cv5WU3FDLznXztU=; b=JX2+Q40/j041kVqt5JqJOyHIvWY+a5/6wsy5E/JFaWW8/9pqLfToP9Dhq1+lLqvrKcs1 Pdh91bBfkMx02MUeUlCb5Jo0T0Y209Y1YNRXIzFsFlT4w741mkGpozn1oYklSE4yWfvIw iu/gzPw0ZAz09tGVV73omLPYAs5VMqXQRDucSu8rmH+WpbgPS2b5ft8EIl+7iQkahfRDT Y1YukHUJKKRNzNre9opejMD6lxKh9DVQt2YHQwC0V5DOnqf0VoqumwurC7wOnCALozLcO yLamB1s1XPOsz4w1jpSWFTrvqYzQmHiDuUOC2hd08omz7O4ebvC4WeYUHfd1C9MaqCw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ISawKs7d; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00E05606A31A; Wed, 28 Oct 2026 18:45:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ISawKs7d Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E7431F01829; Wed, 28 Oct 2026 18:45:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793213157; bh=T9V72xkF+lFWxEgslF7FOPHSp7H+cv5WU3FDLznXztU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ISawKs7debCWMYdxrfSnKqMQF+qa1mj26c732tJl16nnjaTkUBXWkY5LkdSai7rnt bOMYHyT9XfpdosBpkvYgVyzG1A4qT5VEn2YR78uc+3i+vpjvflmQizviUWOoX76M8f jwyNFGfMFlV1CKwRodbmLWpZarr24M0l2Bx3jXWU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Fan Wu , Sasha Levin , stable@kernel.org Subject: [PATCH 6.1 0390/1887] tty: serial: max3100: shut down timer before freeing port Date: Wed, 28 Oct 2026 17:41:26 +0100 Message-ID: <20261028170508.109228916@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261028170459.200466217@linuxfoundation.org> References: <20261028170459.200466217@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Fan Wu [ Upstream commit db0949bbd06db0a75b4b1076f1e25194be7d956a ] max3100_shutdown() stops the polling timer but returns early during system suspend. If the SPI device is unbound before resume, the serial core does not call max3100_shutdown() again, so max3100_remove() frees the port while the timer remains armed. max3100_timeout() may then access the freed port and re-arm the timer. Add final timer teardown to max3100_remove() and use timer_shutdown_sync() to prevent a racing callback from re-arming it. Also free the IRQ and destroy the workqueue there before freeing the port. Keep timer_delete_sync() in max3100_shutdown() so that a subsequent open() can re-arm the timer. The workqueue is created before request_irq() and destroyed on both request_irq() failure and normal shutdown. Its presence at remove thus identifies the IRQ left registered when suspend bypasses shutdown. Free the IRQ before destroying the workqueue, in both max3100_shutdown() and max3100_remove(), and cancel the pending work in between. free_irq() waits for a running interrupt handler to finish and no new handler can start afterwards, so a racing handler cannot queue work on a workqueue that is being destroyed; the force_end_work check in max3100_dowork() only narrows that window, as a handler delayed between the check and queue_work() could still run after the teardown has cleared the workqueue pointer. Cancelling the work also keeps destroy_workqueue() from waiting on a queued work item in case remove() ever runs while the freezable workqueue is still frozen, e.g. device removal during the resume window, before workqueues are thawed. This issue was found by an in-house static analysis tool. Fixes: 7831d56b0a35 ("tty: MAX3100") Cc: stable@kernel.org # 6.2+ Assisted-by: Codex:gpt-5.6 Signed-off-by: Fan Wu Link: https://patch.msgid.link/20260927055957.561030-1-fanwu01@zju.edu.cn Signed-off-by: Greg Kroah-Hartman [ sashal: Changed free_irq() calls to use s->irq instead of the uart_port IRQ field. ] Signed-off-by: Sasha Levin --- drivers/tty/serial/max3100.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c index 67803242a70c2..4ba444460753c 100644 --- a/drivers/tty/serial/max3100.c +++ b/drivers/tty/serial/max3100.c @@ -568,11 +568,11 @@ static void max3100_shutdown(struct uart_port *port) del_timer_sync(&s->timer); if (s->workqueue) { + free_irq(s->irq, s); + cancel_work_sync(&s->work); destroy_workqueue(s->workqueue); s->workqueue = NULL; } - if (s->irq) - free_irq(s->irq, s); /* set shutdown mode to save power */ if (s->max3100_hw_suspend) @@ -831,6 +831,15 @@ static void max3100_remove(struct spi_device *spi) if (max3100s[i] == s) { dev_dbg(&spi->dev, "%s: removing port %d\n", __func__, i); uart_remove_one_port(&max3100_uart_driver, &max3100s[i]->port); + + s->force_end_work = 1; + timer_shutdown_sync(&s->timer); + if (s->workqueue) { + free_irq(s->irq, s); + cancel_work_sync(&s->work); + destroy_workqueue(s->workqueue); + s->workqueue = NULL; + } kfree(max3100s[i]); max3100s[i] = NULL; break; -- 2.53.0