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 EA5A12877F7; Thu, 25 Jun 2026 13:12:40 +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=1782393161; cv=none; b=RvAJlyVTp1H4dGADzXMc9ZWL2B934XnkOJ59xJ+2+lUfzPbBQZNE/j75XI+gkVw6BuZ4CVOGrBNyJ54CdJFwjd5KdpluGEbvD7WNtcIG8efjxPuA0FD1AkXqxbbrbIx230VZYGIxr9InC9NB1kZ90j8etostIzxwOKqruJUKTyc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782393161; c=relaxed/simple; bh=kZ8LzlQHBZAg6xMRnsH/jc5hCR8vRBY260kEV7Tv/bk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gXzV8iRZ7R4MfIGYecItjwGVCqrJj/s+kKLj2eitn0HyJOlyfW+acE2RKru/cktlwehxPEQ/bYqrFHq1wcaCxayxxzpE5VF8FqwZ4REJDhzcUXc2c0XmgJFjHflF3ZuTmmPN21+cTh8H+MBwvL//LlcuT5NsFEvIisJ7bUTNy6g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=0xDsoaj8; 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="0xDsoaj8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D0F91F000E9; Thu, 25 Jun 2026 13:12:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1782393160; bh=KT3SnXqPZ/VvdTYQJboXXwx3fX0L5VV1YF+RbKXD3Ao=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=0xDsoaj8tzh7yZtrVmYPN6lMl07kfbbKC1wseFZ/kiFdp1hNCu4OGL2twUWwtx/Xe MTPUsgcnKaOvu224sDji6QR/JzY/Jlf0ro1SocR9t2eqGQYBn1ns+q2cwN8MEFDRgU 6Gf+SwsOUoahkDpHkh2vzfKinRMypQija1qYT9cE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Stepan Ionichev , Andy Shevchenko Subject: [PATCH 7.1 17/21] serial: 8250_dw: unregister 8250 port if clk_notifier_register() fails Date: Thu, 25 Jun 2026 14:04:09 +0100 Message-ID: <20260625125615.646607488@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260625125613.243729608@linuxfoundation.org> References: <20260625125613.243729608@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 7.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Stepan Ionichev commit 10fc708b4de7f86002d2d735a2dbf3b5b7f65692 upstream. dw8250_probe() registers the 8250 port via serial8250_register_8250_port() and then, if the device has a clock, registers a clock notifier. If clk_notifier_register() fails, probe returns the error but leaves the 8250 port registered. The matching serial8250_unregister_port() lives in dw8250_remove(), which is not called when probe fails, so the port slot stays occupied until the device is rebound or the system is rebooted. The devm-allocated driver data is freed while the port still references it (via the saved private_data and serial_in/serial_out callbacks), so any access to that port slot before a rebind is a use-after-free hazard. Unregister the port on the clk_notifier_register() error path. Fixes: cc816969d7b5 ("serial: 8250_dw: Fix common clocks usage race condition") Cc: stable@vger.kernel.org Signed-off-by: Stepan Ionichev Reviewed-by: Andy Shevchenko Link: https://patch.msgid.link/20260514143746.23671-2-sozdayvek@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/8250/8250_dw.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/tty/serial/8250/8250_dw.c +++ b/drivers/tty/serial/8250/8250_dw.c @@ -850,8 +850,10 @@ static int dw8250_probe(struct platform_ */ if (data->clk) { err = clk_notifier_register(data->clk, &data->clk_notifier); - if (err) + if (err) { + serial8250_unregister_port(data->data.line); return dev_err_probe(dev, err, "Failed to set the clock notifier\n"); + } queue_work(system_dfl_wq, &data->clk_work); }