diff mbox

lib/vsprintf.c: add %paD format specifier for dma_addr_t types

Message ID 1385638084-10719-1-git-send-email-andriy.shevchenko@linux.intel.com (mailing list archive)
State Superseded
Delegated to: Dan Williams
Headers show

Commit Message

Andy Shevchenko Nov. 28, 2013, 11:28 a.m. UTC
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Add the %paD format specifier for printing a dma_addr_t type, since the
DMA address size on some platforms can vary based on build options,
regardless of the native integer type.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 Documentation/printk-formats.txt |  7 +++++++
 lib/vsprintf.c                   | 15 ++++++++++++---
 2 files changed, 19 insertions(+), 3 deletions(-)

Comments

Joe Perches Nov. 28, 2013, 6:32 p.m. UTC | #1
On Thu, 2013-11-28 at 13:28 +0200, user.email wrote:
> From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> Add the %paD format specifier for printing a dma_addr_t type, since the
> DMA address size on some platforms can vary based on build options,
> regardless of the native integer type.

OK, but I prefer this one because upper case is
sometimes used to specify upper case only output.
ala %x %X and %pUl %pUL.

https://lkml.org/lkml/2013/9/12/483


--
To unsubscribe from this list: send the line "unsubscribe dmaengine" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Andy Shevchenko Nov. 29, 2013, 12:56 p.m. UTC | #2
On Thu, 2013-11-28 at 10:32 -0800, Joe Perches wrote:
> On Thu, 2013-11-28 at 13:28 +0200, user.email wrote:
> > From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > 
> > Add the %paD format specifier for printing a dma_addr_t type, since the
> > DMA address size on some platforms can vary based on build options,
> > regardless of the native integer type.
> 
> OK, but I prefer this one because upper case is
> sometimes used to specify upper case only output.
> ala %x %X and %pUl %pUL.

No objections.

> https://lkml.org/lkml/2013/9/12/483

Hmm... Still not in kernel. Do you know reason why it so?
Joe Perches Nov. 29, 2013, 10:10 p.m. UTC | #3
On Fri, 2013-11-29 at 14:56 +0200, Andy Shevchenko wrote:
> On Thu, 2013-11-28 at 10:32 -0800, Joe Perches wrote:
> > On Thu, 2013-11-28 at 13:28 +0200, user.email wrote:
> > > From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > > 
> > > Add the %paD format specifier for printing a dma_addr_t type, since the
> > > DMA address size on some platforms can vary based on build options,
> > > regardless of the native integer type.
> > 
> > OK, but I prefer this one because upper case is
> > sometimes used to specify upper case only output.
> > ala %x %X and %pUl %pUL.
> 
> No objections.
> 
> > https://lkml.org/lkml/2013/9/12/483
> 
> Hmm... Still not in kernel. Do you know reason why it so?

It was just for discussion and I didn't sign or push it
to anyone else.

What's slightly funny is how far back dma_addr_t printk
discussions go.

http://lkml.indiana.edu/hypermail/linux/kernel/0202.1/1221.html

Anyway, if you think you're going to do a lot of
transforms of printk("%x", dma_addr_t) with or without
(unsigned long long) or (u64) casts, I'll submit a signed
patch to Andrew.

Let me know.

In an aside for Julia Lawall (added to cc's), I tried to
do a spatch grep for dma_addr_t (and phys_addr_t) types
that were cast to (unsigned long) or (u64) but I was
unsuccessful.  Is there something else I need to do?

$ cat dma_addr_t.cocci
@@
dma_addr_t foo;
@@

* (unsigned long long)foo;

$ cat t.c
#include <linux/types.h>
#include <linux/printk.h>

int foo(dma_addr_t a)
{
	printk("test: %llx\n", (unsigned long long)a);
}

$ spatch --all-includes --local-includes  -I include/ --sp-file dma_addr_t.cocci t.c
init_defs_builtins: /usr/local/share/coccinelle/standard.h
HANDLING: t.c
$ 

--
To unsubscribe from this list: send the line "unsubscribe dmaengine" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Lars-Peter Clausen Nov. 29, 2013, 10:50 p.m. UTC | #4
On 11/29/2013 11:10 PM, Joe Perches wrote:
> On Fri, 2013-11-29 at 14:56 +0200, Andy Shevchenko wrote:
>> On Thu, 2013-11-28 at 10:32 -0800, Joe Perches wrote:
>>> On Thu, 2013-11-28 at 13:28 +0200, user.email wrote:
>>>> From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>>>>
>>>> Add the %paD format specifier for printing a dma_addr_t type, since the
>>>> DMA address size on some platforms can vary based on build options,
>>>> regardless of the native integer type.
>>>
>>> OK, but I prefer this one because upper case is
>>> sometimes used to specify upper case only output.
>>> ala %x %X and %pUl %pUL.
>>
>> No objections.
>>
>>> https://lkml.org/lkml/2013/9/12/483
>>
>> Hmm... Still not in kernel. Do you know reason why it so?
>
> It was just for discussion and I didn't sign or push it
> to anyone else.
>
> What's slightly funny is how far back dma_addr_t printk
> discussions go.
>
> http://lkml.indiana.edu/hypermail/linux/kernel/0202.1/1221.html
>
> Anyway, if you think you're going to do a lot of
> transforms of printk("%x", dma_addr_t) with or without
> (unsigned long long) or (u64) casts, I'll submit a signed
> patch to Andrew.
>
> Let me know.
>
> In an aside for Julia Lawall (added to cc's), I tried to
> do a spatch grep for dma_addr_t (and phys_addr_t) types
> that were cast to (unsigned long) or (u64) but I was
> unsuccessful.  Is there something else I need to do?
>
> $ cat dma_addr_t.cocci
> @@
> dma_addr_t foo;
> @@
>
> * (unsigned long long)foo;

Remove the semicolon, otherwise it will only match statements which are nothing 
but the cast.

>
> $ cat t.c
> #include <linux/types.h>
> #include <linux/printk.h>
>
> int foo(dma_addr_t a)
> {
> 	printk("test: %llx\n", (unsigned long long)a);
> }
>
> $ spatch --all-includes --local-includes  -I include/ --sp-file dma_addr_t.cocci t.c
> init_defs_builtins: /usr/local/share/coccinelle/standard.h
> HANDLING: t.c
> $
>
> --
> To unsubscribe from this list: send the line "unsubscribe dmaengine" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

--
To unsubscribe from this list: send the line "unsubscribe dmaengine" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Joe Perches Nov. 29, 2013, 10:58 p.m. UTC | #5
On Fri, 2013-11-29 at 23:50 +0100, Lars-Peter Clausen wrote:
> On 11/29/2013 11:10 PM, Joe Perches wrote:
[]
> > $ cat dma_addr_t.cocci
> > @@
> > dma_addr_t foo;
> > @@
> >
> > * (unsigned long long)foo;
> 
> Remove the semicolon, otherwise it will only match statements which are nothing 
> but the cast.

Duh, thanks.


--
To unsubscribe from this list: send the line "unsubscribe dmaengine" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Laurent Pinchart Nov. 29, 2013, 11:44 p.m. UTC | #6
Hi Joe,

On Friday 29 November 2013 14:10:40 Joe Perches wrote:
> On Fri, 2013-11-29 at 14:56 +0200, Andy Shevchenko wrote:
> > On Thu, 2013-11-28 at 10:32 -0800, Joe Perches wrote:
> > > On Thu, 2013-11-28 at 13:28 +0200, user.email wrote:
> > > > From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > > > 
> > > > Add the %paD format specifier for printing a dma_addr_t type, since
> > > > the
> > > > DMA address size on some platforms can vary based on build options,
> > > > regardless of the native integer type.
> > > 
> > > OK, but I prefer this one because upper case is
> > > sometimes used to specify upper case only output.
> > > ala %x %X and %pUl %pUL.
> > 
> > No objections.
> > 
> > > https://lkml.org/lkml/2013/9/12/483
> > 
> > Hmm... Still not in kernel. Do you know reason why it so?
> 
> It was just for discussion and I didn't sign or push it
> to anyone else.
> 
> What's slightly funny is how far back dma_addr_t printk
> discussions go.
> 
> http://lkml.indiana.edu/hypermail/linux/kernel/0202.1/1221.html
> 
> Anyway, if you think you're going to do a lot of
> transforms of printk("%x", dma_addr_t) with or without
> (unsigned long long) or (u64) casts, I'll submit a signed
> patch to Andrew.
> 
> Let me know.

Just FYI, I've recently submitted a couple of patches that cast dma_addr_t for 
printk purpose, which resulted in Andy proposing a printk format extension 
instead.

> In an aside for Julia Lawall (added to cc's), I tried to
> do a spatch grep for dma_addr_t (and phys_addr_t) types
> that were cast to (unsigned long) or (u64) but I was
> unsuccessful.  Is there something else I need to do?
> 
> $ cat dma_addr_t.cocci
> @@
> dma_addr_t foo;
> @@
> 
> * (unsigned long long)foo;
> 
> $ cat t.c
> #include <linux/types.h>
> #include <linux/printk.h>
> 
> int foo(dma_addr_t a)
> {
> 	printk("test: %llx\n", (unsigned long long)a);
> }
> 
> $ spatch --all-includes --local-includes  -I include/ --sp-file
> dma_addr_t.cocci t.c init_defs_builtins:
> /usr/local/share/coccinelle/standard.h
> HANDLING: t.c
> $
Andy Shevchenko Dec. 2, 2013, 9:06 a.m. UTC | #7
On Fri, 2013-11-29 at 14:10 -0800, Joe Perches wrote:
> On Fri, 2013-11-29 at 14:56 +0200, Andy Shevchenko wrote:
> > On Thu, 2013-11-28 at 10:32 -0800, Joe Perches wrote:

[]

> > > https://lkml.org/lkml/2013/9/12/483
> > 
> > Hmm... Still not in kernel. Do you know reason why it so?
> 
> It was just for discussion and I didn't sign or push it
> to anyone else.
> 
> What's slightly funny is how far back dma_addr_t printk
> discussions go.
> 
> http://lkml.indiana.edu/hypermail/linux/kernel/0202.1/1221.html

Wow, 2002!
Let's cross over a finish line in 2013.


> Anyway, if you think you're going to do a lot of
> transforms of printk("%x", dma_addr_t) with or without
> (unsigned long long) or (u64) casts, I'll submit a signed
> patch to Andrew.

I think it worse to submit even if we have no more such casting in the
future (which is the case I don't believe in).
Andy Shevchenko Dec. 2, 2013, 9:08 a.m. UTC | #8
On Mon, 2013-12-02 at 11:06 +0200, Andy Shevchenko wrote:


> > Anyway, if you think you're going to do a lot of

> > transforms of printk("%x", dma_addr_t) with or without

> > (unsigned long long) or (u64) casts, I'll submit a signed

> > patch to Andrew.

> 

> I think it worse to submit even if we have no more such casting in the

> future (which is the case I don't believe in).


s/worse/worth/

-- 
Andy Shevchenko <andriy.shevchenko@intel.com>
Intel Finland Oy
---------------------------------------------------------------------
Intel Finland Oy
Registered Address: PL 281, 00181 Helsinki 
Business Identity Code: 0357606 - 4 
Domiciled in Helsinki 

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
diff mbox

Patch

diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt
index 445ad74..3344ca9 100644
--- a/Documentation/printk-formats.txt
+++ b/Documentation/printk-formats.txt
@@ -63,6 +63,13 @@  Physical addresses:
 	resource_size_t) which can vary based on build options, regardless of
 	the width of the CPU data path. Passed by reference.
 
+DMA addresses:
+
+	%paD	0x01234567 or 0x0123456789abcdef
+
+	For printing a dma_addr_t type which can vary based on build options,
+	regardless of the width of the CPU data path. Passed by reference.
+
 Raw buffer as a hex string:
 	%*ph	00 01 02  ...  3f
 	%*phC	00:01:02: ... :3f
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 10909c5..12ea69d 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1219,6 +1219,7 @@  int kptr_restrict __read_mostly;
  *            The maximum supported length is 64 bytes of the input. Consider
  *            to use print_hex_dump() for the larger input.
  * - 'a' For a phys_addr_t type and its derivative types (passed by reference)
+ * - 'aD' For a dma_addr_t type (passed by reference)
  * - 'd[234]' For a dentry name (optionally 2-4 last components)
  * - 'D[234]' Same as 'd' but for a struct file
  *
@@ -1354,10 +1355,18 @@  char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 		break;
 	case 'a':
 		spec.flags |= SPECIAL | SMALL | ZEROPAD;
-		spec.field_width = sizeof(phys_addr_t) * 2 + 2;
 		spec.base = 16;
-		return number(buf, end,
-			      (unsigned long long) *((phys_addr_t *)ptr), spec);
+		switch (fmt[1]) {
+		case 'D':
+			spec.field_width = sizeof(dma_addr_t) * 2 + 2;
+			return number(buf, end,
+				(unsigned long long)*((dma_addr_t *)ptr), spec);
+		default:
+			spec.field_width = sizeof(phys_addr_t) * 2 + 2;
+			return number(buf, end,
+				(unsigned long long)*((phys_addr_t *)ptr), spec);
+		}
+		break;
 	case 'd':
 		return dentry_name(buf, end, ptr, spec, fmt);
 	case 'D':