From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 18F0E3A900B; Sat, 17 Oct 2026 17:08:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792256930; cv=none; b=NapEFjwv0J1qsAq9QY1+X4/REkaTwV27aLSfYMvkCictF6m46W/S9BIh7xy0K3ZJrInEbCmm/RLTGLqXpUPS7SysHsvCvELCnRoJ2LwlTZa4b33DMjssoh3D94hZY0dYQwd/vtDZ4dMjyayil/0/N76dNtVwRBxWq1jN6xRgsok= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792256930; c=relaxed/simple; bh=nzmuGO9D14+uIdPK5vsp9Mae4CrOCQzy05iS0PJfOVk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tstDgHABIFYgMi4tI3k8vhM6Jum5LAKHVu0M0ES+tCEu9xKvR4NeRiH6N46saTX7BU3ZlYOGtz8gnuoQECu+U0MCGLFyX573+9Sem0tbARKAFdiwmiJAD1hhF6oOgQHpEipiAgPTXl9H5LJbYwxsO7ejufKpx0HGHUG1ejpli+U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Hn0CKmJf; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Hn0CKmJf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5ACE31F000C4; Sat, 17 Oct 2026 17:08:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1792256929; bh=ekRVzBoGGnGPdYX+aVf80Dz3c77CaQI6U1EAJTtX+Xw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Hn0CKmJfuwh4izj0pnh6M6si1FMpTlY5qIDJB6k8udjqFSBjyZevGUqAYsK5pqRd3 uK0XwlK/V3ZRLdU/slXRcpW7NL/pMVfVqN8xF81N0IBoK8DKoo9QDEtjDi8TonhPyW m4GZkX8f9qUXVA02Naom1wir3TZ+poxX8Vxjg20Y= 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.6 0398/1674] tty: serial: max3100: shut down timer before freeing port Date: Sat, 17 Oct 2026 17:44:30 +0200 Message-ID: <20261017160441.332724933@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261017160431.119607952@linuxfoundation.org> References: <20261017160431.119607952@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-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() arguments from port->irq and s->port.irq to s->irq. ] 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 3d2b83d6ab51a..ec230c2f081d6 100644 --- a/drivers/tty/serial/max3100.c +++ b/drivers/tty/serial/max3100.c @@ -567,11 +567,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) @@ -830,6 +830,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