From patchwork Mon Jul 21 13:02:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 33964 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qg0-f71.google.com (mail-qg0-f71.google.com [209.85.192.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 41EFB20672 for ; Mon, 21 Jul 2014 13:03:53 +0000 (UTC) Received: by mail-qg0-f71.google.com with SMTP id f51sf14798983qge.2 for ; Mon, 21 Jul 2014 06:03:53 -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=7ywE4A7ES6KXG/EhCWL61uKfPDbLcDmXjxBG0zsIU6s=; b=UL5/i8bIMwK3RrSos7gtR4oZPKevYIBeVzl1WoxrEKtuvXANuxTpkskWxbeFshcdK+ zrZVeVr4IhNqolzEtNNnbbkDfJN7jUdFglKdpQqadMZXbrYHYEp8ila93/bnzTwIUxG3 2wphuxZAaKuzW3z7ZzLG6qAv5+RNyfiVoxKv+chB6Frp0gTmfyauPnHl0hST5le4bJCi oPNcjjxoe2IeyR7E21m3+ZxL1oC0PzBrKxt3eGHFUwZYTtjSi7ZNu7EEMXAOcIHkoK/g RdUPIjicMsCS1BUAkjTp6Lw5TXHlyk9hy//RnFop331zOFD/9390RakVDrsgqiOsgCyI pPyw== X-Gm-Message-State: ALoCoQk7zQeVn9hdBrYgUYr33kBRLhwDNf0uNIHadmHLKs3c5L4g2T8ZemSnG92sTEyA7eo7AH8O X-Received: by 10.236.43.20 with SMTP id k20mr10803612yhb.54.1405947832954; Mon, 21 Jul 2014 06:03:52 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.90.41 with SMTP id w38ls877290qgd.56.gmail; Mon, 21 Jul 2014 06:03:52 -0700 (PDT) X-Received: by 10.220.3.79 with SMTP id 15mr3638346vcm.63.1405947832796; Mon, 21 Jul 2014 06:03:52 -0700 (PDT) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id rz7si11271193vec.4.2014.07.21.06.03.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Jul 2014 06:03:52 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id id10so7353296vcb.35 for ; Mon, 21 Jul 2014 06:03:52 -0700 (PDT) X-Received: by 10.52.37.81 with SMTP id w17mr1295329vdj.95.1405947832679; Mon, 21 Jul 2014 06:03:52 -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 tc5csp110404vcb; Mon, 21 Jul 2014 06:03:52 -0700 (PDT) X-Received: by 10.68.163.100 with SMTP id yh4mr8090138pbb.122.1405947831586; Mon, 21 Jul 2014 06:03:51 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y5si14185358pas.185.2014.07.21.06.03.50 for ; Mon, 21 Jul 2014 06:03:50 -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 S1754590AbaGUNDs (ORCPT + 13 others); Mon, 21 Jul 2014 09:03:48 -0400 Received: from mail-ie0-f175.google.com ([209.85.223.175]:54810 "EHLO mail-ie0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932205AbaGUNCn (ORCPT ); Mon, 21 Jul 2014 09:02:43 -0400 Received: by mail-ie0-f175.google.com with SMTP id x19so6803252ier.34 for ; Mon, 21 Jul 2014 06:02:43 -0700 (PDT) X-Received: by 10.43.118.7 with SMTP id fo7mr26195950icc.3.1405947763087; Mon, 21 Jul 2014 06:02:43 -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 ri8sm38580163igc.0.2014.07.21.06.02.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 21 Jul 2014 06:02:42 -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 v5 5/7] printk: honor LOG_PREFIX in devkmsg_read() Date: Mon, 21 Jul 2014 08:02:39 -0500 Message-Id: <1405947761-26004-6-git-send-email-elder@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1405947761-26004-1-git-send-email-elder@linaro.org> References: <1405947761-26004-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.176 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 217a02a..e9e5104 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);