From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 AD270377EDA for ; Sun, 19 Jul 2026 06:36:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784442995; cv=none; b=Ksbv30AR5i09BjEbQ2iG2cuBMzFdny3HET20vurimTRWNjOpXll4rTowQBnwfaLiqxnn/vLS6fMif62FuFOZjAiX06U+2HtqDjg+kOcLJ8Gm3jhYEYY0/4BFBQfIOzCNl32qEnazjoLDbGZZmuxRnuYvohpzEQ1kYUfm/MJCc8U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784442995; c=relaxed/simple; bh=1xGW+5OPXtzQAk5+Pyyb09mDv2qTxs5kQSXDGy4qmJ8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jMFS+G9jL9azQB7wUrO6LZuhDpUYps7Kx7DuUw7LtTZ1vb+IBW6TREKD8BcuZa3z9JyE/7s3UZOFqrhiVLTYSZJ7vnloIkagd/TrlXF3JcdNXMEYGVVNw8/xJTRJZJqhmwA31Sf8F9G9PWOTzWdNILS7z/cjob4fUSJHt7eV8MQ= 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=lVHdm3mT; arc=none smtp.client-ip=209.85.128.44 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="lVHdm3mT" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4954d383e64so8606025e9.1 for ; Sat, 18 Jul 2026 23:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784442992; x=1785047792; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=cxs6c/h7vM3D54wuYMS02bOf2z2hWYR7//TmGe3XwKk=; b=lVHdm3mTJUb38d8Tknab1a+XqUI6G15qMj6GvbLy2aTKAPHlRfbvwtQnxEiNiI0tAu RWt56DQ+J8GElaO6XWP0F0oZRiE3MMMVRDHd/l8DrOJ3xj4/zWlmiVK/duGM+VUkjbhQ JNBY+CA4o3tLElncxTOhK3csk2UdPjINCIiCW34R4RBN0dLvd6xDWeVKKRNr70bfjWzR PX14I1iFlk7ZkSMP28QR7WPt/l+a1ms0EARJr6I5rnXqcNEwHeM1YmS38iIlv6XzPpwb kTDkxIkQxzfsIKYd+vvI0nZ7Muyt3KlloM+oLt29fa4sFteVTdoeiRM0TRASq4UcS3pm jTxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784442992; x=1785047792; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=cxs6c/h7vM3D54wuYMS02bOf2z2hWYR7//TmGe3XwKk=; b=M1kIAe54QZhN1SpA25CRu3LzUx+LtC61uVzsoVvPujJF6+kH/pNF+u1KdxhLUg3U5u ixFEYXKAxBF866wPr9WVIX+b1aP4aFhmJVTDjPUTZXuj3ZuPQ6ervzjrY/Q8Exkpa+6s rta1ybhDFBI9VtBmgj+6DxMXub7/pqcLkxtNugP1u0vnyaPZWayFRVXeKvLDB2WhUHb2 kd3wQt7qPdXsodbgEMMHTEa093wMAyov2/NnLYFRu6LRNfC7yzVDO1njJPniNgAinBRJ PNen2rBzKKjod/1ft2QjvY29VLZQaqbLtrAiPzJuQaXO5o43uLkWS7RFSwflykoJ5wQG UQfQ== X-Forwarded-Encrypted: i=1; AHgh+RpGk/1j0KAKQDVrX/Ku7XglWCirdFeF2sKb0S6QVXsrIIyv/jQ7HD4KhLaaqfK4jGumoAVLLiOKKHQjb18oLQ==@lists.linux.dev X-Gm-Message-State: AOJu0YzZmr+lGWA2pQsh5wx5u9QjYtIfl2kGrDTXKVJHqY6uDetyEkI6 I6aBm5MT9NFNubzpzU4RooKp/JIsw22l5BpCkTcTZ7RmbthIBvi5SY62 X-Gm-Gg: AfdE7clZ/uCz+xOyRY7G1bQUaxj+CWwKtBjiqxs0em183g3m7zwaSsmAaTm5/jpl68+ TQzqg4ZXdep8xbbEaI+GDsOi05yG7busD4sJ35VzPEsGKlQ2qSSqhSDZgx7LA/aJzNLAnHBV/kb Gq/qxKwu276gke0YzduNuV29DqYlQWleKtMUs2kr7QM0yvlXd+ekfoedjFwszZE+rYNOHcWKXrf cEFAG6oWi4EWSfLUS3vaennFcg9/4sgrkUce7PJ3qrbVcbb5So36U/yap3WYfVtTTbBDj7DvNK5 RgGimGcC6pMhPbQq7kyrETNs657E6TSXmZG7snw7oducFd6itBtgEWzCg+1bBS+kj5Zr/eGc3bc 7Mpb7uIv0mDl8iKN0NbbEaDAlXk4tQ0Xy7uBKNTpAtcTGV6LigIGX6MhwSU77Fvc1nKS8dWNlpr pxvwfFyTa47Y4FxnTsuNJZXO/BAVzmp9vv1px7JALkna9WeT6tSe9BuK6CVJxxkpkUIZpFusWs6 ixZZ/r+brjvV6AmbYvQquYakfMYqqj+YK4JzcY= X-Received: by 2002:a05:600c:5657:b0:493:f442:3dd4 with SMTP id 5b1f17b1804b1-4954a516af8mr59398075e9.39.1784442991787; Sat, 18 Jul 2026 23:36:31 -0700 (PDT) Received: from localhost.localdomain (dynamic-077-007-018-194.77.7.pool.telefonica.de. [77.7.18.194]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49549c96f19sm193053245e9.9.2026.07.18.23.36.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 18 Jul 2026 23:36:30 -0700 (PDT) From: Karl Mehltretter To: Russell King , Greg Kroah-Hartman , Jiri Slaby Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , linux-rt-devel@lists.linux.dev, Toshiyuki Sato , Petr Mladek , John Ogness , Karl Mehltretter Subject: [PATCH 1/2] serial: amba-pl011: unprepare console clock on unregister Date: Sun, 19 Jul 2026 08:35:01 +0200 Message-Id: <20260719063502.18852-2-kmehltretter@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20260719063502.18852-1-kmehltretter@gmail.com> References: <20260719063502.18852-1-kmehltretter@gmail.com> Precedence: bulk X-Mailing-List: linux-rt-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit pl011_console_setup() calls clk_prepare() on the UART clock, but the console provides no matching teardown, so the clock is never unprepared when the console is unregistered -- via the sysfs "console" attribute or a driver unbind. Each re-registration prepares the clock again, leaking one prepare reference per cycle. Even where preparing the clock has no hardware effect, the stale reference leaves the clock framework's prepare count unbalanced. On providers whose prepare operation enables hardware, the leaked reference may also keep the UART clock running after unregister. Add a console .exit() callback that clk_unprepare()s the clock, balancing the clk_prepare() in pl011_console_setup(). Fixes: 4b4851c65d92 ("clk: amba-pl011: convert to clk_prepare()/clk_unprepare()") Assisted-by: Claude:claude-fable-5 Signed-off-by: Karl Mehltretter --- The i.MX console had the same missing teardown, fixed in 9768a37cec37 ("serial: imx: disable console clocks on unregister"). Measured on QEMU raspi (bcm2835), whose UART clock is a real gateable CPRMAN clock: recycling the console via /sys/class/tty/ttyAMA0/console, the uart clock's prepare_count (/sys/kernel/debug/clk/uart/ clk_prepare_count) climbs by one per cycle -- 2 -> 8 over six cycles -- without this patch, and stays at 2 with it. drivers/tty/serial/amba-pl011.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c index 8ed91e1da22b..1aa43994a3cd 100644 --- a/drivers/tty/serial/amba-pl011.c +++ b/drivers/tty/serial/amba-pl011.c @@ -2552,6 +2552,15 @@ static int pl011_console_setup(struct console *co, char *options) return uart_set_options(&uap->port, co, baud, parity, bits, flow); } +static int pl011_console_exit(struct console *co) +{ + struct uart_amba_port *uap = amba_ports[co->index]; + + clk_unprepare(uap->clk); + + return 0; +} + /** * pl011_console_match - non-standard console matching * @co: registering console @@ -2705,6 +2714,7 @@ static struct console amba_console = { .name = "ttyAMA", .device = uart_console_device, .setup = pl011_console_setup, + .exit = pl011_console_exit, .match = pl011_console_match, .write_atomic = pl011_console_write_atomic, .write_thread = pl011_console_write_thread, -- 2.53.0