From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752594AbbL1SZS (ORCPT ); Mon, 28 Dec 2015 13:25:18 -0500 Received: from smtprelay0214.hostedemail.com ([216.40.44.214]:52441 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751199AbbL1SZP (ORCPT ); Mon, 28 Dec 2015 13:25:15 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::,RULES_HIT:41:69:334:355:368:369:379:541:560:599:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1381:1431:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:2828:3138:3139:3140:3141:3142:3354:3622:3865:3866:3867:3868:3870:3871:3872:4321:5007:6119:6261:7807:8603:10004:10400:10848:10946:11026:11232:11658:11783:11914:12043:12048:12296:12517:12519:12555:12683:12740:13138:13231:13894:14659:21080:30003:30012:30029:30034:30051:30054:30089: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:9,LUA_SUMMARY:none X-HE-Tag: toy55_108d13a853832 X-Filterd-Recvd-Size: 2914 Message-ID: <1451327112.3219.14.camel@perches.com> Subject: Re: [PATCH v1 1/1] lib/vsprintf: refactor duplicate code to xnumber() From: Joe Perches To: Andy Shevchenko , Andrew Morton , Rasmus Villemoes , linux-kernel@vger.kernel.org Date: Mon, 28 Dec 2015 10:25:12 -0800 In-Reply-To: <1451326703-122826-1-git-send-email-andriy.shevchenko@linux.intel.com> References: <1451326703-122826-1-git-send-email-andriy.shevchenko@linux.intel.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.18.3-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 Mon, 2015-12-28 at 20:18 +0200, Andy Shevchenko wrote: > xnumber() is a special helper to print a fixed size type in a hex format with > '0x' prefix with padding and reduced size. In the module we have already > several copies of such code. Consolidate them under xnumber() helper. > > There are couple of differences though. > > It seems nobody cared about the output in case of CONFIG_KALLSYMS=n when > printing symbol address because the asked width is not enough to care either > prefix or last byte. Fixed here. > > The %pNF specifier used to be allowed with a specific field width, though there > is neither any user of it nor mention in the documentation. > > Signed-off-by: Andy Shevchenko > --- >  lib/vsprintf.c | 43 +++++++++++++++---------------------------- >  1 file changed, 15 insertions(+), 28 deletions(-) > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > index dcf5646..e971549 100644 > --- a/lib/vsprintf.c > +++ b/lib/vsprintf.c > @@ -514,6 +514,16 @@ char *number(char *buf, char *end, unsigned long long num, >   return buf; >  } >   > +static noinline_for_stack > +char *xnumber(char *buf, char *end, unsigned long long value, unsigned int type, > +       struct printf_spec spec) xnumber isn't a great name. unsigned int type should probably be size_t size > +{ > + spec.field_width = 2 + 2 * type; > + spec.flags |= SPECIAL | SMALL | ZEROPAD; > + spec.base = 16; > + return number(buf, end, value, spec); > +} > + >  static void move_right(char *buf, char *end, unsigned len, unsigned spaces) >  { >   size_t size; > @@ -649,11 +659,7 @@ char *symbol_string(char *buf, char *end, void *ptr, >   >   return string(buf, end, sym, spec); >  #else > - spec.field_width = 2 * sizeof(void *); > - spec.flags |= SPECIAL | SMALL | ZEROPAD; > - spec.base = 16; > - > - return number(buf, end, value, spec); > + return xnumber(buf, end, value, sizeof(void *), spec);