From patchwork Tue Jul 22 12:13:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 34086 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f200.google.com (mail-pd0-f200.google.com [209.85.192.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 946D420672 for ; Tue, 22 Jul 2014 12:14:09 +0000 (UTC) Received: by mail-pd0-f200.google.com with SMTP id w10sf52484406pde.3 for ; Tue, 22 Jul 2014 05:14:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=Y8Kk4oiSvbdy6gmn+koj/NAk9oM1DBqosKp+F0V99fA=; b=ie+4qYB8xnVe8zqi4UCXxGGb8jlxJEmTWOWEjL8PXICZyUzH4AERsQZ0TMbrcj02g9 KpU+fe96sHFglXrFf4QvI2xLABnCK1Ckwamfd9qYJCdZRlMaLJCLr1Gw0KMfc7FyaENO NFNveBNUf4Le6ejam29SPk1sxUJt/BHwmAqhIovt+b0ffPpbPAUIWxqHgKtIbfZ3rbMW uF8fvQx0HNBmHrcAJkDte33q17Tb+tsxmJgkKAdVIxo1qBzFHZDcsO6CQANnyq0kRaC4 T2ZX+8H1Uib9/2pK154m4zH7uUGqTWeQjPRTOKJKiFuwD2SoDaAhBuyQnxjitWAByxOr eEBQ== X-Gm-Message-State: ALoCoQlS2/fMJDgs4jl/MQN8nD2Dcz3w2aDJTzq5otWJjcGl0muz+XVbYBdzfXX2uEdtjEjYwFzt X-Received: by 10.66.192.201 with SMTP id hi9mr6787495pac.0.1406031248770; Tue, 22 Jul 2014 05:14:08 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.37.142 with SMTP id r14ls2312091qgr.16.gmail; Tue, 22 Jul 2014 05:14:08 -0700 (PDT) X-Received: by 10.52.252.226 with SMTP id zv2mr33176416vdc.19.1406031248628; Tue, 22 Jul 2014 05:14:08 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id oh5si340995vcb.6.2014.07.22.05.14.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 22 Jul 2014 05:14:08 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id lf12so14617452vcb.29 for ; Tue, 22 Jul 2014 05:14:08 -0700 (PDT) X-Received: by 10.52.120.38 with SMTP id kz6mr10267156vdb.86.1406031248189; Tue, 22 Jul 2014 05:14:08 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp190731vcb; Tue, 22 Jul 2014 05:14:07 -0700 (PDT) X-Received: by 10.70.101.163 with SMTP id fh3mr708539pdb.57.1406031247022; Tue, 22 Jul 2014 05:14:07 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h9si103639pdn.499.2014.07.22.05.14.06 for ; Tue, 22 Jul 2014 05:14:06 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755423AbaGVMNz (ORCPT + 12 others); Tue, 22 Jul 2014 08:13:55 -0400 Received: from mail-ie0-f180.google.com ([209.85.223.180]:37591 "EHLO mail-ie0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755367AbaGVMNw (ORCPT ); Tue, 22 Jul 2014 08:13:52 -0400 Received: by mail-ie0-f180.google.com with SMTP id at20so8023631iec.39 for ; Tue, 22 Jul 2014 05:13:51 -0700 (PDT) X-Received: by 10.50.62.80 with SMTP id w16mr15734880igr.21.1406031231505; Tue, 22 Jul 2014 05:13:51 -0700 (PDT) Received: from localhost.localdomain (c-24-245-18-91.hsd1.mn.comcast.net. [24.245.18.91]) by mx.google.com with ESMTPSA id tp4sm21112991igb.9.2014.07.22.05.13.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Jul 2014 05:13:51 -0700 (PDT) From: Alex Elder To: akpm@linux-foundation.org Cc: kay@vrfy.org, pmladek@suse.cz, bp@suse.de, john.stultz@linaro.org, jack@suse.cz, linux-kernel@vger.kernel.org Subject: [PATCH v6 5/7] printk: honor LOG_PREFIX in devkmsg_read() Date: Tue, 22 Jul 2014 07:13:48 -0500 Message-Id: <1406031230-18107-6-git-send-email-elder@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1406031230-18107-1-git-send-email-elder@linaro.org> References: <1406031230-18107-1-git-send-email-elder@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: elder@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , In devkmsg_read(), a variable "cont" holds a character that's used to indicate whether a given log line is a "continuation", that is, whether a log record should be merged with the one before or after it. If a record should be merged with its successor (but not its predecessor) that character is 'c'. And the line following such a 'c' log record is normally marked with a '+' to show it is continues its predecessor. Any other cases are marked '-', indicating the log record stands on its own. There is an exception. If a log record is marked LOG_PREFIX, it indicates that this record represents a new log entry, implicitly terminating the predecessor--even if the predecessor would otherwise have been continued. So a record marked LOG_PREFIX (that is not also marked LOG_CONT) should have '-' for its "cont" variable. The logic that determines this "continuation" character has a bug that gets that exceptional case wrong. The specific case that produces the wrong result is when all of these conditions are non-zero: user->prev & LOG_CONT msg->flags & LOG_PREFIX msg->flags & LOG_CONT The bug is that despite the message's LOG_PREFIX flag, the "cont" character is getting set to '+' rather than 'c'. The problem is that the message's LOG_PREFIX flag is getting ignored if its LOG_CONT flag is also set. Rearrange the logic here to produce the correct result. The following table concisely defines the problem: prev | msg | msg ||"cont" CONT |PREFIX| CONT || char ------+------+------++------ clear| clear| clear|| '-' clear| clear| set || 'c' clear| set | clear|| '-' clear| set | set || 'c' set | clear| clear|| '+' set | clear| set || '+' set | set | clear|| '-' set | set | set || '+' <-- should be 'c' Signed-off-by: Alex Elder Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 1ff3a05..25b7527 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -572,7 +572,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf, struct printk_log *msg; u64 ts_usec; size_t i; - char cont = '-'; + char cont; size_t len; ssize_t ret; bool insert_newline; @@ -620,11 +620,12 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf, * better readable output. 'c' in the record flags mark the first * fragment of a line, '+' the following. */ - if (msg->flags & LOG_CONT && !(user->prev & LOG_CONT)) - cont = 'c'; - else if ((msg->flags & LOG_CONT) || - ((user->prev & LOG_CONT) && !(msg->flags & LOG_PREFIX))) + if ((user->prev & LOG_CONT) && !(msg->flags & LOG_PREFIX)) cont = '+'; + else if (msg->flags & LOG_CONT) + cont = 'c'; + else + cont = '-'; /* Insert a newline if the previous line was not terminated properly */ insert_newline = (user->prev & LOG_CONT) && (msg->flags & LOG_PREFIX);