From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935283AbcKKR24 (ORCPT ); Fri, 11 Nov 2016 12:28:56 -0500 Received: from smtprelay0139.hostedemail.com ([216.40.44.139]:39004 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934509AbcKKR2z (ORCPT ); Fri, 11 Nov 2016 12:28:55 -0500 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::::::::::::::::::::,RULES_HIT:41:355:379:421:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2198:2199:2393:2553:2559:2562:3138:3139:3140:3141:3142:3354:3622:3865:3867:3868:3870:3871:3872:3874:5007:6119:6261:6742:7875:7903:8603:10004:10400:10848:10967:11026:11232:11473:11658:11914:12043:12296:12438:12740:12760:13069:13146:13230:13311:13357:13439:14181:14659:14721:21080:21451:30054:30064:30070:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:3,LUA_SUMMARY:none X-HE-Tag: chalk78_3064bfba1932d X-Filterd-Recvd-Size: 3199 Date: Fri, 11 Nov 2016 12:28:51 -0500 From: Steven Rostedt To: Petr Mladek Cc: Linus Torvalds , Joe Perches , Andrew Morton , Sergey Senozhatsky , Jason Wessel , Jaroslav Kysela , Takashi Iwai , Chris Mason , Josef Bacik , David Sterba , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/4] printk/NMI: Handle continuous lines and missing newline Message-ID: <20161111122851.0417e6af@gandalf.local.home> In-Reply-To: <1478695291-12169-2-git-send-email-pmladek@suse.com> References: <1478695291-12169-1-git-send-email-pmladek@suse.com> <1478695291-12169-2-git-send-email-pmladek@suse.com> X-Mailer: Claws Mail 3.14.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 9 Nov 2016 13:41:28 +0100 Petr Mladek wrote: > /* > @@ -135,8 +170,8 @@ static void __printk_nmi_flush(struct irq_work *work) > __RAW_SPIN_LOCK_INITIALIZER(read_lock); > struct nmi_seq_buf *s = container_of(work, struct nmi_seq_buf, work); > unsigned long flags; > - size_t len, size; > - int i, last_i; > + size_t len; > + int i; > > /* > * The lock has two functions. First, one reader has to flush all > @@ -154,12 +189,14 @@ static void __printk_nmi_flush(struct irq_work *work) > /* > * This is just a paranoid check that nobody has manipulated > * the buffer an unexpected way. If we printed something then > - * @len must only increase. > + * @len must only increase. Also it should never overflow the > + * buffer size. > */ > - if (i && i >= len) { > + if ((i && i >= len) || len > sizeof(s->buffer)) { What's wrong with using s->len? Isn't that what is inside the buffer? Couldn't just checking against the buffer size print garbage? -- Steve > const char *msg = "printk_nmi_flush: internal error\n"; > > printk_nmi_flush_line(msg, strlen(msg)); > + len = 0; > } > > if (!len) > @@ -167,22 +204,7 @@ static void __printk_nmi_flush(struct irq_work *work) > > /* Make sure that data has been written up to the @len */ > smp_rmb(); > - > - size = min(len, sizeof(s->buffer)); > - last_i = i; > - > - /* Print line by line. */ > - for (; i < size; i++) { > - if (s->buffer[i] == '\n') { > - printk_nmi_flush_seq_line(s, last_i, i); > - last_i = i + 1; > - } > - } > - /* Check if there was a partial line. */ > - if (last_i < size) { > - printk_nmi_flush_seq_line(s, last_i, size - 1); > - printk_nmi_flush_line("\n", strlen("\n")); > - } > + i += printk_nmi_flush_buffer(s->buffer + i, len - i); > > /* > * Check that nothing has got added in the meantime and truncate