From patchwork Tue Jun 28 12:07:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 1649481 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=walle.cc header.i=@walle.cc header.a=rsa-sha256 header.s=mail2016061301 header.b=PGqea9u+; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4LXNdg2vj7z9sGJ for ; Tue, 28 Jun 2022 22:07:51 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345469AbiF1MHt (ORCPT ); Tue, 28 Jun 2022 08:07:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238286AbiF1MHr (ORCPT ); Tue, 28 Jun 2022 08:07:47 -0400 Received: from ssl.serverraum.org (ssl.serverraum.org [176.9.125.105]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 604F324BC1; Tue, 28 Jun 2022 05:07:13 -0700 (PDT) Received: from mwalle01.kontron.local. (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id DE50D22246; Tue, 28 Jun 2022 14:07:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1656418031; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=hgB07wGzzjuB/IETny6DvoS9YsWl3zMXH0wKA/TEMtI=; b=PGqea9u+tKJb1Oyj8JGp5Vh1UajHV55/tTx4lPSaKiMFXdM07AGX+UJ8C9CAh++vRp97oA OB+4q6/Vd8nwhbgd0k4l3NST7Wsm4nDIkKmFo6rFoG8wpiUHzkuljasgq8SAnkkA50BW1O M7pTyBlgS12nVxUDE05Q5PXd1WMuNuk= From: Michael Walle To: Rob Herring , Frank Rowand , Greg Kroah-Hartman , Jiri Slaby Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Michael Walle , Rob Herring Subject: [PATCH RESEND v2] earlycon: prevent multiple register_console() Date: Tue, 28 Jun 2022 14:07:05 +0200 Message-Id: <20220628120705.200617-1-michael@walle.cc> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org If the earlycon parameter is given twice, the kernel will spit out a WARN() in register_console() because it was already registered. The non-dt variant setup_earlycon() already handles that gracefully. The dt variant of_setup_earlycon() doesn't. Add the check there and add the -EALREADY handling in early_init_dt_scan_chosen_stdout(). FWIW, this doesn't happen if CONFIG_ACPI_SPCR_TABLE is set. In that case the registration is delayed until after earlycon parameter(s) are parsed. Signed-off-by: Michael Walle Reviewed-by: Rob Herring --- changes since v1: - add missing EALREADY handling in of_setup_earlycon() - return 0 early as suggested by Rob For the curious, here is the backtrace: [ 0.000000] ------------[ cut here ]------------ [ 0.000000] WARNING: CPU: 0 PID: 0 at kernel/printk/printk.c:3328 register_console+0x2b4/0x364 [ 0.000000] console 'atmel_serial0' already registered [ 0.000000] Modules linked in: [ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 5.18.0-next-20220601+ #652 [ 0.000000] Hardware name: Generic DT based system [ 0.000000] Backtrace: [ 0.000000] dump_backtrace from show_stack+0x18/0x1c [ 0.000000] show_stack from dump_stack_lvl+0x48/0x54 [ 0.000000] dump_stack_lvl from dump_stack+0x18/0x1c [ 0.000000] dump_stack from __warn+0xd0/0x148 [ 0.000000] __warn from warn_slowpath_fmt+0x9c/0xc4 [ 0.000000] warn_slowpath_fmt from register_console+0x2b4/0x364 [ 0.000000] register_console from of_setup_earlycon+0x29c/0x2ac [ 0.000000] of_setup_earlycon from early_init_dt_scan_chosen_stdout+0x154/0x18c [ 0.000000] early_init_dt_scan_chosen_stdout from param_setup_earlycon+0x40/0x48 [ 0.000000] param_setup_earlycon from do_early_param+0x88/0xc4 [ 0.000000] do_early_param from parse_args+0x1a4/0x404 [ 0.000000] parse_args from parse_early_options+0x40/0x48 [ 0.000000] parse_early_options from parse_early_param+0x38/0x48 [ 0.000000] parse_early_param from setup_arch+0x114/0x7a4 [ 0.000000] setup_arch from start_kernel+0x74/0x6dc [ 0.000000] start_kernel from 0x0 [ 0.000000] ---[ end trace 0000000000000000 ]--- drivers/of/fdt.c | 4 +++- drivers/tty/serial/earlycon.c | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index a8f5b6532165..043b12be22d6 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1025,6 +1025,7 @@ int __init early_init_dt_scan_chosen_stdout(void) int l; const struct earlycon_id *match; const void *fdt = initial_boot_params; + int ret; offset = fdt_path_offset(fdt, "/chosen"); if (offset < 0) @@ -1057,7 +1058,8 @@ int __init early_init_dt_scan_chosen_stdout(void) if (fdt_node_check_compatible(fdt, offset, match->compatible)) continue; - if (of_setup_earlycon(match, offset, options) == 0) + ret = of_setup_earlycon(match, offset, options); + if (!ret || ret == -EALREADY) return 0; } return -ENODEV; diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c index 57c70851f22a..88d08ba1ca83 100644 --- a/drivers/tty/serial/earlycon.c +++ b/drivers/tty/serial/earlycon.c @@ -253,6 +253,9 @@ int __init of_setup_earlycon(const struct earlycon_id *match, bool big_endian; u64 addr; + if (early_con.flags & CON_ENABLED) + return -EALREADY; + spin_lock_init(&port->lock); port->iotype = UPIO_MEM; addr = of_flat_dt_translate_address(node);