From patchwork Fri Jul 18 14:14:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 33866 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f69.google.com (mail-pa0-f69.google.com [209.85.220.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 80E7720CA0 for ; Fri, 18 Jul 2014 14:15:45 +0000 (UTC) Received: by mail-pa0-f69.google.com with SMTP id kx10sf28107118pab.0 for ; Fri, 18 Jul 2014 07:15:44 -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=TzhRZa6c2VDB++mUZzVRfZdHzLrKtEmOTqBQfa2zPo4=; b=arlmqGtlKagjDxdaW27yYjIlglsmAvzAHQkjujEjtpSXDVGdZfv0fpP0OWpMHkvlJo fSa5MVWxYWdZ/Xe9FfLvVzWX+41S/qUbCG71E+Ay82ivW0G9Br9PGyG30axg1O3u1elx V29PRybdMZjnN4Bl5w/Wivhs0sI8jwIXBooneqx+uKzwKu7fl8vrWwWtTKWe2dfU2P/t 2Yf5XGQPOlniphhEJjqIdRxXL/tASr3SvNYewg6zEqHQ9U+5J48E741/prsT/wl+o/wN 7saO4uw3twdy508dTpBIQXUsuhM2giO8DOSQmTXQxtJn7Jrc3RK+Zs6qFt74p0YzzoLz fyhQ== X-Gm-Message-State: ALoCoQlgEjhek0cm2KIv2Oy3JOgQ9PFl06IjEaqJI9VSpHvTDZw8mizzp5CeIYv1aFBkcLp5IggQ X-Received: by 10.66.65.202 with SMTP id z10mr2391403pas.45.1405692942560; Fri, 18 Jul 2014 07:15:42 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.49.1 with SMTP id p1ls989443qga.97.gmail; Fri, 18 Jul 2014 07:15:42 -0700 (PDT) X-Received: by 10.53.13.200 with SMTP id fa8mr5143973vdd.57.1405692942453; Fri, 18 Jul 2014 07:15:42 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id ol3si5832108vcb.30.2014.07.18.07.15.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 18 Jul 2014 07:15:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id la4so7392400vcb.23 for ; Fri, 18 Jul 2014 07:15:37 -0700 (PDT) X-Received: by 10.52.120.38 with SMTP id kz6mr5191431vdb.86.1405692937293; Fri, 18 Jul 2014 07:15:37 -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 tc5csp14777vcb; Fri, 18 Jul 2014 07:15:36 -0700 (PDT) X-Received: by 10.68.69.110 with SMTP id d14mr5466494pbu.106.1405692935599; Fri, 18 Jul 2014 07:15:35 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f5si6117547pat.101.2014.07.18.07.15.33; Fri, 18 Jul 2014 07:15:33 -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 S1945989AbaGROPV (ORCPT + 25 others); Fri, 18 Jul 2014 10:15:21 -0400 Received: from mail-ie0-f175.google.com ([209.85.223.175]:61490 "EHLO mail-ie0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935112AbaGROOX (ORCPT ); Fri, 18 Jul 2014 10:14:23 -0400 Received: by mail-ie0-f175.google.com with SMTP id x19so4429530ier.6 for ; Fri, 18 Jul 2014 07:14:22 -0700 (PDT) X-Received: by 10.50.141.170 with SMTP id rp10mr9525815igb.6.1405692862640; Fri, 18 Jul 2014 07:14:22 -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 ga11sm6234171igd.8.2014.07.18.07.14.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 18 Jul 2014 07:14:22 -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 v3 4/7] printk: honor LOG_PREFIX in devkmsg_read() Date: Fri, 18 Jul 2014 09:14:16 -0500 Message-Id: <1405692859-32500-5-git-send-email-elder@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1405692859-32500-1-git-send-email-elder@linaro.org> References: <1405692859-32500-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.178 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 00367b5..b0e2934 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,