From patchwork Mon Jul 28 13:29:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 34364 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f70.google.com (mail-pa0-f70.google.com [209.85.220.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5628520AE8 for ; Mon, 28 Jul 2014 13:30:12 +0000 (UTC) Received: by mail-pa0-f70.google.com with SMTP id lf10sf52844858pab.9 for ; Mon, 28 Jul 2014 06:30:11 -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=ciQ9RjBSxIu08Bamyt2IqUDG+hV4NxZxt+upUAyHgJA=; b=Z/fySidwANqtHfvXCxVukCs4HrbXcchqzHIk80Im94KcaXAUzuoKFuzyBPOK8m2QWz EdDMFI69SIdHaTTXDeM1KSU/Ywf6Eq+WYhfMoyzF6Mtb4YjuRGywMEtUpZGzbNsXhf9B Ea7s3VSFgniui4nQzzt+J7XkHO6PYI3Gag9iWhmrctJDSe8zPNAKU1eHwbJ1v84bCTbL BqrP+ZjQcmYqDBfYREZLiwl0D63AKUkSgJMwjoqnH1lrcq1j2FZAYdGayWS35uXj3Blk U2wCSMgU+Ww/uGTuxSkA4pYTMtsZfYPSCPeIVfTg3YDhV3qxHSZp1jD5tiSX+U1rDD+d 5nHA== X-Gm-Message-State: ALoCoQlK+uR1VrGu1gR0LHzOfiDUMRINOuQ7dmzsx4MjXkXKdudMP1n+1FDms5HEFsnH6+Bib4/d X-Received: by 10.66.158.193 with SMTP id ww1mr16687756pab.12.1406554211442; Mon, 28 Jul 2014 06:30:11 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.21.203 with SMTP id 69ls1999327qgl.13.gmail; Mon, 28 Jul 2014 06:30:11 -0700 (PDT) X-Received: by 10.220.174.137 with SMTP id t9mr8249354vcz.12.1406554211308; Mon, 28 Jul 2014 06:30:11 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id y3si12403715vdx.29.2014.07.28.06.30.11 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 28 Jul 2014 06:30:11 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.169 as permitted sender) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id le20so2368348vcb.0 for ; Mon, 28 Jul 2014 06:30:11 -0700 (PDT) X-Received: by 10.52.120.38 with SMTP id kz6mr1677965vdb.86.1406554211236; Mon, 28 Jul 2014 06:30:11 -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 tc5csp166657vcb; Mon, 28 Jul 2014 06:30:10 -0700 (PDT) X-Received: by 10.68.245.162 with SMTP id xp2mr38253000pbc.60.1406554210145; Mon, 28 Jul 2014 06:30:10 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cm7si8949989pdb.231.2014.07.28.06.30.09 for ; Mon, 28 Jul 2014 06:30:10 -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 S1752837AbaG1NaH (ORCPT + 26 others); Mon, 28 Jul 2014 09:30:07 -0400 Received: from mail-ig0-f171.google.com ([209.85.213.171]:42406 "EHLO mail-ig0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752743AbaG1N3Z (ORCPT ); Mon, 28 Jul 2014 09:29:25 -0400 Received: by mail-ig0-f171.google.com with SMTP id l13so3644343iga.10 for ; Mon, 28 Jul 2014 06:29:24 -0700 (PDT) X-Received: by 10.42.12.6 with SMTP id w6mr43981584icw.69.1406554164812; Mon, 28 Jul 2014 06:29:24 -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 i10sm26832385igm.13.2014.07.28.06.29.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Jul 2014 06:29:24 -0700 (PDT) From: Alex Elder To: akpm@linux-foundation.org Cc: kay@vrfy.org, pmladek@suse.cz, john.stultz@linaro.org, jack@suse.cz, linux-kernel@vger.kernel.org Subject: [PATCH v7 5/7] printk: honor LOG_PREFIX in devkmsg_read() Date: Mon, 28 Jul 2014 08:29:18 -0500 Message-Id: <1406554160-9562-6-git-send-email-elder@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1406554160-9562-1-git-send-email-elder@linaro.org> References: <1406554160-9562-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.169 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 4b063c8..1eb07f4 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,