From patchwork Wed Mar 15 10:28:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksey Makarov X-Patchwork-Id: 95327 Delivered-To: patch@linaro.org Received: by 10.140.89.134 with SMTP id v6csp259023qgd; Wed, 15 Mar 2017 03:33:16 -0700 (PDT) X-Received: by 10.99.52.202 with SMTP id b193mr360323pga.131.1489573996124; Wed, 15 Mar 2017 03:33:16 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n8si1702089pll.303.2017.03.15.03.33.16; Wed, 15 Mar 2017 03:33:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-serial-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751922AbdCOKdP (ORCPT + 2 others); Wed, 15 Mar 2017 06:33:15 -0400 Received: from mail-lf0-f44.google.com ([209.85.215.44]:33374 "EHLO mail-lf0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751580AbdCOKdO (ORCPT ); Wed, 15 Mar 2017 06:33:14 -0400 Received: by mail-lf0-f44.google.com with SMTP id a6so5002606lfa.0 for ; Wed, 15 Mar 2017 03:33:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=6z3wYW6YI0Q0bDDZuv+iY4zl/y9CNA9ShbNtD9bOivo=; b=HtvgFpdIgYINBE/3pmHChKYvtp9dO55UFdTv9niIyG2nsbin1fvEkKDn6//puKjPaM iqfek9+jyuJpb2/85hq1TGEj43dLZ9TMI6sgriOYrEEtBN+udcPJm3UD82x7lQY2o6YR 6tN5RQv/N5I8cpd8ePCEBawdcKo/zv33x0pRU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=6z3wYW6YI0Q0bDDZuv+iY4zl/y9CNA9ShbNtD9bOivo=; b=Sw6S3K+4hVdCrCGmA8+d8OM/rPEmnGVpQY9KFpn2yeXZpv5C/ogOZZMM+Wp0z2dsHn 2NL2o4cv+jAXkWd9OEN7WqHEu2wrHB3ZnVFNSi7ZimmHNnUbMninY5wE9P51tmUTXfR4 qFpHggGiU9tkYJ4vOV2u32wjkcem9d4r95qGDsppqTHgjKi15hWRSlR91iS2DEQOdLVN PIyoav+uQW5NcwaRyj2xr82TGHUvxgIDxUz8ehuCUghFgNMWwHvHnySHZiqqEYmeLXD0 387p9HXfkECKYWCBmJ5ZPeaa7W3E/NemMvdRhTBZWVpZwXMnw8ZCZb+P0AOE4uRmPQqv ULgg== X-Gm-Message-State: AFeK/H0RXrwQgBayIn0gNS2KG167cfft9pSc5rLgBl6FyTZori1dm5C8G3t2DsjOLW3rUqWG X-Received: by 10.25.227.77 with SMTP id c13mr706283lfk.43.1489573992499; Wed, 15 Mar 2017 03:33:12 -0700 (PDT) Received: from localhost.localdomain (nivc-213.auriga.ru. [80.240.102.213]) by smtp.gmail.com with ESMTPSA id 4sm265163ljf.33.2017.03.15.03.33.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Mar 2017 03:33:11 -0700 (PDT) From: Aleksey Makarov To: linux-serial@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Aleksey Makarov , Sudeep Holla , Greg Kroah-Hartman , Peter Hurley , Jiri Slaby , Robin Murphy , Steven Rostedt , "Nair, Jayachandran" , Sergey Senozhatsky , Petr Mladek Subject: [PATCH v5 0/3] printk: fix double printing with earlycon Date: Wed, 15 Mar 2017 13:28:49 +0300 Message-Id: <20170315102854.1763-1-aleksey.makarov@linaro.org> X-Mailer: git-send-email 2.12.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org If a console was specified by ACPI SPCR table _and_ command line parameters like "console=ttyAMA0" _and_ "earlycon" were specified, then log messages appear twice. This issue was addressed in the patch [1] but the approach was wrong and a revert [2] was suggested. First two patches "printk: fix name/type/scope of preferred_console var" and "printk: rename selected_console -> preferred_console" were sent some time ago as one patch "printk: fix name and type of some variables" [3]. They fix name/type/scope of some variables without changing the logic. The real fix is in the second patch. The root cause is that the code traverses the list of specified consoles (the `console_cmdline` array) and stops at the first match. But it may happen that the same console is referred by the elements of this array twice: pl011,mmio,0x87e024000000,115200 -- from SPCR ttyAMA0 -- from command line but in this case `preferred_console` points to the second entry and the flag CON_CONSDEV is not set, so bootconsole is not deregistered. To fix that, introduce an invariant "The last non-braille console is always the preferred one" on the entries of the console_cmdline array and don't try to check for double entries. Then traverse it in reverse order to be sure that if the console is preferred then it will be the first matching entry. v5: - rewrite 3/3. Insetead of rearranging the loop, introduce an invariant "The last non-braille console is always the preferred one" on the entries of the console_cmdline array and don't try to check for double entries. Then traverse it in reverse order to be sure that if the console is preferred then it will be the first matching entry. - add a better explanation from Petr Mladek for 2/3. v4: It was not sent upstream due to some problems in implementation of 3/3. - add some Acked-by: and Reviewed-by: to 1/3 and 2/3 - v2 was closer to the original logic, even though v3 looked simpler. The problem is that newcon->setup() is called twice, firstly from newcon->match(), then explicitly. And it could be called third time later in another call to newcon->match(). Implement correct sequence: 1) try to match against preferred_console, 2) if that fails check other entries of console_cmdline. Also move braille console matching/registration to a separate pass to simplify the code. v3 (only for 3/3): https://lkml.kernel.org/r/20170303154946.15399-1-aleksey.makarov@linaro.org - v2 still changes the logic of the code and calls newcon->match() several times. V3 fixes that. It initially matches the console against the preferred_console entry, and then if that fails, against other entries. v2: https://lkml.kernel.org/r/20170302131153.22733-1-aleksey.makarov@linaro.org - split the patch that renames `selected_console` and `preferred_console` into two patches (Steven Rostedt) - add a comment explaining why we need a separate match to check for preferred_console (Steven Rostedt) - v1 of this patchset changed the logic of console initialization a bit. That could lead to bugs/incompatibilities. Use the exactly the same logic as in the original code. v1: https://lkml.kernel.org/r/20170301161347.4202-1-aleksey.makarov@linaro.org [1] https://lkml.kernel.org/r/1485963998-921-1-git-send-email-sudeep.holla@arm.com commit aea9a80ba98a ("tty: serial: pl011: add ttyAMA for matching pl011 console") [2] https://lkml.kernel.org/r/20170301152304.29635-1-aleksey.makarov@linaro.org [3] https://lkml.kernel.org/r/1455299022-11641-2-git-send-email-aleksey.makarov@linaro.org Aleksey Makarov (3): printk: fix name/type/scope of preferred_console var printk: rename selected_console -> preferred_console printk: fix double printing with earlycon kernel/printk/printk.c | 61 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 24 deletions(-) -- 2.12.0 -- To unsubscribe from this list: send the line "unsubscribe linux-serial" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html