From patchwork Wed Jul 16 17:26:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 33746 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f70.google.com (mail-oa0-f70.google.com [209.85.219.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B7D0120792 for ; Wed, 16 Jul 2014 17:28:46 +0000 (UTC) Received: by mail-oa0-f70.google.com with SMTP id eb12sf6767902oac.1 for ; Wed, 16 Jul 2014 10:28:46 -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=iDyVmOuvnO/MNUXEXGooEj9Uor62PR3ebE2MIwmC3Q4=; b=K6QemiZo23J4J84fxTrclqyduM63CqgJliH4LWdFD0QxFUhWMpR31hWMgzGwYI1ZII KkiIJhYbnEfnCY0G2i2/sdA73AhX9Fe+DzPuB2ntH3GIun6AtglS2Z2ei2vXNNjE+T5O LXJ7uMpGSnff1B4h6jfuVKI+kB0ROkWs9OYGA2NYAz9XWm89Yk5vYe5FXoLABRJBfKgj mV5OftkDcbMBYIuJsKtQgJ7nL9B0qSbBJh9x0evgC4luas2fjeiMDjDjVWypKqXzr7gF x0wPTJTC+sQa1CAWvrnaTJp0bNDo2h0mjP0L0Of51CXYQE22Eeu/gH/fRMxSXTEP5WDE dOhA== X-Gm-Message-State: ALoCoQnNCTtx0qE7KNgMlFJXXNG0rrdlnsIEu2KEHqsl3lPbUGyuVgA3rnyvbJ1S0643OzAdZgod X-Received: by 10.182.123.232 with SMTP id md8mr14701530obb.41.1405531726182; Wed, 16 Jul 2014 10:28:46 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.106.119 with SMTP id d110ls180364qgf.47.gmail; Wed, 16 Jul 2014 10:28:46 -0700 (PDT) X-Received: by 10.220.80.142 with SMTP id t14mr10015280vck.55.1405531726030; Wed, 16 Jul 2014 10:28:46 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id uw7si9151642vec.24.2014.07.16.10.28.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 16 Jul 2014 10:28:46 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id lf12so2311764vcb.15 for ; Wed, 16 Jul 2014 10:28:46 -0700 (PDT) X-Received: by 10.52.23.71 with SMTP id k7mr18412177vdf.27.1405531725963; Wed, 16 Jul 2014 10:28:45 -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 tc5csp316867vcb; Wed, 16 Jul 2014 10:28:45 -0700 (PDT) X-Received: by 10.70.35.43 with SMTP id e11mr15718716pdj.10.1405531725132; Wed, 16 Jul 2014 10:28:45 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sn4si15015756pab.203.2014.07.16.10.28.44; Wed, 16 Jul 2014 10:28: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 S1760324AbaGPR2Q (ORCPT + 28 others); Wed, 16 Jul 2014 13:28:16 -0400 Received: from mail-ig0-f169.google.com ([209.85.213.169]:36078 "EHLO mail-ig0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759448AbaGPR1F (ORCPT ); Wed, 16 Jul 2014 13:27:05 -0400 Received: by mail-ig0-f169.google.com with SMTP id r2so4154548igi.2 for ; Wed, 16 Jul 2014 10:27:05 -0700 (PDT) X-Received: by 10.50.1.38 with SMTP id 6mr18409801igj.39.1405531625053; Wed, 16 Jul 2014 10:27:05 -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 dx6sm32137412igb.15.2014.07.16.10.27.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 16 Jul 2014 10:27:04 -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 2/4] printk: honor LOG_PREFIX in devkmsg_read() Date: Wed, 16 Jul 2014 12:26:58 -0500 Message-Id: <1405531620-9983-3-git-send-email-elder@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1405531620-9983-1-git-send-email-elder@linaro.org> References: <1405531620-9983-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.170 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 | set | 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 301ade3..9e9cf93 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,