From patchwork Fri Jul 18 21:28:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 33914 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qg0-f69.google.com (mail-qg0-f69.google.com [209.85.192.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9ECDD208CF for ; Fri, 18 Jul 2014 21:29:13 +0000 (UTC) Received: by mail-qg0-f69.google.com with SMTP id a108sf8648126qge.8 for ; Fri, 18 Jul 2014 14:29:13 -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=kH6OtL3GtDavOSJKvK5BNiwOSyIG7n/ES8XF+l+Q6lI=; b=ZSeGcRIIBQSZqabfXWrOkptYKPjdlF6iGKsVqC7e6ID7jZ6OODIpQfNf9/O2osnKfD nGu2z8A7wxU4n7nkoXGbcqL38U16YTJiCbq/6C1e/bXD5clZKKum/0QEwNW/NN8iOlj3 J4oubVU5E5xlzyjkjpSwAC2dkLpgEMTf+ZmwcT5VFIgNyWUB0Cp4XBiVH9j4LaRZJIbN A4b1xIqLcvNTa9w0Jr9RYV0NQZ2YsGYpSDSyJjDEYViutMKajMRCCoWDAR0O5RAyRWR9 QAYJBc9E3O1aUzhvrV6WAuHwGKUIZGJIzkYUf/9hDtqdWVx/SQMAGmUj0JC+E3oRPjRs jT+Q== X-Gm-Message-State: ALoCoQlcdvYeoKILyVvha6Li4Boujx2PffLjO+9sEoENSYxfcH2IEGEZCGi0eJuWMp53yZADUH3L X-Received: by 10.236.124.131 with SMTP id x3mr3259614yhh.14.1405718953467; Fri, 18 Jul 2014 14:29:13 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.42.117 with SMTP id b108ls1151701qga.19.gmail; Fri, 18 Jul 2014 14:29:13 -0700 (PDT) X-Received: by 10.220.196.207 with SMTP id eh15mr7524853vcb.78.1405718953325; Fri, 18 Jul 2014 14:29:13 -0700 (PDT) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id vl1si6947036vec.61.2014.07.18.14.29.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 18 Jul 2014 14:29:13 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.179 as permitted sender) client-ip=209.85.220.179; Received: by mail-vc0-f179.google.com with SMTP id hq11so6865986vcb.24 for ; Fri, 18 Jul 2014 14:29:13 -0700 (PDT) X-Received: by 10.220.118.136 with SMTP id v8mr9669137vcq.50.1405718953237; Fri, 18 Jul 2014 14:29:13 -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 tc5csp42372vcb; Fri, 18 Jul 2014 14:29:12 -0700 (PDT) X-Received: by 10.68.166.98 with SMTP id zf2mr8416293pbb.148.1405718951077; Fri, 18 Jul 2014 14:29:11 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qe5si7203739pac.103.2014.07.18.14.29.10; Fri, 18 Jul 2014 14:29: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 S1946152AbaGRV3B (ORCPT + 23 others); Fri, 18 Jul 2014 17:29:01 -0400 Received: from mail-ig0-f173.google.com ([209.85.213.173]:33592 "EHLO mail-ig0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1946008AbaGRV2N (ORCPT ); Fri, 18 Jul 2014 17:28:13 -0400 Received: by mail-ig0-f173.google.com with SMTP id h18so1071727igc.12 for ; Fri, 18 Jul 2014 14:28:13 -0700 (PDT) X-Received: by 10.50.73.198 with SMTP id n6mr13283895igv.11.1405718893110; Fri, 18 Jul 2014 14:28:13 -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 vk3sm9535840igb.17.2014.07.18.14.28.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 18 Jul 2014 14:28:12 -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 v4 4/7] printk: honor LOG_PREFIX in devkmsg_read() Date: Fri, 18 Jul 2014 16:28:02 -0500 Message-Id: <1405718885-11227-5-git-send-email-elder@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1405718885-11227-1-git-send-email-elder@linaro.org> References: <1405718885-11227-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.179 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 ad644b3..f8ab63c 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,