From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752181AbcFFPXf (ORCPT ); Mon, 6 Jun 2016 11:23:35 -0400 Received: from smtprelay0162.hostedemail.com ([216.40.44.162]:60600 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751834AbcFFPXe (ORCPT ); Mon, 6 Jun 2016 11:23:34 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::,RULES_HIT:41:69:355:379:541:599:960:968:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1543:1593:1594:1605:1711:1730:1747:1777:1792:2393:2553:2559:2562:2828:2900:3138:3139:3140:3141:3142:3622:3865:3866:3867:3868:3870:3871:3872:3873:3874:4250:4321:5007:6119:6691:7807:7875:7903:8531:10004:10400:10848:11026:11232:11473:11658:11783:11914:12043:12291:12296:12517:12519:12555:12683:12740:13095:13161:13229:13439:13894:14659:14721:21080:21433:21434:30012:30051:30054:30075: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:1,LUA_SUMMARY:none X-HE-Tag: foot72_58e7e8d37d840 X-Filterd-Recvd-Size: 4712 Message-ID: <1465226609.25087.10.camel@perches.com> Subject: Re: [PATCH] char: Prefer pr_* instead of printk From: Joe Perches To: Greg KH , Jyoti Singh Cc: arnd@arndb.de, linux-kernel@vger.kernel.org, Jyoti Singh Date: Mon, 06 Jun 2016 08:23:29 -0700 In-Reply-To: <20160604163640.GA6559@kroah.com> References: <1465051511-10758-1-git-send-email-jssengar92@gmail.com> <20160604163640.GA6559@kroah.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.18.5.2-0ubuntu3 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 Sat, 2016-06-04 at 09:36 -0700, Greg KH wrote: > On Sat, Jun 04, 2016 at 08:15:11PM +0530, Jyoti Singh wrote: > > > > This patch replaces all the printk[KERN_INFO] with pr_* in the file > > "ttyprintk.c" addressing the following warning: > > > > WARNING:Prefer [subsystem eg: netdev]_info([subsystem]dev, ... > > then dev_info(dev,... then pr_info(...  to printk(KERN_INFO ... > > Found with checkpatch > Sometimes checkpatch tells you to do things that are incorrect :) > > Are you _sure_ the code works the same before and after this?  The > ttyprintk driver is a bit "special". when pr_fmt is not defined (and ttyprint doesn't use pr_fmt), pr_ uses are printks. #define pr_info(fmt, ...) \ printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) The only one that is not a printk is pr_debug. It'd be simpler code if all the printks in this file were consolidated into something like a single tpk_flush function and the tpk_tag removed. Something like (completely untested, just typed and compiled with a couple typos fixed) ---  drivers/char/ttyprintk.c | 69 ++++++++++++++++++++++--------------------------  1 file changed, 31 insertions(+), 38 deletions(-) diff --git a/drivers/char/ttyprintk.c b/drivers/char/ttyprintk.c index b098d2d..67549ce 100644 --- a/drivers/char/ttyprintk.c +++ b/drivers/char/ttyprintk.c @@ -31,60 +31,53 @@ static struct ttyprintk_port tpk_port;   * printk messages (also suitable for logging service):   * - any cr is replaced by nl   * - adds a ttyprintk source tag in front of each line - * - too long message is fragmeted, with '\'nl between fragments - * - TPK_STR_SIZE isn't really the write_room limiting factor, bcause + * - too long message is fragmented, with '\'nl between fragments + * - TPK_STR_SIZE isn't really the write_room limiting factor, because   *   it is emptied on the fly during preformatting.   */  #define TPK_STR_SIZE 508 /* should be bigger then max expected line length */  #define TPK_MAX_ROOM 4096 /* we could assume 4K for instance */ -static const char *tpk_tag = "[U] "; /* U for User */  static int tpk_curr;   +static char tpk_buffer[TPK_STR_SIZE + 4]; + +static void tpk_flush(void) +{ + if (tpk_curr > 0) { + tpk_buffer[tpk_curr] = '\0'; + pr_info("[U] %s\n", tpk_buffer); + tpk_curr = 0; + } +} +  static int tpk_printk(const unsigned char *buf, int count)  { - static char tmp[TPK_STR_SIZE + 4];   int i = tpk_curr;     if (buf == NULL) { - /* flush tmp[] */ - if (tpk_curr > 0) { - /* non nl or cr terminated message - add nl */ - tmp[tpk_curr + 0] = '\n'; - tmp[tpk_curr + 1] = '\0'; - printk(KERN_INFO "%s%s", tpk_tag, tmp); - tpk_curr = 0; - } + tpk_flush();   return i;   }     for (i = 0; i < count; i++) { - tmp[tpk_curr] = buf[i]; - if (tpk_curr < TPK_STR_SIZE) { - switch (buf[i]) { - case '\r': - /* replace cr with nl */ - tmp[tpk_curr + 0] = '\n'; - tmp[tpk_curr + 1] = '\0'; - printk(KERN_INFO "%s%s", tpk_tag, tmp); - tpk_curr = 0; - if ((i + 1) < count && buf[i + 1] == '\n') - i++; - break; - case '\n': - tmp[tpk_curr + 1] = '\0'; - printk(KERN_INFO "%s%s", tpk_tag, tmp); - tpk_curr = 0; - break; - default: - tpk_curr++; - } - } else { + if (tpk_curr >= TPK_STR_SIZE) {   /* end of tmp buffer reached: cut the message in two */ - tmp[tpk_curr + 1] = '\\'; - tmp[tpk_curr + 2] = '\n'; - tmp[tpk_curr + 3] = '\0'; - printk(KERN_INFO "%s%s", tpk_tag, tmp); - tpk_curr = 0; + tpk_buffer[tpk_curr++] = '\\'; + tpk_flush(); + } + + switch (buf[i]) { + case '\r': + tpk_flush(); + if ((i + 1) < count && buf[i + 1] == '\n') + i++; + break; + case '\n': + tpk_flush(); + break; + default: + tpk_buffer[tpk_curr++] = buf[i]; + break;   }   }