DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 0/2] use %z for formatting
@ 2018-02-15 22:25 Stephen Hemminger
  2018-02-15 22:25 ` [dpdk-dev] [PATCH 1/2] pci: use %z to format size_t Stephen Hemminger
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Stephen Hemminger @ 2018-02-15 22:25 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger

Better to use %z and avoid any 32 bit platform woes;
and not cast unnecessarily

Stephen Hemminger (2):
  pci: use %z to format size_t
  eal: use %zu to format size_t

 lib/librte_eal/linuxapp/eal/eal_memory.c |  8 ++++----
 lib/librte_pci/rte_pci.c                 | 11 ++++++-----
 2 files changed, 10 insertions(+), 9 deletions(-)

-- 
2.15.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [dpdk-dev] [PATCH 1/2] pci: use %z to format size_t
  2018-02-15 22:25 [dpdk-dev] [PATCH 0/2] use %z for formatting Stephen Hemminger
@ 2018-02-15 22:25 ` Stephen Hemminger
  2018-02-15 22:25 ` [dpdk-dev] [PATCH 2/2] eal: use %zu " Stephen Hemminger
  2018-04-04 10:41 ` [dpdk-dev] [PATCH 0/2] use %z for formatting Thomas Monjalon
  2 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2018-02-15 22:25 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Stephen Hemminger

This addresses potential issues where size_t and off_t can vary
on some platforms.  For size_t the best way to format the value
is to use the z modifier to printf. For off_t need to cast to
long long to handle 64 bit offset on 32 bit platforms.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
---
 lib/librte_pci/rte_pci.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/lib/librte_pci/rte_pci.c b/lib/librte_pci/rte_pci.c
index 1a6d748568ad..530738dbdf47 100644
--- a/lib/librte_pci/rte_pci.c
+++ b/lib/librte_pci/rte_pci.c
@@ -155,9 +155,10 @@ pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
 	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
 			MAP_SHARED | additional_flags, fd, offset);
 	if (mapaddr == MAP_FAILED) {
-		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
-			__func__, fd, requested_addr,
-			(unsigned long)size, (unsigned long)offset,
+		RTE_LOG(ERR, EAL,
+			"%s(): cannot mmap(%d, %p, 0x%zx, 0x%llx): %s (%p)\n",
+			__func__, fd, requested_addr, size,
+			(unsigned long long)offset,
 			strerror(errno), mapaddr);
 	} else
 		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
@@ -174,8 +175,8 @@ pci_unmap_resource(void *requested_addr, size_t size)
 
 	/* Unmap the PCI memory resource of device */
 	if (munmap(requested_addr, size)) {
-		RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, 0x%lx): %s\n",
-			__func__, requested_addr, (unsigned long)size,
+		RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, %#zx): %s\n",
+			__func__, requested_addr, size,
 			strerror(errno));
 	} else
 		RTE_LOG(DEBUG, EAL, "  PCI memory unmapped at %p\n",
-- 
2.15.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [dpdk-dev] [PATCH 2/2] eal: use %zu to format size_t
  2018-02-15 22:25 [dpdk-dev] [PATCH 0/2] use %z for formatting Stephen Hemminger
  2018-02-15 22:25 ` [dpdk-dev] [PATCH 1/2] pci: use %z to format size_t Stephen Hemminger
@ 2018-02-15 22:25 ` Stephen Hemminger
  2018-04-04 10:41 ` [dpdk-dev] [PATCH 0/2] use %z for formatting Thomas Monjalon
  2 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2018-02-15 22:25 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Stephen Hemminger

The recommended way to format size_t in printf is to use the
z modifier which handles the case where size_t maybe 32 or 64 bits.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
---
 lib/librte_eal/linuxapp/eal/eal_memory.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 38853b753aab..86df67480201 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1390,16 +1390,16 @@ rte_eal_hugepage_attach(void)
 			max_seg = s;
 			if (base_addr != MAP_FAILED) {
 				/* errno is stale, don't use */
-				RTE_LOG(ERR, EAL, "Could not mmap %llu bytes "
+				RTE_LOG(ERR, EAL, "Could not mmap %zu bytes "
 					"in /dev/zero at [%p], got [%p] - "
 					"please use '--base-virtaddr' option\n",
-					(unsigned long long)mcfg->memseg[s].len,
+					mcfg->memseg[s].len,
 					mcfg->memseg[s].addr, base_addr);
 				munmap(base_addr, mcfg->memseg[s].len);
 			} else {
-				RTE_LOG(ERR, EAL, "Could not mmap %llu bytes "
+				RTE_LOG(ERR, EAL, "Could not mmap %zu bytes "
 					"in /dev/zero at [%p]: '%s'\n",
-					(unsigned long long)mcfg->memseg[s].len,
+					mcfg->memseg[s].len,
 					mcfg->memseg[s].addr, strerror(errno));
 			}
 			if (aslr_enabled() > 0) {
-- 
2.15.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dpdk-dev] [PATCH 0/2] use %z for formatting
  2018-02-15 22:25 [dpdk-dev] [PATCH 0/2] use %z for formatting Stephen Hemminger
  2018-02-15 22:25 ` [dpdk-dev] [PATCH 1/2] pci: use %z to format size_t Stephen Hemminger
  2018-02-15 22:25 ` [dpdk-dev] [PATCH 2/2] eal: use %zu " Stephen Hemminger
@ 2018-04-04 10:41 ` Thomas Monjalon
  2 siblings, 0 replies; 4+ messages in thread
From: Thomas Monjalon @ 2018-04-04 10:41 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev

15/02/2018 23:25, Stephen Hemminger:
> Better to use %z and avoid any 32 bit platform woes;
> and not cast unnecessarily
> 
> Stephen Hemminger (2):
>   pci: use %z to format size_t
>   eal: use %zu to format size_t
> 
>  lib/librte_eal/linuxapp/eal/eal_memory.c |  8 ++++----
>  lib/librte_pci/rte_pci.c                 | 11 ++++++-----
>  2 files changed, 10 insertions(+), 9 deletions(-)

Applied, thanks

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-04-04 10:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-15 22:25 [dpdk-dev] [PATCH 0/2] use %z for formatting Stephen Hemminger
2018-02-15 22:25 ` [dpdk-dev] [PATCH 1/2] pci: use %z to format size_t Stephen Hemminger
2018-02-15 22:25 ` [dpdk-dev] [PATCH 2/2] eal: use %zu " Stephen Hemminger
2018-04-04 10:41 ` [dpdk-dev] [PATCH 0/2] use %z for formatting Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).