{"id":806670,"url":"http://patchwork.ozlabs.org/api/1.0/patches/806670/?format=json","project":{"id":48,"url":"http://patchwork.ozlabs.org/api/1.0/projects/48/?format=json","name":"Linux ARC development","link_name":"linux-arc","list_id":"linux-snps-arc.lists.infradead.org","list_email":"linux-snps-arc@lists.infradead.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20170828165807.8408-3-Eugeniy.Paltsev@synopsys.com>","date":"2017-08-28T16:58:07","name":"[v2,2/2] console: don't select first registered console if stdout-path used","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"1dd3543a58cebf8f4d5d2a0183753f522991bba9","submitter":{"id":69220,"url":"http://patchwork.ozlabs.org/api/1.0/people/69220/?format=json","name":"Eugeniy Paltsev","email":"Eugeniy.Paltsev@synopsys.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-arc/patch/20170828165807.8408-3-Eugeniy.Paltsev@synopsys.com/mbox/","series":[{"id":218,"url":"http://patchwork.ozlabs.org/api/1.0/series/218/?format=json","date":"2017-08-28T16:58:05","name":"console: don't select first registered console if stdout-path used","version":2,"mbox":"http://patchwork.ozlabs.org/series/218/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/806670/checks/","tags":{},"headers":{"Return-Path":"<linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org; spf=none (mailfrom)\n\tsmtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133;\n\thelo=bombadil.infradead.org;\n\tenvelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=lists.infradead.org\n\theader.i=@lists.infradead.org header.b=\"Vtr9LJUU\"; \n\tdkim-atps=neutral"],"Received":["from bombadil.infradead.org (bombadil.infradead.org\n\t[65.50.211.133])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xgysV2T6lz9sNn\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 29 Aug 2017 03:08:46 +1000 (AEST)","from localhost ([127.0.0.1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux))\n\tid 1dmNWn-0003nv-23; Mon, 28 Aug 2017 17:08:45 +0000","from smtprelay2.synopsys.com ([198.182.60.111]\n\thelo=smtprelay.synopsys.com)\n\tby bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux))\n\tid 1dmNN0-000571-FF for linux-snps-arc@lists.infradead.org;\n\tMon, 28 Aug 2017 16:58:46 +0000","from mailhost.synopsys.com (mailhost1.synopsys.com [10.12.238.239])\n\tby smtprelay.synopsys.com (Postfix) with ESMTP id 2365E10C1493;\n\tMon, 28 Aug 2017 09:58:20 -0700 (PDT)","from mailhost.synopsys.com (localhost [127.0.0.1])\n\tby mailhost.synopsys.com (Postfix) with ESMTP id 0BEC1ACF;\n\tMon, 28 Aug 2017 09:58:20 -0700 (PDT)","from localhost.internal.synopsys.com (unknown [10.121.8.106])\n\tby mailhost.synopsys.com (Postfix) with ESMTP id 48DD9A7D;\n\tMon, 28 Aug 2017 09:58:18 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20170209; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe:\n\tList-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References:\n\tIn-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID:\n\tContent-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc\n\t:Resent-Message-ID:List-Owner;\n\tbh=gGPD9ZXcUX9a6eqAr7YPh++EbWWEUWqPSGkPoAu5tgg=;\n\tb=Vtr9LJUUdGMZyuIzHOKCeNGY7Z\n\tM2zvxxzf9Bsepf3Osf5YAOLHCmEmbsj/XfTEUAy1+OrsZBdjoEImOunCOXGMKDvtd9iFFCvYKWjYN\n\tl5I96g0SHAShmS1BGs7c0jSmdz4WYOGALfad+njX2ciXy54UlPcqfZqlsGIvvRvotmYZ9YgKEO/8R\n\tDJdtqmJ8vtNol+MhErYD5+l0HOJqdyV0jJM2qVeFSdx3Vcosk8TjKsvbrQs+DEmPAcp3sjX1GaY7q\n\tTspv+hspbrqJJX0a3n8vKdTRgEVgJ7lvuOw0WUxTHVgmq2UvyLT06AIwRr13WlvXQQHCudxaQogM+\n\tGXxF3Egg==;","From":"Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>","To":"Petr Mladek <pmladek@suse.com>,\n\tSergey Senozhatsky <sergey.senozhatsky@gmail.com>","Subject":"[PATCH v2 2/2] console: don't select first registered console if\n\tstdout-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:\n\tContent analysis details:   (-1.9 points)\n\tpts rule name              description\n\t---- ----------------------\n\t--------------------------------------------------\n\t-0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/,\n\tno trust [198.182.60.111 listed in list.dnswl.org]\n\t-0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay\n\tdomain\n\t-1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%\n\t[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\n\t<linux-snps-arc.lists.infradead.org>","List-Unsubscribe":"<http://lists.infradead.org/mailman/options/linux-snps-arc>, \n\t<mailto:linux-snps-arc-request@lists.infradead.org?subject=unsubscribe>","List-Archive":"<http://lists.infradead.org/pipermail/linux-snps-arc/>","List-Post":"<mailto:linux-snps-arc@lists.infradead.org>","List-Help":"<mailto:linux-snps-arc-request@lists.infradead.org?subject=help>","List-Subscribe":"<http://lists.infradead.org/mailman/listinfo/linux-snps-arc>, \n\t<mailto:linux-snps-arc-request@lists.infradead.org?subject=subscribe>","Cc":"Hans de Goede <hdegoede@redhat.com>, linux-snps-arc@lists.infradead.org, \n\tEugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>,\n\tlinux-kernel@vger.kernel.org, Steven Rostedt <rostedt@goodmis.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Sender":"\"linux-snps-arc\" <linux-snps-arc-bounces@lists.infradead.org>","Errors-To":"linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"},"content":"In the current implementation we take the first console that\nregisters if we didn't select one.\n\nBut if we specify console via \"stdout-path\" property in device tree\nwe don't want first console that registers here to be selected.\nOtherwise we may choose wrong console - for example if some console\nis registered earlier than console is pointed in \"stdout-path\"\nproperty because console pointed in \"stdout-path\" property can be add as\npreferred quite late - when it's driver is probed.\n\nWe retain previous behavior for tty0 console (if \"stdout-path\" used)\nas a special case:\ntty0 will be registered even if it was specified neither\nin \"bootargs\" nor in \"stdout-path\".\nWe had to retain this behavior because a lot of ARM boards (and some\npowerpc) rely on it.\n\nSigned-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>\n---\nChanges v1->v2:\n * Add exception for \"tty0\" console as current behavior is widely used\n   by ARM and powerpc boards.\n\n kernel/printk/printk.c | 84 +++++++++++++++++++++++++++++++++++++++++---------\n 1 file changed, 69 insertions(+), 15 deletions(-)","diff":"diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c\nindex 512f7c2..be40f57 100644\n--- a/kernel/printk/printk.c\n+++ b/kernel/printk/printk.c\n@@ -26,6 +26,7 @@\n #include <linux/nmi.h>\n #include <linux/module.h>\n #include <linux/moduleparam.h>\n+#include <linux/of.h>\n #include <linux/delay.h>\n #include <linux/smp.h>\n #include <linux/security.h>\n@@ -2376,6 +2377,55 @@ static int __init keep_bootcon_setup(char *str)\n \n early_param(\"keep_bootcon\", keep_bootcon_setup);\n \n+static bool console_selected_by_of(void)\n+{\n+\treturn !!of_stdout;\n+}\n+\n+static bool can_be_tty0(struct console *newcon)\n+{\n+\tstruct console *con = NULL;\n+\n+\tif (newcon->index > 0)\n+\t\treturn false;\n+\n+\tif (strcmp(newcon->name, \"tty\") != 0)\n+\t\treturn false;\n+\n+\tif (newcon->index == 0)\n+\t\treturn true;\n+\n+\t/* do we have \"tty\" console already registered? */\n+\tfor_each_console(con) {\n+\t\tif (strcmp(con->name, \"tty\") != 0)\n+\t\t\tcontinue;\n+\n+\t\tif (con->index >= 0)\n+\t\t\treturn false;\n+\t}\n+\n+\treturn true;\n+}\n+\n+static bool take_console_noopts(struct console *newcon)\n+{\n+\tif (newcon->index < 0)\n+\t\tnewcon->index = 0;\n+\n+\tif ((newcon->setup != NULL) && (newcon->setup(newcon, NULL) != 0))\n+\t\treturn false;\n+\n+\tnewcon->flags |= CON_ENABLED;\n+\n+\tif (newcon->device && !can_be_tty0(newcon))\n+\t\tnewcon->flags |= CON_CONSDEV;\n+\n+\tif (newcon->device)\n+\t\treturn true;\n+\n+\treturn false;\n+}\n+\n /*\n  * The console driver calls this routine during kernel initialization\n  * to register the console printing procedure with printk() and to\n@@ -2432,22 +2482,26 @@ void register_console(struct console *newcon)\n \t\thas_preferred = preferred_console >= 0;\n \n \t/*\n-\t *\tSee if we want to use this console driver. If we\n-\t *\tdidn't select a console we take the first one\n-\t *\tthat registers here.\n+\t * If we specify console via \"stdout-path\" property in device tree\n+\t * we don't want first console that registers here to be selected.\n \t */\n-\tif (!has_preferred) {\n-\t\tif (newcon->index < 0)\n-\t\t\tnewcon->index = 0;\n-\t\tif (newcon->setup == NULL ||\n-\t\t    newcon->setup(newcon, NULL) == 0) {\n-\t\t\tnewcon->flags |= CON_ENABLED;\n-\t\t\tif (newcon->device) {\n-\t\t\t\tnewcon->flags |= CON_CONSDEV;\n-\t\t\t\thas_preferred = true;\n-\t\t\t}\n-\t\t}\n-\t}\n+\tif (console_selected_by_of())\n+\t\thas_preferred = true;\n+\n+\t/*\n+\t * See if we want to use this console driver. If we didn't select\n+\t * a console we take the first one that registers here.\n+\t */\n+\tif (!has_preferred)\n+\t\thas_preferred |= take_console_noopts(newcon);\n+\n+\t/*\n+\t * Treat \"tty0\" (in case of \"stdout-path\" using) as a special case:\n+\t * \"tty0\" will be registered even if it was specified neither in\n+\t * \"bootargs\" nor in \"stdout-path\".\n+\t */\n+\tif (console_selected_by_of() && can_be_tty0(newcon))\n+\t\thas_preferred |= take_console_noopts(newcon);\n \n \t/*\n \t *\tSee if this console matches one we selected on\n","prefixes":["v2","2/2"]}