From patchwork Mon Aug 28 16:58:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugeniy Paltsev X-Patchwork-Id: 806670 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Vtr9LJUU"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xgysV2T6lz9sNn for ; Tue, 29 Aug 2017 03:08:46 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=gGPD9ZXcUX9a6eqAr7YPh++EbWWEUWqPSGkPoAu5tgg=; b=Vtr9LJUUdGMZyuIzHOKCeNGY7Z M2zvxxzf9Bsepf3Osf5YAOLHCmEmbsj/XfTEUAy1+OrsZBdjoEImOunCOXGMKDvtd9iFFCvYKWjYN l5I96g0SHAShmS1BGs7c0jSmdz4WYOGALfad+njX2ciXy54UlPcqfZqlsGIvvRvotmYZ9YgKEO/8R DJdtqmJ8vtNol+MhErYD5+l0HOJqdyV0jJM2qVeFSdx3Vcosk8TjKsvbrQs+DEmPAcp3sjX1GaY7q Tspv+hspbrqJJX0a3n8vKdTRgEVgJ7lvuOw0WUxTHVgmq2UvyLT06AIwRr13WlvXQQHCudxaQogM+ GXxF3Egg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dmNWn-0003nv-23; Mon, 28 Aug 2017 17:08:45 +0000 Received: from smtprelay2.synopsys.com ([198.182.60.111] helo=smtprelay.synopsys.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dmNN0-000571-FF for linux-snps-arc@lists.infradead.org; Mon, 28 Aug 2017 16:58:46 +0000 Received: from mailhost.synopsys.com (mailhost1.synopsys.com [10.12.238.239]) by smtprelay.synopsys.com (Postfix) with ESMTP id 2365E10C1493; Mon, 28 Aug 2017 09:58:20 -0700 (PDT) Received: from mailhost.synopsys.com (localhost [127.0.0.1]) by mailhost.synopsys.com (Postfix) with ESMTP id 0BEC1ACF; Mon, 28 Aug 2017 09:58:20 -0700 (PDT) Received: from localhost.internal.synopsys.com (unknown [10.121.8.106]) by mailhost.synopsys.com (Postfix) with ESMTP id 48DD9A7D; Mon, 28 Aug 2017 09:58:18 -0700 (PDT) From: Eugeniy Paltsev To: Petr Mladek , Sergey Senozhatsky Subject: [PATCH v2 2/2] console: don't select first registered console if stdout-path used Date: Mon, 28 Aug 2017 19:58:07 +0300 Message-Id: <20170828165807.8408-3-Eugeniy.Paltsev@synopsys.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170828165807.8408-1-Eugeniy.Paltsev@synopsys.com> References: <20170828165807.8408-1-Eugeniy.Paltsev@synopsys.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170828_095839_229063_00E9A93E X-CRM114-Status: GOOD ( 15.38 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [198.182.60.111 listed in list.dnswl.org] -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hans de Goede , linux-snps-arc@lists.infradead.org, Eugeniy Paltsev , linux-kernel@vger.kernel.org, Steven Rostedt MIME-Version: 1.0 Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org In the current implementation we take the first console that registers if we didn't select one. But if we specify console via "stdout-path" property in device tree we don't want first console that registers here to be selected. Otherwise we may choose wrong console - for example if some console is registered earlier than console is pointed in "stdout-path" property because console pointed in "stdout-path" property can be add as preferred quite late - when it's driver is probed. We retain previous behavior for tty0 console (if "stdout-path" used) as a special case: tty0 will be registered even if it was specified neither in "bootargs" nor in "stdout-path". We had to retain this behavior because a lot of ARM boards (and some powerpc) rely on it. Signed-off-by: Eugeniy Paltsev --- Changes v1->v2: * Add exception for "tty0" console as current behavior is widely used by ARM and powerpc boards. kernel/printk/printk.c | 84 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 69 insertions(+), 15 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 512f7c2..be40f57 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -2376,6 +2377,55 @@ static int __init keep_bootcon_setup(char *str) early_param("keep_bootcon", keep_bootcon_setup); +static bool console_selected_by_of(void) +{ + return !!of_stdout; +} + +static bool can_be_tty0(struct console *newcon) +{ + struct console *con = NULL; + + if (newcon->index > 0) + return false; + + if (strcmp(newcon->name, "tty") != 0) + return false; + + if (newcon->index == 0) + return true; + + /* do we have "tty" console already registered? */ + for_each_console(con) { + if (strcmp(con->name, "tty") != 0) + continue; + + if (con->index >= 0) + return false; + } + + return true; +} + +static bool take_console_noopts(struct console *newcon) +{ + if (newcon->index < 0) + newcon->index = 0; + + if ((newcon->setup != NULL) && (newcon->setup(newcon, NULL) != 0)) + return false; + + newcon->flags |= CON_ENABLED; + + if (newcon->device && !can_be_tty0(newcon)) + newcon->flags |= CON_CONSDEV; + + if (newcon->device) + return true; + + return false; +} + /* * The console driver calls this routine during kernel initialization * to register the console printing procedure with printk() and to @@ -2432,22 +2482,26 @@ void register_console(struct console *newcon) has_preferred = preferred_console >= 0; /* - * See if we want to use this console driver. If we - * didn't select a console we take the first one - * that registers here. + * If we specify console via "stdout-path" property in device tree + * we don't want first console that registers here to be selected. */ - if (!has_preferred) { - if (newcon->index < 0) - newcon->index = 0; - if (newcon->setup == NULL || - newcon->setup(newcon, NULL) == 0) { - newcon->flags |= CON_ENABLED; - if (newcon->device) { - newcon->flags |= CON_CONSDEV; - has_preferred = true; - } - } - } + if (console_selected_by_of()) + has_preferred = true; + + /* + * See if we want to use this console driver. If we didn't select + * a console we take the first one that registers here. + */ + if (!has_preferred) + has_preferred |= take_console_noopts(newcon); + + /* + * Treat "tty0" (in case of "stdout-path" using) as a special case: + * "tty0" will be registered even if it was specified neither in + * "bootargs" nor in "stdout-path". + */ + if (console_selected_by_of() && can_be_tty0(newcon)) + has_preferred |= take_console_noopts(newcon); /* * See if this console matches one we selected on