Skip to contentSkip to conversation

resource_size_t and printk()

DISCUSSION Pierre Ossman 5 participants 10 messages Jul 4, 2006 – Jul 13, 2006

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Hi there!

Your commit b60ba8343b78b182c03cf239d4342785376c1ad1 has been causing me a bit of confusion and I thought I'd point out the problem so that you can resolve it. :)

resource_size_t is not guaranteed to be a long long, but might be a u64 or u32 depending on your .config. So you need an explicit cast in the printk:s or you get a lot of junk on the output.

There might be other commits with the same issue. I just noticed this one.

Rgds
Pierre

#1 lore raw
Quoted 9 lines · Pierre Ossman

Hi there!

Your commit b60ba8343b78b182c03cf239d4342785376c1ad1 has been causing me a bit of confusion and I thought I'd point out the problem so that you can resolve it. :)

resource_size_t is not guaranteed to be a long long, but might be a u64 or u32 depending on your .config. So you need an explicit cast in the printk:s or you get a lot of junk on the output.

That is exactly correct. Is there somewhere in that patch that I forgot to fix this up properly?

thanks,

greg k-h

#2 lore raw
Quoted 8 lines · Greg KH
Quoted 6 lines · Pierre Ossman

Hi there!

Your commit b60ba8343b78b182c03cf239d4342785376c1ad1 has been causing me a bit of confusion and I thought I'd point out the problem so that you can resolve it. :)

Quoted 9 lines
Quoted 4 lines

resource_size_t is not guaranteed to be a long long, but might be a u64 or u32 depending on your .config. So you need an explicit cast in the printk:s or you get a lot of junk on the output.

That is exactly correct. Is there somewhere in that patch that I forgot to fix this up properly?

In drivers/pnp/interface.c, theres a couple of these:

@@ -264,7 +264,7 @@ static ssize_t pnp_show_current_resource
if (pnp_port_flags(dev, i) & IORESOURCE_DISABLED)
pnp_printf(buffer," disabled\n");
else
- pnp_printf(buffer," 0x%lx-0x%lx\n",
+ pnp_printf(buffer," 0x%llx-0x%llx\n",
pnp_port_start(dev, i), pnp_port_end(dev, i));
}

Rgds
Pierre

#3 lore raw
Quoted 23 lines · Pierre Ossman
Quoted 8 lines · Greg KH
Quoted 6 lines · Pierre Ossman

Hi there!

Your commit b60ba8343b78b182c03cf239d4342785376c1ad1 has been causing me a bit of confusion and I thought I'd point out the problem so that you can resolve it. :)

Quoted 9 lines
Quoted 4 lines

resource_size_t is not guaranteed to be a long long, but might be a u64 or u32 depending on your .config. So you need an explicit cast in the printk:s or you get a lot of junk on the output.

That is exactly correct. Is there somewhere in that patch that I forgot to fix this up properly?

In drivers/pnp/interface.c, theres a couple of these:

Review static ssize_t pnp_show_current_resource · line 270

Quoted 8 lines
(quoted diff) +1 -1
@@ -264,7 +264,7 @@ static ssize_t pnp_show_current_resource
 			if (pnp_port_flags(dev, i) & IORESOURCE_DISABLED)
 				pnp_printf(buffer," disabled\n");
 			else
-				pnp_printf(buffer," 0x%lx-0x%lx\n",
+				pnp_printf(buffer," 0x%llx-0x%llx\n",
 						pnp_port_start(dev, i),
 						pnp_port_end(dev, i));
 		}

Good catch, care to create a patch to fix these?

thanks,

greg k-h

#4 lore raw
Quoted 2 lines · Greg KH

Good catch, care to create a patch to fix these?

Included.

[PNP] Add missing casts in printk() arguments

Some resource_size_t values are fed to printk() without handling the fact that they can have different size depending on your .config.

---

 drivers/pnp/interface.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
drivers/pnp/interface.c +6 -6
index 3163e3d..0c14f4f 100644
@@ -265,8 +265,8 @@ static ssize_t pnp_show_current_resource
 				pnp_printf(buffer," disabled\n");
 			else
 				pnp_printf(buffer," 0x%llx-0x%llx\n",
-						pnp_port_start(dev, i),
-						pnp_port_end(dev, i));
+					(long long)pnp_port_start(dev, i),
+					(long long)pnp_port_end(dev, i));
 		}
 	}
 	for (i = 0; i < PNP_MAX_MEM; i++) {
@@ -276,8 +276,8 @@ static ssize_t pnp_show_current_resource
 				pnp_printf(buffer," disabled\n");
 			else
 				pnp_printf(buffer," 0x%llx-0x%llx\n",
-						pnp_mem_start(dev, i),
-						pnp_mem_end(dev, i));
+					(long long)pnp_mem_start(dev, i),
+					(long long)pnp_mem_end(dev, i));
 		}
 	}
 	for (i = 0; i < PNP_MAX_IRQ; i++) {
@@ -287,7 +287,7 @@ static ssize_t pnp_show_current_resource
 				pnp_printf(buffer," disabled\n");
 			else
 				pnp_printf(buffer," %lld\n",
-						pnp_irq(dev, i));
+					(long long)pnp_irq(dev, i));
 		}
 	}
 	for (i = 0; i < PNP_MAX_DMA; i++) {
@@ -297,7 +297,7 @@ static ssize_t pnp_show_current_resource
 				pnp_printf(buffer," disabled\n");
 			else
 				pnp_printf(buffer," %lld\n",
-						pnp_dma(dev, i));
+					(long long)pnp_dma(dev, i));
 		}
 	}
 	ret = (buffer->curr - buf);
#5 lore raw
Quoted 5 lines · On Wed, 12 Jul 2006 10:18:09 +0200 Pierre Ossman wrote:
Quoted 2 lines · Greg KH

Good catch, care to create a patch to fix these?

Included.

ugh :(

I know it's more wordy, but we usually use
(unsigned long long), not just (long long).

Wish we had an abbreviation for that.

---
~Randy

#6 lore raw
Quoted 4 lines · Randy.Dunlap

I know it's more wordy, but we usually use
(unsigned long long), not just (long long).

Wish we had an abbreviation for that.

We have a specific qualifier for ptrdiff_t... Why not add one (untested!) for resource_size_t, and get rid of all these bloody annoying casts?

I'm more than slightly irritated to have to go and add ugly (unsigned long long) casts to squelch compiler whining on parisc.

This patch will probably cause even more compiler warnings thought because gcc will try to be too smart with the use of formats...

lib/vsprintf.c +4 -1
index bed7229..2d71ff6 100644
@@ -343,7 +343,8 @@ int vsnprintf(char *buf, size_t size, co
 		/* get the conversion qualifier */
 		qualifier = -1;
 		if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' ||
-		    *fmt =='Z' || *fmt == 'z' || *fmt == 't') {
+		    *fmt == 'Z' || *fmt == 'z' || *fmt == 't' ||
+		    *fmt == 'r') {
 			qualifier = *fmt;
 			++fmt;
 			if (qualifier == 'l' && *fmt == 'l') {
@@ -477,6 +478,8 @@ int vsnprintf(char *buf, size_t size, co
 			num = (unsigned short) va_arg(args, int);
 			if (flags & SIGN)
 				num = (signed short) num;
+		} else if (qualifier == 'r') {
+			num = va_arg(args, resource_size_t);
 		} else {
 			num = va_arg(args, unsigned int);
 			if (flags & SIGN)
#7 lore raw
In reply to Pierre Ossman
Quoted 33 lines · Pierre Ossman
Quoted 2 lines · Greg KH

Good catch, care to create a patch to fix these?

Included.

[PNP] Add missing casts in printk() arguments

Some resource_size_t values are fed to printk() without handling the fact that they can have different size depending on your .config.

---

 drivers/pnp/interface.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
drivers/pnp/interface.c +2 -2
index 3163e3d..0c14f4f 100644
@@ -265,8 +265,8 @@ static ssize_t pnp_show_current_resource
 				pnp_printf(buffer," disabled\n");
 			else
 				pnp_printf(buffer," 0x%llx-0x%llx\n",
-						pnp_port_start(dev, i),
-						pnp_port_end(dev, i));
+					(long long)pnp_port_start(dev, i),
+					(long long)pnp_port_end(dev, i));
 		}
 	}
 	for (i = 0; i < PNP_MAX_MEM; i++) {

drivers/pnp/interface.c static ssize_t pnp_show_current_resource · line 280

Quoted 7 lines
drivers/pnp/interface.c +2 -2
@@ -276,8 +276,8 @@ static ssize_t pnp_show_current_resource
 				pnp_printf(buffer," disabled\n");
 			else
 				pnp_printf(buffer," 0x%llx-0x%llx\n",
-						pnp_mem_start(dev, i),
-						pnp_mem_end(dev, i));
+					(long long)pnp_mem_start(dev, i),
+					(long long)pnp_mem_end(dev, i));

Like Randy said, please use "unsigned long long".

Care to redo this?

thanks,

greg k-h

#8 lore raw

Ar Mer, 2006-07-12 am 14:37 -0700, ysgrifennodd Greg KH:

Quoted 3 lines

Like Randy said, please use "unsigned long long".

Care to redo this?

While you are at it someone did 8139cp and used "%l" not "%ll"

drivers/net/8139cp.c +1 -1
diff -u --new-file --recursive --exclude-from /usr/src/exclude linux.vanilla-2.6.18-rc1/drivers/net/8139cp.c linux-2.6.18-rc1/drivers/net/8139cp.c
@@ -1916,7 +1916,7 @@
 	regs = ioremap(pciaddr, CP_REGS_SIZE);
 	if (!regs) {
 		rc = -EIO;
-		dev_err(&pdev->dev, "Cannot map PCI MMIO (%lx@%lx)\n",
+		dev_err(&pdev->dev, "Cannot map PCI MMIO (%llx@%llx)\n",
 		       (unsigned long long)pci_resource_len(pdev, 1),
 		       (unsigned long long)pciaddr);
 		goto err_out_res;
#9 lore raw
In reply to Greg KH
Quoted 4 lines · Greg KH

Like Randy said, please use "unsigned long long".

Care to redo this?

Here you go.

[PNP] Add missing casts in printk() arguments

Some resource_size_t values are fed to printk() without handling the fact that they can have different size depending on your .config.

---

 drivers/pnp/interface.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
drivers/pnp/interface.c +6 -6
index 3163e3d..9d8b415 100644
@@ -265,8 +265,8 @@ static ssize_t pnp_show_current_resource
 				pnp_printf(buffer," disabled\n");
 			else
 				pnp_printf(buffer," 0x%llx-0x%llx\n",
-						pnp_port_start(dev, i),
-						pnp_port_end(dev, i));
+					(unsigned long long)pnp_port_start(dev, i),
+					(unsigned long long)pnp_port_end(dev, i));
 		}
 	}
 	for (i = 0; i < PNP_MAX_MEM; i++) {
@@ -276,8 +276,8 @@ static ssize_t pnp_show_current_resource
 				pnp_printf(buffer," disabled\n");
 			else
 				pnp_printf(buffer," 0x%llx-0x%llx\n",
-						pnp_mem_start(dev, i),
-						pnp_mem_end(dev, i));
+					(unsigned long long)pnp_mem_start(dev, i),
+					(unsigned long long)pnp_mem_end(dev, i));
 		}
 	}
 	for (i = 0; i < PNP_MAX_IRQ; i++) {
@@ -287,7 +287,7 @@ static ssize_t pnp_show_current_resource
 				pnp_printf(buffer," disabled\n");
 			else
 				pnp_printf(buffer," %lld\n",
-						pnp_irq(dev, i));
+					(unsigned long long)pnp_irq(dev, i));
 		}
 	}
 	for (i = 0; i < PNP_MAX_DMA; i++) {
@@ -297,7 +297,7 @@ static ssize_t pnp_show_current_resource
 				pnp_printf(buffer," disabled\n");
 			else
 				pnp_printf(buffer," %lld\n",
-						pnp_dma(dev, i));
+					(unsigned long long)pnp_dma(dev, i));
 		}
 	}
 	ret = (buffer->curr - buf);