From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751794AbdH3Bwo (ORCPT ); Tue, 29 Aug 2017 21:52:44 -0400 Received: from smtprelay0123.hostedemail.com ([216.40.44.123]:34275 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751240AbdH3Bwn (ORCPT ); Tue, 29 Aug 2017 21:52:43 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::::::,RULES_HIT:41:355:379:541:599:800:960:966:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2196:2198:2199:2200:2393:2553:2559:2562:2693:2828:3138:3139:3140:3141:3142:3353:3622:3865:3866:3867:3868:3870:3871:3874:4321:4385:5007:7514:7875:10004:10400:10848:10967:11026:11232:11658:11783:11914:12043:12296:12555:12740:12895:13069:13161:13229:13311:13357:13439:13894:14180:14181:14659:14721:21080:21088:21627:30054:30060:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: robin18_8bcc96e652f00 X-Filterd-Recvd-Size: 3168 Message-ID: <1504057959.2786.4.camel@perches.com> Subject: Re: printk: what is going on with additional newlines? From: Joe Perches To: Steven Rostedt , Sergey Senozhatsky Cc: Linus Torvalds , Pavel Machek , Sergey Senozhatsky , Petr Mladek , Jan Kara , Andrew Morton , Jiri Slaby , Andreas Mohr , Tetsuo Handa , Linux Kernel Mailing List Date: Tue, 29 Aug 2017 18:52:39 -0700 In-Reply-To: <20170829211046.74644c8a@gandalf.local.home> References: <20170815025625.1977-1-sergey.senozhatsky@gmail.com> <20170828090521.GA25025@amd> <20170828102830.GA403@jagdpanzerIV.localdomain> <20170828122109.GA532@jagdpanzerIV.localdomain> <20170828124634.GD492@amd> <20170829134048.GA437@jagdpanzerIV.localdomain> <20170829195013.5048dc42@gandalf.local.home> <20170830010348.GB654@jagdpanzerIV.localdomain> <20170829211046.74644c8a@gandalf.local.home> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.6-1ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2017-08-29 at 21:10 -0400, Steven Rostedt wrote: > On Wed, 30 Aug 2017 10:03:48 +0900 > Sergey Senozhatsky wrote: > > > Hello, > > > > On (08/29/17 19:50), Steven Rostedt wrote: > > [..] > > > > A private buffer has none of those issues. > > > > > > What about using the seq_buf*() then? > > > > > > struct seq_buf s; > > > > > > buf = kmalloc(mysize); > > > seq_buf_init(&s, buf, mysize); > > > > > > seq_printf(&s,"blah blah %d", bah_blah); > > > [...] > > > seq_printf(&s, "my last print\n"); > > > > > > printk("%.*s", s.len, s.buffer); > > > > > > kfree(buf); > > > > could do. for a single continuation line printk("%.*s", s.len, s.buffer) > > this will work perfectly fine. for a more general case - backtraces, dumps, > > etc. - this requires some tweaks. > > We could simply add a seq_buf_printk() that is implemented in the printk > proper, to parse the seq_buf buffer properly, and add the timestamps and > such. No need. printk would already add timestamps. One addition might be to add a bit to initialize the buffer so that printk("%s", s->buffer) is simpler. --- diff --git a/include/linux/seq_buf.h b/include/linux/seq_buf.h index fb7eb9ccb1cd..fb6c9de0ee33 100644 --- a/include/linux/seq_buf.h +++ b/include/linux/seq_buf.h @@ -26,6 +26,7 @@ static inline void seq_buf_clear(struct seq_buf *s)  {   s->len = 0;   s->readpos = 0; + *s->buffer = 0;  }    static inline void