From patchwork Wed Nov 16 16:21:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21172 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp237490wru; Wed, 16 Nov 2022 08:34:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf5a93H67faBtaj7kk1Jwm533dfImKU8oaJ+HUhPn8I4CkRwcWSCW2dgUKXs2GxSgKlrdnSW X-Received: by 2002:a17:906:b1c8:b0:78d:474c:2a59 with SMTP id bv8-20020a170906b1c800b0078d474c2a59mr18094482ejb.759.1668616478926; Wed, 16 Nov 2022 08:34:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668616478; cv=none; d=google.com; s=arc-20160816; b=NuG9bAjxRLkvcPlQBqltWyGcL33NO4F0w2MEvn2ysQcB7f2cZwK5hKiIFVVEORBAho hRvAajKIwdVM1O62YCaYXI6oMcGC3o7wj5jF7/Wm5X/qYL6aa6PFXwvKn0u/LXTzV8o2 fLKlYIj/TjQ3ds+WPjk44QbO3kpiPHnmM3RGWuSCVWpM2x9bvQwAMIki0bx6p+B/buqM DFn//5BvgvywNy/LdncVTAgmBDPpZd33Qm72g/9/yLMPlFQKorRs64SYQLtPZKaX6lqe EZfJVXRWCVHgqMhip8z4/Hirv5cxUQzH/kYrCTNM6xLbAh2qjb5BhNgA14a1AaXFwlme rk1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=cDzPKGMTkhpNbvwnnhR0RElQZrV0hyGRgg+q/Zsvwrs=; b=nmMWBDXUXHBFFSMp+Z0qMtXVLrdVWwr3DEKxTsjo9gyLh19w1jp9XvYFPGfLismDL5 0RBqSm8R+wRk7aj78/e4ZYo0scrB79RulHcP+oOO55Y61qFMkjxXLpDrIiVJAlJcxd/U Mt8hBYD22EMwdZn9OC6I9rITmd4qU40BTJ5rF5iZey7YK1AQ+u7oVjVjF+jlZa6+jktY KjRAv0FGdiOvHvHePYl43dUtKBf+bsRmOFVjHquJEhymfxpRFvA2nA7QReSjYDdDguVf 6VbdgLU0xCMZl9od3ks4CVyTCh46eQeYULMSwgn+GX/VHhCQ9MFjod1E8FI1AojPF/t+ CzFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=UfLU5wHJ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f19-20020a056402355300b0045981993486si11244976edd.227.2022.11.16.08.34.13; Wed, 16 Nov 2022 08:34:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=UfLU5wHJ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238787AbiKPQ0Q (ORCPT + 99 others); Wed, 16 Nov 2022 11:26:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238577AbiKPQXZ (ORCPT ); Wed, 16 Nov 2022 11:23:25 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2300F59856; Wed, 16 Nov 2022 08:22:19 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615737; 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: in-reply-to:in-reply-to:references:references; bh=cDzPKGMTkhpNbvwnnhR0RElQZrV0hyGRgg+q/Zsvwrs=; b=UfLU5wHJLWp2NQ8DrGn+ZhapyKLJzuFNlQXXldDXx0k+nP4yAyUOy2sHJk6ME9MoiZti5p fcu2oBfa9wWuRVhWK9Ulklw3Nj2rHGXadOoRecmBnUmWBbZgQC13WOWqP0rNqLAY7E59hH lrkhUWficQyx3cs3jEPN22zCYn6k4LhknPT0qgMs677kzH5/m1BTEzkcr3VugcRF3+h7DZ WUZpIWelOtzA/fVObnfzb12Ci/iLk5aPJNnNpVgFRZ9Kh2U52ogF/TK2e4kB+vcWmoNfhr mb7h/4k0WLiMPS+KEnrxEQSg1ItPKuz5UqS9KYRL6McjVRXqTPXUrYtP6TkjNw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615737; 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: in-reply-to:in-reply-to:references:references; bh=cDzPKGMTkhpNbvwnnhR0RElQZrV0hyGRgg+q/Zsvwrs=; b=rho7inCMOM4wtFYfYjQ2Ghv5PGoPaL+iWTbYTlh/MLc6tA17+ZIDyyY1rjFXbM4M80xO8a IViyH4PqOY1vbcDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH printk v5 40/40] tty: serial: sh-sci: use setup() callback for early console Date: Wed, 16 Nov 2022 17:27:52 +0106 Message-Id: <20221116162152.193147-41-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS 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: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749671192973137329?= X-GMAIL-MSGID: =?utf-8?q?1749671192973137329?= When setting up the early console, the setup() callback of the regular console is used. It is called manually before registering the early console instead of providing a setup() callback for the early console. This is probably because the early setup needs a different @options during the early stage. The issue here is that the setup() callback is called without the console_list_lock held and functions such as uart_set_options() expect that. Rather than manually calling the setup() function before registering, provide an early console setup() callback that will use the different early options. This ensures that the error checking, ordering, and locking context when setting up the early console are correct. Since this early console can only be registered via the earlyprintk= parameter, the @options argument of the setup() callback will always be NULL. Rather than simply ignoring the argument, add a WARN_ON() to get our attention in case the setup() callback semantics should change in the future. Note that technically the current implementation works because it is only used in early boot. And since the early console setup is performed before registering, it cannot race with anything and thus does not need any locking. However, longterm maintenance is easier when drivers rely on the subsystem API rather than manually implementing steps that could cause breakage in the future. Signed-off-by: John Ogness Reviewed-by: Geert Uytterhoeven Reviewed-by: Petr Mladek --- drivers/tty/serial/sh-sci.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 62f773286d44..76452fe2af86 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -3054,15 +3054,29 @@ static struct console serial_console = { }; #ifdef CONFIG_SUPERH +static char early_serial_buf[32]; + +static int early_serial_console_setup(struct console *co, char *options) +{ + /* + * This early console is always registered using the earlyprintk= + * parameter, which does not call add_preferred_console(). Thus + * @options is always NULL and the options for this early console + * are passed using a custom buffer. + */ + WARN_ON(options); + + return serial_console_setup(co, early_serial_buf); +} + static struct console early_serial_console = { .name = "early_ttySC", .write = serial_console_write, + .setup = early_serial_console_setup, .flags = CON_PRINTBUFFER, .index = -1, }; -static char early_serial_buf[32]; - static int sci_probe_earlyprintk(struct platform_device *pdev) { const struct plat_sci_port *cfg = dev_get_platdata(&pdev->dev); @@ -3074,8 +3088,6 @@ static int sci_probe_earlyprintk(struct platform_device *pdev) sci_init_single(pdev, &sci_ports[pdev->id], pdev->id, cfg, true); - serial_console_setup(&early_serial_console, early_serial_buf); - if (!strstr(early_serial_buf, "keep")) early_serial_console.flags |= CON_BOOT;