Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1286925

Re: [PATCH v2] of/address: replace printk() with pr_debug() / pr_err()

Path csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!bofh.it!news.nic.it!robomod
From Joe Perches <joe@perches.com>
Newsgroups linux.kernel
Subject Re: [PATCH v2] of/address: replace printk() with pr_debug() / pr_err()
Date Wed, 09 Dec 2015 01:10:02 +0100
Message-ID <qDAuu-Rv-1@gated-at.bofh.it> (permalink)
References <qDsZZ-4yl-37@gated-at.bofh.it> <qDt9E-4CC-27@gated-at.bofh.it> <qDtW2-59U-25@gated-at.bofh.it> <qDxZD-7Cj-1@gated-at.bofh.it>
X-Original-To Rob Herring <robh+dt@kernel.org>, Andrew Morton <akpm@linux-foundation.org>
X-Session-Marker 6A6F6540706572636865732E636F6D
X-Spam-Summary 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::,RULES_HIT:2:41:69:355:379:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1535:1593:1594:1605:1606:1730:1747:1777:1792:2393:2553:2559:2562:2693:2828:3138:3139:3140:3141:3142:3622:3743:3865:3866:3867:3870:3871:3872:3874:4117:4250:4321:5007:6261:7903:7904:8603:10004:10848:11026:11232:11473:11658:11783:11889:11914:12043:12291:12296:12438:12517:12519:12555:12683:12740:13894:14659:21080:30003:30034:30054:30056: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:2,LUA_SUMMARY:none
X-He-Tag root29_402840c18af35
X-Filterd-Recvd-Size 6921
Content-Type text/plain; charset="ISO-8859-1"
X-Mailer Evolution 3.18.2-0ubuntu2
MIME-Version 1.0
Content-Transfer-Encoding 8bit
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 173
Organization linux.* mail to news gateway
X-Original-Cc Masahiro Yamada <yamada.masahiro@socionext.com>, "devicetree@vger.kernel.org" <devicetree@vger.kernel.org>, Frank Rowand <frowand.list@gmail.com>, "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>, Grant Likely <grant.likely@linaro.org>
X-Original-Date Tue, 08 Dec 2015 16:03:59 -0800
X-Original-Message-ID <1449619439.18646.20.camel@perches.com>
X-Original-References <1449590868-19070-1-git-send-email-yamada.masahiro@socionext.com> <1449591386.3315.2.camel@perches.com> <1449594231.13275.2.camel@perches.com> <CAL_JsqJ0oftptSxyAcGOnQ3XA9v55B2n=8DiWBcErcLKgfsppg@mail.gmail.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1286925

Show key headers only | View raw


On Tue, 2015-12-08 at 15:28 -0600, Rob Herring wrote:
> On Tue, Dec 8, 2015 at 11:03 AM, Joe Perches <joe@perches.com> wrote:
> > On Tue, 2015-12-08 at 08:16 -0800, Joe Perches wrote:
> > > On Wed, 2015-12-09 at 01:07 +0900, Masahiro Yamada wrote:
> > > > Trivial changes suggested by checkpatch.pl.
> > > []
> > > > diff --git a/drivers/of/address.c b/drivers/of/address.c
> > > []
> > > > @@ -23,7 +23,7 @@ static int __of_address_to_resource(struct device_node *dev,
> > > >  #ifdef DEBUG
> > > >  static void of_dump_addr(const char *s, const __be32 *addr, int na)
> > > >  {
> > > > -   printk(KERN_DEBUG "%s", s);
> > > > +   pr_debug("%s", s);
> > > >     while (na--)
> > > >             printk(" %08x", be32_to_cpu(*(addr++)));
> > > >     printk("\n");
[]
> > static void of_dumpaddr(const char *s, const __be32 *addr, int na)
> > {
> >         print_hex_dump_debug(s, DUMP_PREFIX_NONE, 16, 1,
> >                              addr, na * sizeof(__be32), false);
> > }
> 
> Except that it doesn't do the endian swapping. Looking closer at this,
> we should just drop this hunk. So I will take v1.

Maybe endian conversions should be added to hex_dump_debug like:
(probably doesn't apply.  Evolution 3.18 is horrible)
---
 include/linux/printk.h |  7 +++++++
 lib/hexdump.c          | 56 +++++++++++++++++++++++++++++++++++---------------
 2 files changed, 47 insertions(+), 16 deletions(-)

diff --git a/include/linux/printk.h b/include/linux/printk.h
index 9729565..4be190c 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -424,6 +424,13 @@ enum {
 	DUMP_PREFIX_ADDRESS,
 	DUMP_PREFIX_OFFSET
 };
+
+enum {
+	DUMP_TYPE_CPU = 0,
+	DUMP_TYPE_LE = BIT(30),
+	DUMP_TYPE_BE = BIT(31)
+};
+
 extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
 			      int groupsize, char *linebuf, size_t linebuflen,
 			      bool ascii);
diff --git a/lib/hexdump.c b/lib/hexdump.c
index 992457b..49113aa 100644
--- a/lib/hexdump.c
+++ b/lib/hexdump.c
@@ -81,6 +81,7 @@ EXPORT_SYMBOL(bin2hex);
  * @len: number of bytes in the @buf
  * @rowsize: number of bytes to print per line; must be 16 or 32
  * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1)
+ *             OR'd with DUMP_TYPE_BE or DUMP_TYPE_LE for endian conversions
  * @linebuf: where to put the converted data
  * @linebuflen: total size of @linebuf, including space for terminating NUL
  * @ascii: include ASCII after the hex output
@@ -114,19 +115,20 @@ int hex_dump_to_buffer(const void *buf, size_t len, int rowsize, int groupsize,
 	int j, lx = 0;
 	int ascii_column;
 	int ret;
+	int actual_groupsize = groupsize & ~(DUMP_TYPE_LE | DUMP_TYPE_BE);
 
 	if (rowsize != 16 && rowsize != 32)
 		rowsize = 16;
 
 	if (len > rowsize)		/* limit to one line at a time */
 		len = rowsize;
-	if (!is_power_of_2(groupsize) || groupsize > 8)
-		groupsize = 1;
-	if ((len % groupsize) != 0)	/* no mixed size output */
-		groupsize = 1;
+	if (!is_power_of_2(actual_groupsize) || actual_groupsize > 8)
+		actual_groupsize = 1;
+	if ((len % actual_groupsize) != 0)	/* no mixed size output */
+		actual_groupsize = 1;
 
-	ngroups = len / groupsize;
-	ascii_column = rowsize * 2 + rowsize / groupsize + 1;
+	ngroups = len / actual_groupsize;
+	ascii_column = rowsize * 2 + rowsize / actual_groupsize + 1;
 
 	if (!linebuflen)
 		goto overflow1;
@@ -134,35 +136,56 @@ int hex_dump_to_buffer(const void *buf, size_t len, int rowsize, int groupsize,
 	if (!len)
 		goto nil;
 
-	if (groupsize == 8) {
+	if (actual_groupsize == 8) {
 		const u64 *ptr8 = buf;
 
 		for (j = 0; j < ngroups; j++) {
+			u64 val;
+
+			if (groupsize & DUMP_TYPE_LE)
+				val = get_unaligned_le64(ptr8 + j);
+			else if (groupsize & DUMP_TYPE_BE)
+				val = get_unaligned_be64(ptr8 + j);
+			else
+				val = get_unaligned(ptr8 + j);
 			ret = snprintf(linebuf + lx, linebuflen - lx,
-				       "%s%16.16llx", j ? " " : "",
-				       get_unaligned(ptr8 + j));
+				       "%s%16.16llx", j ? " " : "", val);
 			if (ret >= linebuflen - lx)
 				goto overflow1;
 			lx += ret;
 		}
-	} else if (groupsize == 4) {
+	} else if (actual_groupsize == 4) {
 		const u32 *ptr4 = buf;
 
 		for (j = 0; j < ngroups; j++) {
+			u32 val;
+
+			if (groupsize & DUMP_TYPE_LE)
+				val = get_unaligned_le32(ptr4 + j);
+			else if (groupsize & DUMP_TYPE_BE)
+				val = get_unaligned_be32(ptr4 + j);
+			else
+				val = get_unaligned(ptr4 + j);
 			ret = snprintf(linebuf + lx, linebuflen - lx,
-				       "%s%8.8x", j ? " " : "",
-				       get_unaligned(ptr4 + j));
+				       "%s%8.8x", j ? " " : "", val);
 			if (ret >= linebuflen - lx)
 				goto overflow1;
 			lx += ret;
 		}
-	} else if (groupsize == 2) {
+	} else if (actual_groupsize == 2) {
 		const u16 *ptr2 = buf;
 
 		for (j = 0; j < ngroups; j++) {
+			u16 val;
+
+			if (groupsize & DUMP_TYPE_LE)
+				val = get_unaligned_le16(ptr2 + j);
+			else if (groupsize & DUMP_TYPE_BE)
+				val = get_unaligned_be16(ptr2 + j);
+			else
+				val = get_unaligned(ptr2 + j);
 			ret = snprintf(linebuf + lx, linebuflen - lx,
-				       "%s%4.4x", j ? " " : "",
-				       get_unaligned(ptr2 + j));
+				       "%s%4.4x", j ? " " : "", val);
 			if (ret >= linebuflen - lx)
 				goto overflow1;
 			lx += ret;
@@ -203,7 +226,8 @@ nil:
 overflow2:
 	linebuf[lx++] = '\0';
 overflow1:
-	return ascii ? ascii_column + len : (groupsize * 2 + 1) * ngroups - 1;
+	return ascii ? ascii_column + len
+		     : (actual_groupsize * 2 + 1) * ngroups - 1;
 }
 EXPORT_SYMBOL(hex_dump_to_buffer);
 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2] of/address: replace printk() with pr_debug() / pr_err() Masahiro Yamada <yamada.masahiro@socionext.com> - 2015-12-08 17:10 +0100
  Re: [PATCH v2] of/address: replace printk() with pr_debug() /  pr_err() Joe Perches <joe@perches.com> - 2015-12-08 17:20 +0100
    Re: [PATCH v2] of/address: replace printk() with pr_debug() /  pr_err() Joe Perches <joe@perches.com> - 2015-12-08 18:10 +0100
      Re: [PATCH v2] of/address: replace printk() with pr_debug() / pr_err() Rob Herring <robh+dt@kernel.org> - 2015-12-08 22:30 +0100
        Re: [PATCH v2] of/address: replace printk() with pr_debug() /  pr_err() Joe Perches <joe@perches.com> - 2015-12-09 01:10 +0100
          Re: [PATCH v2] of/address: replace printk() with pr_debug() / pr_err() Andy Shevchenko <andy.shevchenko@gmail.com> - 2015-12-09 13:10 +0100
            Re: [PATCH v2] of/address: replace printk() with pr_debug() /  pr_err() Joe Perches <joe@perches.com> - 2015-12-09 20:30 +0100
              Re: [PATCH v2] of/address: replace printk() with pr_debug() / pr_err() Andy Shevchenko <andy.shevchenko@gmail.com> - 2015-12-09 21:10 +0100
                Re: [PATCH v2] of/address: replace printk() with pr_debug() /  pr_err() Joe Perches <joe@perches.com> - 2015-12-09 21:20 +0100
                Re: [PATCH v2] of/address: replace printk() with pr_debug() / pr_err() Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-12-09 21:20 +0100
                Re: [PATCH v2] of/address: replace printk() with pr_debug() / pr_err() Andy Shevchenko <andy.shevchenko@gmail.com> - 2015-12-09 21:40 +0100
                Re: [PATCH v2] of/address: replace printk() with pr_debug() /  pr_err() Joe Perches <joe@perches.com> - 2015-12-09 21:50 +0100
        [PATCH] hexdump: Add ability to do endian conversions in print_hex_dump functions Joe Perches <joe@perches.com> - 2015-12-09 23:00 +0100
          Re: [PATCH] hexdump: Add ability to do endian conversions in  print_hex_dump functions Andrew Morton <akpm@linux-foundation.org> - 2015-12-09 23:10 +0100
            Re: [PATCH] hexdump: Add ability to do endian conversions in  print_hex_dump functions Joe Perches <joe@perches.com> - 2015-12-09 23:20 +0100
              Re: [PATCH] hexdump: Add ability to do endian conversions in  print_hex_dump functions Andrew Morton <akpm@linux-foundation.org> - 2015-12-09 23:50 +0100
                Re: [PATCH] hexdump: Add ability to do endian conversions in  print_hex_dump functions Joe Perches <joe@perches.com> - 2015-12-10 00:10 +0100
          Re: [PATCH] hexdump: Add ability to do endian conversions in  print_hex_dump functions Andy Shevchenko <andy.shevchenko@gmail.com> - 2015-12-09 23:20 +0100
            Re: [PATCH] hexdump: Add ability to do endian conversions in  print_hex_dump functions Joe Perches <joe@perches.com> - 2015-12-09 23:30 +0100
            Re: [PATCH] hexdump: Add ability to do endian conversions in  print_hex_dump functions Andy Shevchenko <andy.shevchenko@gmail.com> - 2015-12-10 00:10 +0100
              Re: [PATCH] hexdump: Add ability to do endian conversions in  print_hex_dump functions Joe Perches <joe@perches.com> - 2015-12-10 00:20 +0100
          Re: [PATCH] hexdump: Add ability to do endian conversions in  print_hex_dump functions kbuild test robot <lkp@intel.com> - 2015-12-10 07:00 +0100
            Re: [PATCH] hexdump: Add ability to do endian conversions in  print_hex_dump functions Joe Perches <joe@perches.com> - 2015-12-10 07:30 +0100

csiph-web