From patchwork Thu Jul 17 14:09:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 33782 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f200.google.com (mail-ie0-f200.google.com [209.85.223.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C9FDE20CA0 for ; Thu, 17 Jul 2014 14:09:52 +0000 (UTC) Received: by mail-ie0-f200.google.com with SMTP id at20sf21350157iec.11 for ; Thu, 17 Jul 2014 07:09:52 -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=guR56sB0M7CEep5wL1gfj7MlQuTAuzozpDaDoifUImU=; b=itWkaRKq/WG8Bct+BeKqKuIcGxEkm0O0XjFVIWIYHKU2dgfb0sEKDBlPx8F/E5kKg4 15wsEycO6JrzOMyZg9JQIC3QBSze59iJD4cB0eNjNBKqn3rmobSUoCtj6v7FUaQI810z UXng8oYD7FPGWIlJTQSPzke4FOLv3JWyHUSZx0rKxXl/vwYf57b0ncvZkq9kj7q1kF7S qY8sIWBLk+h10htr9/zv8nMBh9DMQy22Vbq/ulYlugh1OZuBKbWAknhIKOiLDHBWiX0R QxxktIhdOqXVU5LMDZTZpiUhNw61ko1QkkYznmTZ/jDKoj/aeXXMXMU9URIw7CpwoU3x vxww== X-Gm-Message-State: ALoCoQn9YUbySkxeA82wzKMboEE1QDWaTPFm5h89qUAK/4vUgqODyllgK3p7lTL1CTdalQCZfft7 X-Received: by 10.42.188.84 with SMTP id cz20mr17923070icb.1.1405606191801; Thu, 17 Jul 2014 07:09:51 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.50.73.227 with SMTP id o3ls1717653igv.27.gmail; Thu, 17 Jul 2014 07:09:51 -0700 (PDT) X-Received: by 10.70.90.207 with SMTP id by15mr37647559pdb.31.1405606191585; Thu, 17 Jul 2014 07:09:51 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id x19si6628393yhh.169.2014.07.17.07.09.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 17 Jul 2014 07:09:51 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id lf12so4621594vcb.40 for ; Thu, 17 Jul 2014 07:09:51 -0700 (PDT) X-Received: by 10.221.47.9 with SMTP id uq9mr18458306vcb.48.1405606191278; Thu, 17 Jul 2014 07:09:51 -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 tc5csp39421vcb; Thu, 17 Jul 2014 07:09:50 -0700 (PDT) X-Received: by 10.67.4.163 with SMTP id cf3mr5452407pad.92.1405606189664; Thu, 17 Jul 2014 07:09:49 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xs3si2483615pbb.247.2014.07.17.07.09.44; Thu, 17 Jul 2014 07:09:44 -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 S933375AbaGQOJV (ORCPT + 23 others); Thu, 17 Jul 2014 10:09:21 -0400 Received: from mail-ie0-f171.google.com ([209.85.223.171]:45870 "EHLO mail-ie0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933296AbaGQOJT (ORCPT ); Thu, 17 Jul 2014 10:09:19 -0400 Received: by mail-ie0-f171.google.com with SMTP id at1so2961153iec.2 for ; Thu, 17 Jul 2014 07:09:18 -0700 (PDT) X-Received: by 10.50.61.140 with SMTP id p12mr28009207igr.41.1405606154887; Thu, 17 Jul 2014 07:09:14 -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 hu10sm55538179igb.22.2014.07.17.07.09.14 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Jul 2014 07:09:14 -0700 (PDT) From: Alex Elder To: akpm@linux-foundation.org Cc: pmladek@suse.cz, bp@suse.de, john.stultz@linaro.org, jack@suse.cz, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/6] printk: honor LOG_PREFIX in devkmsg_read() Date: Thu, 17 Jul 2014 09:09:08 -0500 Message-Id: <1405606151-19875-4-git-send-email-elder@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1405606151-19875-1-git-send-email-elder@linaro.org> References: <1405606151-19875-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.181 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 1ee1862..5d719bf 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; @@ -619,11 +619,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 = '-'; len = sprintf(user->buf, "%u,%llu,%llu,%c;", (msg->facility << 3) | msg->level,